-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chadderbox
committed
Nov 28, 2021
1 parent
a90f8d8
commit 24ca394
Showing
5 changed files
with
726 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,6 @@ dmypy.json | |
.pyre/ | ||
|
||
#cbLang test files | ||
*.cb | ||
Testing.py | ||
cbLangBootstrap/* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from native reference sys; | ||
|
||
class Error() | ||
{ | ||
function Start(error): | ||
print(error); | ||
sys.exit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
from native reference os.path; | ||
from native reference subprocess; | ||
from native reference sys; | ||
from native reference shutil; | ||
|
||
include parse; | ||
include error; | ||
|
||
class Interpreter() | ||
{ | ||
function Interpret(code) | ||
{ | ||
subprocess.call(["python", "output.py"]); | ||
} | ||
} | ||
class Main() | ||
{ | ||
function GetCode(filePath) | ||
{ | ||
if os.path.isfile(filePath) | ||
{ | ||
with open(filePath, 'r') as file | ||
{ | ||
return file.read(); | ||
} | ||
} | ||
else | ||
{ | ||
Error("Input file not found"); | ||
} | ||
} | ||
|
||
function HandleArgs() | ||
{ | ||
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"); | ||
} | ||
else if sys.argv[1] == "--run" or sys.argv[1] == "-r" | ||
{ | ||
if len(sys.argv) < 3 | ||
{ | ||
Error("Invalid number of arguments"); | ||
} | ||
else | ||
{ | ||
if os.path.isfile(sys.argv[2]) | ||
{ | ||
parser = Parser(this.GetCode((sys.argv[2]))); | ||
interpreter = Interpreter(); | ||
interpreter.Interpret(parser.code); | ||
} | ||
else | ||
{ | ||
Error("File not found"); | ||
} | ||
} | ||
} | ||
else if os.path.isfile(sys.argv[1]) | ||
{ | ||
parser = Parser(this.GetCode(sys.argv[1])); | ||
interpreter = Interpreter(); | ||
interpreter.Interpret(parser.code); | ||
} | ||
else if sys.argv[1] == "--transpile" or sys.argv[1] == "-t" | ||
{ | ||
if len(sys.argv) < 4 | ||
{ | ||
Error("Invalid number of arguments"); | ||
} | ||
else | ||
{ | ||
if os.path.isfile(sys.argv[2]) | ||
{ | ||
parser = Parser(this.GetCode((sys.argv[2]))); | ||
with open(sys.argv[3], "w") as f | ||
{ | ||
f.write(parser.code); | ||
} | ||
} | ||
else | ||
{ | ||
Error("Input file not found"); | ||
} | ||
} | ||
} | ||
else if sys.argv[1] == "--compile" or sys.argv[1] == "-c" | ||
{ | ||
if len(sys.argv) < 4 | ||
{ | ||
Error("Invalid number of arguments"); | ||
} | ||
else | ||
{ | ||
if os.path.isfile(sys.argv[2]) | ||
{ | ||
parser = Parser(this.GetCode((sys.argv[2]))); | ||
fileName = sys.argv[3].split(".")[0]; | ||
with open(fileName + ".py", "w") as f | ||
{ | ||
f.write(parser.code); | ||
} | ||
if (os.path.isfile(fileName + ".exe")) | ||
{ | ||
os.remove(fileName + ".exe"); | ||
} | ||
subprocess.call(["PyInstaller", fileName + ".py", "--onefile", "--log-level", "ERROR"]); | ||
os.rename("dist/{}".format(fileName+".exe"),"./"+sys.argv[3]); | ||
os.remove(fileName + ".py"); | ||
os.remove(fileName + ".spec"); | ||
shutil.rmtree("build"); | ||
shutil.rmtree("dist"); | ||
} | ||
else | ||
{ | ||
Error("File not found"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Error("Invalid argument"); | ||
} | ||
|
||
if (os.path.isfile("output.py")) | ||
{ | ||
os.remove("output.py"); | ||
} | ||
} | ||
|
||
function CheckArgs() | ||
{ | ||
if len(sys.argv) < 2: | ||
Error("Invalid number of arguments"); | ||
this.HandleArgs(); | ||
} | ||
|
||
function Main() | ||
{ | ||
this.CheckArgs(); | ||
} | ||
} |
Oops, something went wrong.