|
@@ -16,6 +16,9 @@ Element function construct_function_list(list : Element):
|
|
|
Element prev_element
|
|
|
Element first_element
|
|
|
|
|
|
+ Element model
|
|
|
+ model = instantiate_model("formalisms/SimpleClassDiagrams")
|
|
|
+
|
|
|
list = list_reverse(list)
|
|
|
|
|
|
// Initialize variables
|
|
@@ -30,11 +33,11 @@ Element function construct_function_list(list : Element):
|
|
|
while (continue):
|
|
|
command = list_pop_final(list)
|
|
|
if (command == "global"):
|
|
|
- result = construct_global(list)
|
|
|
+ result = construct_global(model, list)
|
|
|
elif (command == "funcdef"):
|
|
|
- result = construct_funcdef(False, list)
|
|
|
+ result = construct_funcdef(model, list, False)
|
|
|
elif (command == "mutable_funcdef"):
|
|
|
- result = construct_funcdef(True, list)
|
|
|
+ result = construct_funcdef(model, list, True)
|
|
|
else:
|
|
|
log("ERROR (1): did not understand command " + cast_value(command))
|
|
|
output("ERROR: compiled code not understood: " + cast_value(command))
|
|
@@ -64,13 +67,14 @@ Element function construct_function_list(list : Element):
|
|
|
|
|
|
// Overwrite the main function with our declaration function
|
|
|
prev_element = main_function["body"]
|
|
|
+ log("Got parameters for main function: " + set_to_string(dict_keys(main_function)))
|
|
|
dict_delete(main_function, "body")
|
|
|
dict_add_fast(main_function, "body", first_element)
|
|
|
dict_add_fast(result["end"], "next", prev_element)
|
|
|
|
|
|
return main_function!
|
|
|
|
|
|
-Action function construct_global(list : Element):
|
|
|
+Action function construct_global(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
String declared_element
|
|
|
String op
|
|
@@ -123,7 +127,7 @@ Action function construct_global(list : Element):
|
|
|
dict_add_fast(result, "end", this_element)
|
|
|
return result!
|
|
|
|
|
|
-Action function construct_funcdef(mutable : Boolean, list : Element):
|
|
|
+Action function construct_funcdef(model : Element, list : Element, mutable : Boolean):
|
|
|
Action assign
|
|
|
Action resolve
|
|
|
Action constant
|
|
@@ -173,7 +177,7 @@ Action function construct_funcdef(mutable : Boolean, list : Element):
|
|
|
counter = counter + 1
|
|
|
|
|
|
// Now add the body
|
|
|
- dict_add_fast(func, "body", construct_unknown(list))
|
|
|
+ dict_add_fast(func, "body", construct_unknown(model, list))
|
|
|
|
|
|
Element result
|
|
|
result = dict_create()
|
|
@@ -183,76 +187,76 @@ Action function construct_funcdef(mutable : Boolean, list : Element):
|
|
|
dict_add_fast(result, "end", assign)
|
|
|
return result!
|
|
|
|
|
|
-Element function construct_unknown(list : Element):
|
|
|
+Element function construct_unknown(model : Element, list : Element):
|
|
|
String elem
|
|
|
Element new_model
|
|
|
Element new_model_model
|
|
|
elem = list_pop_final(list)
|
|
|
|
|
|
if (elem == "if"):
|
|
|
- return construct_if(list)!
|
|
|
+ return construct_if(model, list)!
|
|
|
elif (elem == "while"):
|
|
|
- return construct_while(list)!
|
|
|
+ return construct_while(model, list)!
|
|
|
elif (elem == "access"):
|
|
|
- return construct_access(list)!
|
|
|
+ return construct_access(model, list)!
|
|
|
elif (elem == "resolve"):
|
|
|
- return construct_resolve(list)!
|
|
|
+ return construct_resolve(model, list)!
|
|
|
elif (elem == "assign"):
|
|
|
- return construct_assign(list)!
|
|
|
+ return construct_assign(model, list)!
|
|
|
elif (elem == "call"):
|
|
|
- return construct_call(list)!
|
|
|
+ return construct_call(model, list)!
|
|
|
elif (elem == "return"):
|
|
|
- return construct_return(list)!
|
|
|
+ return construct_return(model, list)!
|
|
|
elif (elem == "const"):
|
|
|
- return construct_const(list)!
|
|
|
+ return construct_const(model, list)!
|
|
|
elif (elem == "declare"):
|
|
|
- return construct_declare(list)!
|
|
|
+ return construct_declare(model, list)!
|
|
|
elif (elem == "output"):
|
|
|
- return construct_output(list)!
|
|
|
+ return construct_output(model, list)!
|
|
|
elif (elem == "input"):
|
|
|
- return construct_input(list)!
|
|
|
+ return construct_input(model, list)!
|
|
|
elif (elem == "deref"):
|
|
|
- return construct_deref(list)!
|
|
|
+ return construct_deref(model, list)!
|
|
|
elif (elem == "break"):
|
|
|
- return construct_break(list)!
|
|
|
+ return construct_break(model, list)!
|
|
|
elif (elem == "continue"):
|
|
|
- return construct_continue(list)!
|
|
|
+ return construct_continue(model, list)!
|
|
|
else:
|
|
|
log("ERROR (2): did not understand command " + cast_value(elem))
|
|
|
output("ERROR: compiled code not understood: " + cast_value(elem))
|
|
|
return read_root()!
|
|
|
|
|
|
-Action function construct_if(list : Element):
|
|
|
+Action function construct_if(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!if)
|
|
|
- dict_add_fast(this_element, "cond", construct_unknown(list))
|
|
|
- dict_add_fast(this_element, "then", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "cond", construct_unknown(model, list))
|
|
|
+ dict_add_fast(this_element, "then", construct_unknown(model, list))
|
|
|
if (list_pop_final(list)):
|
|
|
- dict_add_fast(this_element, "else", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "else", construct_unknown(model, list))
|
|
|
if (list_pop_final(list)):
|
|
|
- dict_add_fast(this_element, "next", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "next", construct_unknown(model, list))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_while(list : Element):
|
|
|
+Action function construct_while(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!while)
|
|
|
- dict_add_fast(this_element, "cond", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "cond", construct_unknown(model, list))
|
|
|
|
|
|
list_append(while_stack, this_element)
|
|
|
- dict_add_fast(this_element, "body", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "body", construct_unknown(model, list))
|
|
|
list_delete(while_stack, list_len(while_stack) - 1)
|
|
|
|
|
|
if (list_pop_final(list)):
|
|
|
- dict_add_fast(this_element, "next", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "next", construct_unknown(model, list))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_access(list : Element):
|
|
|
+Action function construct_access(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!access)
|
|
|
- dict_add_fast(this_element, "var", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "var", construct_unknown(model, list))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_resolve(list : Element):
|
|
|
+Action function construct_resolve(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
Element linked_element
|
|
|
String name
|
|
@@ -266,19 +270,19 @@ Action function construct_resolve(list : Element):
|
|
|
dict_add_fast(this_element, "var", linked_element)
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_assign(list : Element):
|
|
|
+Action function construct_assign(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!assign)
|
|
|
- dict_add_fast(this_element, "var", construct_unknown(list))
|
|
|
- dict_add_fast(this_element, "value", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "var", construct_unknown(model, list))
|
|
|
+ dict_add_fast(this_element, "value", construct_unknown(model, list))
|
|
|
if (list_pop_final(list)):
|
|
|
- dict_add_fast(this_element, "next", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "next", construct_unknown(model, list))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_call(list : Element):
|
|
|
+Action function construct_call(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!call)
|
|
|
- dict_add_fast(this_element, "func", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "func", construct_unknown(model, list))
|
|
|
|
|
|
Integer nrParams
|
|
|
nrParams = list_pop_final(list)
|
|
@@ -294,7 +298,7 @@ Action function construct_call(list : Element):
|
|
|
param = create_node()
|
|
|
|
|
|
dict_add_fast(param, "name", string_get(arg_names_call, counter))
|
|
|
- dict_add_fast(param, "value", construct_unknown(list))
|
|
|
+ dict_add_fast(param, "value", construct_unknown(model, list))
|
|
|
|
|
|
if (counter == 0):
|
|
|
dict_add_fast(this_element, "params", param)
|
|
@@ -308,25 +312,25 @@ Action function construct_call(list : Element):
|
|
|
dict_add_fast(this_element, "last_param", prev_param)
|
|
|
|
|
|
if (list_pop_final(list)):
|
|
|
- dict_add_fast(this_element, "next", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "next", construct_unknown(model, list))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_return(list : Element):
|
|
|
+Action function construct_return(model : Element, list : Element):
|
|
|
if (list_pop_final(list)):
|
|
|
Action this_element
|
|
|
this_element = create_value(!return)
|
|
|
- dict_add_fast(this_element, "value", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "value", construct_unknown(model, list))
|
|
|
return this_element!
|
|
|
else:
|
|
|
return create_value(!return)!
|
|
|
|
|
|
-Action function construct_const(list : Element):
|
|
|
+Action function construct_const(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!constant)
|
|
|
dict_add_fast(this_element, "node", list_pop_final(list))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_declare(list : Element):
|
|
|
+Action function construct_declare(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
Element declared_element
|
|
|
String name
|
|
@@ -367,38 +371,38 @@ Action function construct_declare(list : Element):
|
|
|
dict_add_fast(assign, "value", value)
|
|
|
|
|
|
if (list_pop_final(list)):
|
|
|
- dict_add_fast(assign, "next", construct_unknown(list))
|
|
|
+ dict_add_fast(assign, "next", construct_unknown(model, list))
|
|
|
else:
|
|
|
if (list_pop_final(list)):
|
|
|
- dict_add_fast(this_element, "next", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "next", construct_unknown(model, list))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_input(list : Element):
|
|
|
+Action function construct_input(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!input)
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_output(list : Element):
|
|
|
+Action function construct_output(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!output)
|
|
|
- dict_add_fast(this_element, "value", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "value", construct_unknown(model, list))
|
|
|
if (list_pop_final(list)):
|
|
|
- dict_add_fast(this_element, "next", construct_unknown(list))
|
|
|
+ dict_add_fast(this_element, "next", construct_unknown(model, list))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_deref(list : Element):
|
|
|
+Action function construct_deref(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!constant)
|
|
|
dict_add_fast(this_element, "node", import_node(list_pop_final(list)))
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_break(list : Element):
|
|
|
+Action function construct_break(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!break)
|
|
|
dict_add_fast(this_element, "while", while_stack[list_len(while_stack) - 1])
|
|
|
return this_element!
|
|
|
|
|
|
-Action function construct_continue(list : Element):
|
|
|
+Action function construct_continue(model : Element, list : Element):
|
|
|
Action this_element
|
|
|
this_element = create_value(!continue)
|
|
|
dict_add_fast(this_element, "while", while_stack[list_len(while_stack) - 1])
|