summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/back/generator.py13
-rw-r--r--src/back/tac.py1
-rw-r--r--src/emu/risci.c6
-rw-r--r--src/front/ast.py7
4 files changed, 19 insertions, 8 deletions
diff --git a/src/back/generator.py b/src/back/generator.py
index 7ca2658..1ae403f 100644
--- a/src/back/generator.py
+++ b/src/back/generator.py
@@ -52,12 +52,7 @@ class Generator(object):
Register().get_registers(name).reverse()
self.emit("ADD sp, r0, bp")
self.emit("POP bp")
- if name == "main":
- self.emit("PUSH rv")
- self.emit("PUSH r0")
- self.emit("SYS")
- else:
- self.emit("RET")
+ self.emit("RET")
def generate(self):
# pass 1 - generate non-label ops
@@ -98,6 +93,10 @@ class Generator(object):
self.emit("SYS")
self.emit("POP r0")
self.emit("POP r0")
+ elif tac.op == Op.SYS:
+ self.emit("SYS")
+ else:
+ raise Exception("%s is not a valid TAC operator" % tac.op)
elif isinstance(tac, FunctionPrologue):
self.generate_prologue(tac.name)
elif isinstance(tac, FunctionEpilogue):
@@ -105,7 +104,7 @@ class Generator(object):
elif isinstance(tac, Label):
self.emit(Label(tac.name))
else:
- raise Exception("%s is not a valid TACList element", repr(tac))
+ raise Exception("%s is not a valid TACList element" % repr(tac))
# pass 2 - generate label ops
for op in self.__op_list:
diff --git a/src/back/tac.py b/src/back/tac.py
index 86ccd90..7207758 100644
--- a/src/back/tac.py
+++ b/src/back/tac.py
@@ -40,6 +40,7 @@ Op.JMP = Op("JMP") # goto x
Op.CALL = Op("CALL") # call x return in y
Op.RETURN = Op("RETURN") # return x
+Op.SYS = Op("SYS") # system call
Op.PRINT = Op("PRINT") # print x
class TAC(object):
diff --git a/src/emu/risci.c b/src/emu/risci.c
index 1711089..4f73615 100644
--- a/src/emu/risci.c
+++ b/src/emu/risci.c
@@ -104,6 +104,12 @@ int main(int argc, char *argv[])
usage(EXIT_FAILURE);
read_program(argv[0]);
+ /* push arguments onto stack */
+ while (--argc) {
+ //dump_registers();
+ push(atoi(argv[argc]));
+ }
+
/* reset program counter to first instruction */
IP = 0;
diff --git a/src/front/ast.py b/src/front/ast.py
index f272ca2..8b86cdd 100644
--- a/src/front/ast.py
+++ b/src/front/ast.py
@@ -28,7 +28,12 @@ class Program(Node):
def generate(self):
self.debug("Program.generate(): %s" % repr(self))
- self.emit(Op.JMP, "main")
+ Register().set_function("__start")
+ r = Register().new()
+ self.emit(Op.CALL, "main", r)
+ self.emit(Op.PUSH, r)
+ self.emit(Op.PUSH, 0)
+ self.emit(Op.SYS)
for function in self.functions:
function.generate()