-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathryton.py
57 lines (44 loc) · 1.53 KB
/
ryton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import sys
from Interpritator.Core import SharpyLang
def setup_ryton_environment():
if getattr(sys, 'frozen', False):
base_path = os.path.dirname(sys.executable)
else:
base_path = os.path.dirname(__file__)
os.environ['RYTON_HOME'] = base_path
os.environ['RYTON_STDLIB'] = os.path.join(base_path, 'Interpritator/std')
sys.path.insert(0, os.path.join(base_path, 'Interpritator'))
sys.path.insert(0, os.path.join(base_path, 'Interpritator/std'))
current_dir = os.getcwd()
os.environ['RYTON_PACKAGES'] = current_dir
sys.path.insert(0, current_dir)
def main():
setup_ryton_environment()
ryton = SharpyLang(os.getcwd())
if len(sys.argv) < 2:
print("Using:")
print("ryton run file.ry - run file")
print("ryton compile file.ry - compile to bitecode")
print("ryton exec file.ryc - execute bytecode file")
return
command = sys.argv[1]
if len(sys.argv) < 3:
print("Enter File")
return
filename = sys.argv[2]
if command == "run":
with open(filename, 'r', encoding='utf-8') as f:
code = f.read()
ryton.run(code)
elif command == "compile":
with open(filename, 'r', encoding='utf-8') as f:
code = f.read()
output = os.path.splitext(filename)[0]
ryton.compile(code, output)
elif command == "exec":
ryton.exec(filename)
else:
print(f"Command Not Found: {command}")
if __name__ == '__main__':
main()