|
@@ -190,40 +190,56 @@ String function code_print(node : Element, indentation : Integer):
|
|
|
Boolean function main(model : Element):
|
|
|
// Read out the main function
|
|
|
log("Start up MAIN function")
|
|
|
- String initial_function
|
|
|
String al_node
|
|
|
- Element initial_function_element
|
|
|
+ Element function_element
|
|
|
String code
|
|
|
|
|
|
- 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])))
|
|
|
- log("Parameters:")
|
|
|
- Element params
|
|
|
- String param
|
|
|
- params = dict_keys(model["model"][initial_function]["params"])
|
|
|
- code = "def main("
|
|
|
- while (set_len(params) > 0):
|
|
|
- param = set_pop(params)
|
|
|
- log(" " + param + " --> " + cast_id(model["model"][initial_function]["params"][param]))
|
|
|
- code = code + "var_" + cast_id(model["model"][initial_function]["params"][param])
|
|
|
- if (set_len(params) > 0):
|
|
|
- code = code + ", "
|
|
|
- code = code + "):\n"
|
|
|
+ Element funcdefs
|
|
|
+ String function
|
|
|
+ funcdefs = allInstances(model, "AL/funcdef")
|
|
|
+ while (set_len(funcdefs) > 0):
|
|
|
+ // Iterate over all functions
|
|
|
+ function = set_pop(funcdefs)
|
|
|
+
|
|
|
+ log("Starting at function " + function)
|
|
|
+ log("Got keys: " + set_to_string(dict_keys(model["model"][function])))
|
|
|
+ log("Parameters:")
|
|
|
+ Element params
|
|
|
+ String param
|
|
|
+ params = dict_keys(model["model"][function]["params"])
|
|
|
+ code = "def func_" + function + "):\n"
|
|
|
+ while (set_len(params) > 0):
|
|
|
+ param = set_pop(params)
|
|
|
+ log(" " + param + " --> " + cast_id(model["model"][function]["params"][param]))
|
|
|
+ code = code + "var_" + cast_id(model["model"][function]["params"][param])
|
|
|
+ if (set_len(params) > 0):
|
|
|
+ code = code + ", "
|
|
|
+ code = code + "):\n"
|
|
|
+
|
|
|
+ function_element = model["model"][function]["body"]
|
|
|
+ al_node = cast_value(function_element)
|
|
|
+ while (cast_value(function_element) == "global"):
|
|
|
+ log("Assigning to " + cast_value(function_element["next"]["var"]["var"]))
|
|
|
+ log(" the element: " + cast_id(function_element["next"]["value"]["node"]))
|
|
|
+ log(" keys: " + set_to_string(dict_keys(function_element["next"]["value"]["node"])))
|
|
|
+ log("Function is element: " + cast_id(function_element["next"]["value"]["node"]))
|
|
|
+ function_element = function_element["next"]["next"]
|
|
|
+ log("Started execution at " + cast_value(function_element))
|
|
|
+ log("Started REAL execution at " + cast_value(function_element))
|
|
|
|
|
|
- initial_function_element = model["model"][initial_function]["body"]
|
|
|
- al_node = cast_value(initial_function_element)
|
|
|
- while (cast_value(initial_function_element) == "global"):
|
|
|
- log("Assigning to " + cast_value(initial_function_element["next"]["var"]["var"]))
|
|
|
- log(" the element: " + cast_id(initial_function_element["next"]["value"]["node"]))
|
|
|
- log(" keys: " + set_to_string(dict_keys(initial_function_element["next"]["value"]["node"])))
|
|
|
- log("Function is element: " + cast_id(initial_function_element["next"]["value"]["node"]))
|
|
|
- initial_function_element = initial_function_element["next"]["next"]
|
|
|
- log("Started execution at " + cast_value(initial_function_element))
|
|
|
- log("Started REAL execution at " + cast_value(initial_function_element))
|
|
|
-
|
|
|
- code = code + code_print(initial_function_element, 1)
|
|
|
+ code = code + code_print(function_element, 1)
|
|
|
+
|
|
|
+ log("Finding initial function...")
|
|
|
+ initial_function = set_pop(allInstances(model, "AL/Initial"))
|
|
|
+ initial_function = set_pop(allAssociationDestinations(model, function, "AL/initial_funcdef"))
|
|
|
+ log("Initial function: " + initial_function)
|
|
|
+ code = code + "main = func_" + initial_function + "\n"
|
|
|
+
|
|
|
+ // Found the main function, though we only have the name of the function to assign...
|
|
|
+ // What we can do is reassign main to that function!
|
|
|
+
|
|
|
log("Generated code:")
|
|
|
log(code)
|
|
|
+
|
|
|
+ log("Function block can now be invoked by calling the 'main' function!")
|
|
|
return True!
|