|
@@ -0,0 +1,119 @@
|
|
|
+include "primitives.alh"
|
|
|
+include "modelling.alh"
|
|
|
+include "object_operations.alh"
|
|
|
+
|
|
|
+// def print_instruction(self, inst, indent=0):
|
|
|
+// intrinsics = {"integer_addition": (lambda x, y: "(%s + %s)" % (x, y)),
|
|
|
+// #"string_join": (lambda x, y: "(str(%s) + str(%s))" % (x, y)),
|
|
|
+// #"dict_read": (lambda x, y: "(%s[%s])" % (x, y)),
|
|
|
+// #"dict_overwrite": (lambda x, y, z: "(%s[%s] = %s)" % (x, y, z)),
|
|
|
+// #"dict_add_fast": (lambda x, y, z: "(%s[%s] = %s)" % (x, y, z)),
|
|
|
+// #"dict_add_fast": (lambda x, y, z: "(%s[%s] = %s)" % (x, y, z)),
|
|
|
+// }
|
|
|
+//
|
|
|
+// inst_type, = yield [("RV", [inst])]
|
|
|
+// instruction = "(no_printer_for_%s)" % inst_type["value"]
|
|
|
+//
|
|
|
+// if inst_type["value"] == "if":
|
|
|
+// cond, true, false = yield [("RD", [inst, "cond"]),
|
|
|
+// ("RD", [inst, "then"]),
|
|
|
+// ("RD", [inst, "else"])]
|
|
|
+// cond, = yield [("CALL_ARGS", [self.print_instruction, (cond, 0)])]
|
|
|
+// true, = yield [("CALL_ARGS", [self.print_instruction, (true, indent+1)])]
|
|
|
+// if false:
|
|
|
+// false, = yield [("CALL_ARGS", [self.print_instruction, (false, indent+1)])]
|
|
|
+// false = (" " * indent + "else:\n%s\n") % false
|
|
|
+// else:
|
|
|
+// false = ""
|
|
|
+//
|
|
|
+// instruction = " " * indent + "if (" + cond + "):\n" + true + "\n" + false
|
|
|
+// #TODO fix for inline calls
|
|
|
+// elif inst_type["value"] == "constant":
|
|
|
+// node, = yield [("RD", [inst, "node"])]
|
|
|
+// node, = yield [("RV", [node])]
|
|
|
+// if isinstance(node, str):
|
|
|
+// instruction = " " * indent + '"%s"' % node
|
|
|
+// else:
|
|
|
+// 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"
|
|
|
+// #TODO fix for inline calls
|
|
|
+// elif inst_type["value"] == "declare":
|
|
|
+// instruction = ""
|
|
|
+// elif inst_type["value"] == "resolve":
|
|
|
+// value, = yield [("RD", [inst, "var"])]
|
|
|
+// str_value, = yield [("RV", [value])]
|
|
|
+// if str_value:
|
|
|
+// instruction = str_value
|
|
|
+// else:
|
|
|
+// 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"
|
|
|
+// #TODO fix for inline calls
|
|
|
+// elif inst_type["value"] == "call":
|
|
|
+// func_name, = yield [("RD", [inst, "func"])]
|
|
|
+// func_name, = yield [("CALL_ARGS", [self.print_instruction, (func_name, 0)])]
|
|
|
+// param_list = []
|
|
|
+//
|
|
|
+// param, = yield [("RD", [inst, "params"])]
|
|
|
+// while param:
|
|
|
+// value, = yield [("RD", [param, "value"])]
|
|
|
+// res, param = yield [("CALL_ARGS", [self.print_instruction, (value, 0)]),
|
|
|
+// ("RD", [param, "next_param"])]
|
|
|
+// param_list.append(res)
|
|
|
+//
|
|
|
+// if func_name in intrinsics:
|
|
|
+// instruction = " " * indent + intrinsics[func_name](*param_list)
|
|
|
+// else:
|
|
|
+// instruction = " " * indent + func_name + "(" + ", ".join(param_list) + ")"
|
|
|
+// """
|
|
|
+// if indent == 0:
|
|
|
+// #TODO fix for inline calls
|
|
|
+// instruction = 'result, = yield [("CALL_ARGS", (%s, (' % func_name + ",".join(param_list) + ',)))]'
|
|
|
+// else:
|
|
|
+// instruction = " " * indent + 'yield [("CALL_ARGS", (%s, (' % func_name + ",".join(param_list) + ',)))]'
|
|
|
+// """
|
|
|
+// if indent:
|
|
|
+// instruction += "\n"
|
|
|
+// elif inst_type["value"] == "access":
|
|
|
+// value, = yield [("RD", [inst, "var"])]
|
|
|
+// instruction, = yield [("CALL_ARGS", [self.print_instruction, (value, 0)])]
|
|
|
+// 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
|
|
|
+// #TODO fix for inline calls
|
|
|
+//
|
|
|
+// 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(instruction + next_inst)
|
|
|
+
|
|
|
+Boolean function main(model : Element):
|
|
|
+ // Read out the main function
|
|
|
+ String initial_function
|
|
|
+ String al_node
|
|
|
+
|
|
|
+ initial_function = set_pop(allInstances(model, "AL/Initial"))
|
|
|
+ initial_function = set_pop(allAssociationDestinations(model, initial_function))
|
|
|
+ al_node = cast_value(initial_function)
|
|
|
+ log("Read out initial node: " + initial_function)
|
|
|
+ log("Value: " + al_node)
|
|
|
+
|
|
|
+ // Ready, now branch out
|
|
|
+ // TODO
|
|
|
+ return True!
|