-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiller.py
83 lines (74 loc) · 2.1 KB
/
compiller.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import sys
def ext(err: str = ""):
print(err)
exec("")
def _help():
print("ScrapCPU compiler. Usage: compiler.py file [-ma][-o file][-c num][-m sys][-v ver][-h]")
print("-ma: memeory addon")
print("-o: output file")
print("-c: current counter position, default: 0")
print("-m: machine type(0 - original(default), 1 - the modpack)")
print("-v: number of TimCPU version (0 - original(default), 1 - mini, 2 - mega)")
print("-h: help")
print("\n")
print("!!!if -m set by 1 then -ma, -v will be unused!!!")
print("Arguments: file")
ext()
if len(sys.argv) == 1: # if you just launch app
_help()
if len(sys.argv) > 1:
ma = False
o = ""
c = 0
m = 0
v = 0
count = 0
arg = sys.argv[1:]
for i in arg:
match i:
case "-ma":
ma = True
case "-o":
o = open(arg[count + 1], "w")
case "-h":
_help()
case "-c":
c = arg[count + 1]
case "-m":
m = arg[count + 1]
case "-v":
v = arg[count + 1]
count += 1
match int(m):
case 0:
import original as comp
case 1:
import themodpack as comp
# setting addons
comp.ma = ma
comp.o = o
comp.c = c
if v == 0:
match v:
case "0":
comp.registers = comp.registers0
case "1":
comp.registers = comp.registers1
case "2":
comp.registers = comp.registers2
try:
text = open(sys.argv[1], "r").readlines()
except FileNotFoundError:
ext("file not found")
print("File found! Compiling...")
comp.cmp(text)
if not comp.err:
if int(m) == 1:
print("| num|| OPCODE || ARG1 || ARG2 || RESULT |")
else:
print("| OPCODE || ARG1 || ARG2 || RESULT |")
else:
print("!Error!")
for i in comp.inst:
print(i)
ext()