diff --git a/.gitignore b/.gitignore index 16481c3..eaa60b1 100644 --- a/.gitignore +++ b/.gitignore @@ -129,6 +129,7 @@ dmypy.json .pyre/ #cbLang test files +output.py Testing.py cbLangBootstrap/* diff --git a/README.md b/README.md index 6858fae..4f411ff 100644 --- a/README.md +++ b/README.md @@ -90,4 +90,21 @@ To compile code, use the command `cbLang.exe -c filename.cb output.exe`. *(This } } -*^This is a basic example of importing external code, along with demonstrating other concepts in the programming language.* \ No newline at end of file +*^This is a basic example of importing external code, along with demonstrating other concepts in the programming language.* + + class Main + { + function Main() + { + Other.Test(); + } + } + + class Other + { + static function Test() + { + print("This code was printed from a static m,ethod in Other"); + } + } +*^This is a basic example of static methods.* \ No newline at end of file diff --git a/interpreter.cb b/interpreter.cb index 1dd5389..598ee3c 100644 --- a/interpreter.cb +++ b/interpreter.cb @@ -34,7 +34,7 @@ class Main() { if sys.argv[1] == "--help" or sys.argv[1] == "-h" { - Error("Command line arguments: \n--help -h: Prints this message \n--version -b: Prints the version of the interpreter \n--run -r (default) [file]: Runs the interpreter on the file specified \n--transpile -t [file] [address]: Converts the file specified into python code and saves it to the address specified \n--compile -c [file] [address]: Compiles the file specified into an executable and saves it to the address specified"); + Error("Command line arguments: \n--help -h: Prints help message \n--version -b: Prints the version of the interpreter \n--run -r (default) [file]: Runs the interpreter on the file specified \n--transpile -t [file] [address]: Converts the file specified into python code and saves it to the address specified \n--compile -c [file] [address]: Compiles the file specified into an executable and saves it to the address specified"); } else if sys.argv[1] == "--run" or sys.argv[1] == "-r" { diff --git a/parse.cb b/parse.cb index 66878bf..66ca438 100644 --- a/parse.cb +++ b/parse.cb @@ -427,10 +427,24 @@ class Parser { if (line.partition("def")[0].strip() == "") { - code = code.replace(line, line.replace("(", "(self,")); + code = code.replace(line, line.replace("(", "(this,")); } } } + newCode = []; + for count, line in enumerate(code.splitlines()) + { + if "static " in line + { + if not this.IsInString("static ", line, false) + { + newCode.insert(count - 1, " @staticmethod"); + line = line.replace(line, line.replace("static ", "")); + } + } + newCode.append(line); + } + code = "\n".join(newCode); return code; } @@ -487,6 +501,18 @@ class Parser } code = newCode; + //this + for line in code.splitlines() + { + if "this" in line + { + if not this.IsInString("this", line, true) + { + code = code.replace(line, line.replace("this", "self")); + } + } + } + //Remove indent helpers newCode = ""; for line in code.splitlines()