|
@@ -90,6 +90,7 @@ class WMA:
|
|
|
self.size = 0
|
|
|
|
|
|
self.parser = lark.Lark(GRAMMAR)
|
|
|
+ self.used_regs = []
|
|
|
|
|
|
def emit(self, *ops):
|
|
|
self.buffer.extend(ops)
|
|
@@ -161,6 +162,7 @@ class WMA:
|
|
|
elif arg.value == "ZZ":
|
|
|
self.emit(-15)
|
|
|
else:
|
|
|
+ self.used_regs.append(arg.value)
|
|
|
self.emit((False, arg.value))
|
|
|
|
|
|
def compile_operation(self, op):
|
|
@@ -407,7 +409,7 @@ class WMA:
|
|
|
if len(command.children) == 2:
|
|
|
label = command.children[0].value[:-1]
|
|
|
|
|
|
- self.emit((True,label))
|
|
|
+ self.emit((True, label))
|
|
|
|
|
|
if type(command.children[1]) is lark.Tree and command.children[1].data != "mixed":
|
|
|
self.compile_operation(command.children[1])
|
|
@@ -418,7 +420,7 @@ class WMA:
|
|
|
if command.children[0].type == "LABEL":
|
|
|
label = command.children[0].value[:-1]
|
|
|
|
|
|
- self.emit((True,label))
|
|
|
+ self.emit((True, label))
|
|
|
else:
|
|
|
with open(command.children[0].value[1:], "r") as f:
|
|
|
self.precompile(f.read())
|
|
@@ -426,15 +428,13 @@ class WMA:
|
|
|
self.compile_operation(command.children[0])
|
|
|
|
|
|
def compile(self, source):
|
|
|
- source += "\n"
|
|
|
- for reg in "ABCDEFGHIXYK":
|
|
|
- source += f"{reg}:0"
|
|
|
-
|
|
|
- if reg != "K":
|
|
|
- source += ";"
|
|
|
-
|
|
|
self.precompile(source)
|
|
|
|
|
|
+ for reg in "ABCDEFGHIXYK":
|
|
|
+ if reg in self.used_regs:
|
|
|
+ self.buffer.append((True, reg))
|
|
|
+ self.buffer.append(0)
|
|
|
+
|
|
|
self.compile_labels()
|
|
|
|
|
|
return self.encode()
|