|
@@ -182,7 +182,8 @@ class ModelverseKernel(object):
|
|
|
|
|
|
def print_instruction(self, inst, indent=0):
|
|
|
inst_type, = yield [("RV", [inst])]
|
|
|
- #print(" %s (%s)" % (inst, inst_type["value"]))
|
|
|
+ instruction = "(no_printer_for_%s)" % inst_type["value"]
|
|
|
+
|
|
|
if inst_type["value"] == "if":
|
|
|
cond, true, false = yield [("RD", [inst, "cond"]),
|
|
|
("RD", [inst, "then"]),
|
|
@@ -196,17 +197,48 @@ class ModelverseKernel(object):
|
|
|
else:
|
|
|
false = ""
|
|
|
|
|
|
- next_inst, = yield[("RD", [inst, "next"])]
|
|
|
- if next_inst:
|
|
|
- next_inst, = yield [("CALL_ARGS", [self.print_instruction, (next_inst, indent)])]
|
|
|
- else:
|
|
|
- next_inst = ""
|
|
|
- raise primitive_functions.PrimitiveFinished(" " * indent + "if(" + cond + "):\n" + true + "\n" + false + next_inst)
|
|
|
- elif inst_type["value"] == "const":
|
|
|
+ instruction = " " * indent + "if(" + cond + "):\n" + true + "\n" + false
|
|
|
+ elif inst_type["value"] == "constant":
|
|
|
node, = yield [("RD", [inst, "node"])]
|
|
|
- #print("Node: %s" % (node))
|
|
|
+ node, = yield [("RV", [node])]
|
|
|
+ instruction = " " * indent + str(node)
|
|
|
+ elif inst_type["value"] == "return":
|
|
|
+ value, = yield [("RD", [inst, "value"])]
|
|
|
+ if value:
|
|
|
+ value, = yield [("CALL_ARGS", [self.print_instruction, (value, 0)])]
|
|
|
+ instruction = " " * indent + "return %s\n" % value
|
|
|
+ else:
|
|
|
+ instruction = " " * indent + "return\n"
|
|
|
+ elif inst_type["value"] == "declare":
|
|
|
+ instruction = ""
|
|
|
+ elif inst_type["value"] == "resolve":
|
|
|
+ value, = yield [("RD", [inst, "var"])]
|
|
|
+ #instruction, = yield [("CALL_ARGS", [self.print_instruction, (value, 0)])]
|
|
|
+ instruction = "var_%s" % value
|
|
|
+ elif inst_type["value"] == "assign":
|
|
|
+ var, val = yield [("RD", [inst, "var"]),
|
|
|
+ ("RD", [inst, "value"])]
|
|
|
+ var, val = yield [("CALL_ARGS", [self.print_instruction, (var, 0)]),
|
|
|
+ ("CALL_ARGS", [self.print_instruction, (val, 0)])]
|
|
|
+ instruction = " " * indent + var + " = " + val + "\n"
|
|
|
+ elif inst_type["value"] == "call":
|
|
|
+ instruction = " " * indent + "call(X)"
|
|
|
+ if indent:
|
|
|
+ instruction += "\n"
|
|
|
+ elif inst_type["value"] == "while":
|
|
|
+ cond, body = yield [("RD", [inst, "cond"]),
|
|
|
+ ("RD", [inst, "body"])]
|
|
|
+ cond, body = yield [("CALL_ARGS", [self.print_instruction, (cond, 0)]),
|
|
|
+ ("CALL_ARGS", [self.print_instruction, (body, indent+1)])]
|
|
|
+ instruction = " " * indent + "while (%s):\n" % cond + body
|
|
|
+
|
|
|
+ next_inst, = yield [("RD", [inst, "next"])]
|
|
|
+ if next_inst:
|
|
|
+ next_inst, = yield [("CALL_ARGS", [self.print_instruction, (next_inst, indent)])]
|
|
|
+ else:
|
|
|
+ next_inst = ""
|
|
|
|
|
|
- raise primitive_functions.PrimitiveFinished("(no_printer_for_%s)" % inst_type["value"])
|
|
|
+ raise primitive_functions.PrimitiveFinished(instruction + next_inst)
|
|
|
|
|
|
def read_function(self, inst):
|
|
|
initial_instruction = inst
|
|
@@ -218,7 +250,7 @@ class ModelverseKernel(object):
|
|
|
raise jit.JitCompilationFailedException("FAIL")
|
|
|
|
|
|
print("Reading function: %s" % suggested_name)
|
|
|
- printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 0)])]
|
|
|
+ printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 1)])]
|
|
|
print("Total printed function: ")
|
|
|
print(printed)
|
|
|
|