Browse Source

Execute constructor

Yentl Van Tendeloo 8 years ago
parent
commit
ae2fed5425
1 changed files with 11 additions and 3 deletions
  1. 11 3
      models/SCCD_execute.alc

+ 11 - 3
models/SCCD_execute.alc

@@ -111,14 +111,14 @@ Element function expand_parallel_state(model : Element, parallel_state : String)
 
 	return result!
 
-Void function start_class(model : Element, data : Element, class : String):
+Void function start_class(model : Element, data : Element, class : String, identifier : String, parameters : Element):
 	// Start up the class and assign its initial state to it
 
 	// Create the data structure for a running class
 	Element class_handle
 	class_handle = create_node()
 	dict_add(class_handle, "type", class)
-	dict_add(class_handle, "ID", cast_id2s(create_node()))
+	dict_add(class_handle, "ID", identifier)
 	dict_add(class_handle, "timers", create_node())
 
 	// Add the current state of the class
@@ -136,6 +136,14 @@ Void function start_class(model : Element, data : Element, class : String):
 		dict_add(attributes, read_attribute(model, set_pop(attrs), "name"), read_root())
 	dict_add(class_handle, "attributes", attributes)
 
+	// Invoke constructor
+	Element constructor
+	constructor = read_attribute(model, class, "constructor_body")
+	if (element_neq(constructor, read_root())):
+		// Constructor, so execute
+		constructor = get_func_AL_model(import_node(constructor))
+		constructor(attributes, parameters)
+
 	// Execute all entry actions
 	Element init
 	init = create_node()
@@ -574,7 +582,7 @@ Boolean function main(model : Element):
 	default_class = set_pop(filter(model, allInstances(model, "SCCD/Class"), "default", True))
 
 	// Start up the default class
-	start_class(model, data, default_class)
+	start_class(model, data, default_class, "main", create_node())
 
 	Float timeout
 	Element interrupt