|
@@ -107,13 +107,82 @@ String function get_indent(indentation : Integer):
|
|
|
String code
|
|
|
code = ""
|
|
|
while (indentation > 0):
|
|
|
- code = code + "\t"
|
|
|
+ code = code + " "
|
|
|
indentation = indentation - 1
|
|
|
return code!
|
|
|
|
|
|
String function code_print(node : Element, indentation : Integer):
|
|
|
String code
|
|
|
- code = "(no_printer_for_" + cast_value(node) + ")"
|
|
|
+ String inst_type
|
|
|
+
|
|
|
+ inst_type = cast_value(node)
|
|
|
+ code = "(no_printer_for_" + inst_type + ")"
|
|
|
+
|
|
|
+ if (inst_type == "if"):
|
|
|
+ String cond_code
|
|
|
+ String true_code
|
|
|
+ String false_code
|
|
|
+
|
|
|
+ cond_code = code_print(node["cond"], 0)
|
|
|
+ true_code = code_print(node["then"], indentation + 1)
|
|
|
+ if (dict_in(node, "else")):
|
|
|
+ false_code = get_indent(indentation) + "else:\n"
|
|
|
+ false_code = code_print(node["else"], indentation + 1)
|
|
|
+ else:
|
|
|
+ false_code = ""
|
|
|
+
|
|
|
+ code = get_indent(indentation) + "if(" + cond_code + "):\n" + true_code + false_code
|
|
|
+ elif (inst_type == "constant"):
|
|
|
+ String value
|
|
|
+ value = cast_value(node["node"])
|
|
|
+ if (value == "true"):
|
|
|
+ value = "True"
|
|
|
+ elif (value == "false"):
|
|
|
+ value = "False"
|
|
|
+ code = get_indent(indentation) + value
|
|
|
+ elif (inst_type == "return"):
|
|
|
+ if (dict_in(node, "value")):
|
|
|
+ code = get_indent(indentation) + "return " + code_print(node["value"], 0) + "\n"
|
|
|
+ else:
|
|
|
+ code = get_indent(indentation) + "return\n"
|
|
|
+ elif (inst_type == "declare"):
|
|
|
+ code = ""
|
|
|
+ elif (inst_type == "resolve"):
|
|
|
+ if (is_physical_string(node["var"])):
|
|
|
+ code = cast_string(node["var"])
|
|
|
+ else:
|
|
|
+ code = "var_" + cast_id(node["var"])
|
|
|
+ elif (inst_type == "assign"):
|
|
|
+ code = get_indent(indentation) + code_print(node["var"], 0) + " = " + code_print(node["value"], 0) + "\n"
|
|
|
+ elif (inst_type == "access"):
|
|
|
+ code = code_print(node["var"], indentation)
|
|
|
+ elif (inst_type == "while"):
|
|
|
+ code = get_indent(indentation) + "while (" + code_print(node["cond"], 0) + "):\n" + code_print(node["body"], indentation + 1)
|
|
|
+ elif (inst_type == "call"):
|
|
|
+ String func_name
|
|
|
+ String params
|
|
|
+
|
|
|
+ params = ""
|
|
|
+ func_name = code_print(node["func"], 0)
|
|
|
+
|
|
|
+ Element param
|
|
|
+ param = node["params"]
|
|
|
+ while (True):
|
|
|
+ if (params == ""):
|
|
|
+ params = code_print(param["value"], 0)
|
|
|
+ else:
|
|
|
+ params = params + ", " + code_print(param["value"], 0)
|
|
|
+ if (bool_not(dict_in(param, "next_param"))):
|
|
|
+ break!
|
|
|
+ param = param["next_param"]
|
|
|
+
|
|
|
+ code = func_name + "(" + params + ")"
|
|
|
+ if (indentation > 0):
|
|
|
+ code = get_indent(indentation) + code + "\n"
|
|
|
+
|
|
|
+ if (dict_in(node, "next")):
|
|
|
+ code = code + code_print(node["next"], indentation)
|
|
|
+
|
|
|
return code!
|
|
|
|
|
|
Boolean function main(model : Element):
|
|
@@ -124,6 +193,8 @@ Boolean function main(model : Element):
|
|
|
|
|
|
initial_function = set_pop(allInstances(model, "AL/Initial"))
|
|
|
initial_function = set_pop(allAssociationDestinations(model, initial_function, "AL/initial_funcdef"))
|
|
|
+ log("Starting at function " + initial_function)
|
|
|
+ log("Got keys: " + set_to_string(dict_keys(model["model"][initial_function])))
|
|
|
initial_function_element = model["model"][initial_function]["body"]
|
|
|
al_node = cast_value(initial_function_element)
|
|
|
while (cast_value(initial_function_element) == "global"):
|
|
@@ -135,7 +206,7 @@ Boolean function main(model : Element):
|
|
|
log("Started execution at " + cast_value(initial_function_element))
|
|
|
log("Started REAL execution at " + cast_value(initial_function_element))
|
|
|
String code
|
|
|
- code = code_print(initial_function_element, 0)
|
|
|
+ code = code_print(initial_function_element, 1)
|
|
|
log("Generated code:")
|
|
|
log(code)
|
|
|
return True!
|