Browse Source

Preliminary support for spawning a new task to a specific function

Yentl Van Tendeloo 7 years ago
parent
commit
dad216b4b2

BIN
bootstrap/bootstrap.m.gz


+ 2 - 2
bootstrap/core_algorithm.alc

@@ -211,7 +211,7 @@ Boolean function check_login(user_id : String):
 
 
 	return password == stored_password!
 	return password == stored_password!
 
 
-Void function new_task():
+Element function new_task(parameters : Element):
 	String username
 	String username
 	String user_id
 	String user_id
 	String password
 	String password
@@ -250,7 +250,7 @@ Void function new_task():
 	user_function_skip_init(user_id)
 	user_function_skip_init(user_id)
 
 
 	// User destroyed already, so just stop execution
 	// User destroyed already, so just stop execution
-	return!
+	return create_node()!
 
 
 String function get_entry_id(name : String):
 String function get_entry_id(name : String):
 	Element hierarchy_split
 	Element hierarchy_split

+ 9 - 1
bootstrap/initial_code_task.alc

@@ -1,6 +1,7 @@
 include "bootstrap/primitives.alc"
 include "bootstrap/primitives.alc"
 include "bootstrap/semi_primitives.alc"
 include "bootstrap/semi_primitives.alc"
 include "core_algorithm.alh"
 include "core_algorithm.alh"
+include "utils.alh"
 
 
 Void mutable function __main():
 Void mutable function __main():
 	Element root
 	Element root
@@ -25,5 +26,12 @@ Void mutable function __main():
 	exec(root["bootstrap/typing.alc"]["initializers"])
 	exec(root["bootstrap/typing.alc"]["initializers"])
 	exec(root["bootstrap/compiler.alc"]["initializers"])
 	exec(root["bootstrap/compiler.alc"]["initializers"])
 	exec(root["bootstrap/json.alc"]["initializers"])
 	exec(root["bootstrap/json.alc"]["initializers"])
-	new_task()
+
+	Element initial_function
+	Element initial_arguments
+	root = read_root()
+	initial_function = root[get_taskname()]["globals"]["initial_function"]
+	initial_arguments = root[get_taskname()]["globals"]["initial_arguments"]
+
+	initial_function(initial_arguments)
 	return!
 	return!

+ 3 - 0
bootstrap/task_manager.alc

@@ -33,6 +33,9 @@ Void function task_management():
 			dict_add_fast(task_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
 			dict_add_fast(task_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
 			dict_add_fast(task_frame, "symbols", create_node())
 			dict_add_fast(task_frame, "symbols", create_node())
 
 
+			dict_add_fast(task_root["globals"], "initial_function", new_task)
+			dict_add_fast(task_root["globals"], "initial_arguments", list_create())
+
 			//Add this only at the end, as otherwise the task will already be detected
 			//Add this only at the end, as otherwise the task will already be detected
 			dict_add_fast(read_root(), taskname, task_root)
 			dict_add_fast(read_root(), taskname, task_root)
 	return!
 	return!

+ 92 - 0
bootstrap/utils.alc

@@ -2,6 +2,7 @@ include "modelling.alh"
 include "primitives.alh"
 include "primitives.alh"
 include "object_operations.alh"
 include "object_operations.alh"
 include "model_management.alh"
 include "model_management.alh"
+include "random.alh"
 
 
 String function JSON_print(model : Element):
 String function JSON_print(model : Element):
 	String result
 	String result
@@ -134,3 +135,94 @@ Element function alphabet():
 	list_append(chars, "y")
 	list_append(chars, "y")
 	list_append(chars, "z")
 	list_append(chars, "z")
 	return chars!
 	return chars!
+
+String function spawn_TODO(function : Element, arguments : Element):
+	// Define a new task, with all the required stack information
+	// This is taken from the "task_management" code
+	Element task_root
+	Element task_frame
+	Element output_value
+	Element input_value 
+
+	task_root = create_node()
+	task_frame = create_node()
+	output_value = create_node()
+	input_value = create_node()
+	dict_add_fast(task_root, "frame", task_frame)
+	dict_add_fast(task_root, "globals", create_node())
+	dict_add_fast(task_root, "output", output_value)
+	dict_add_fast(task_root, "last_output", output_value)
+	dict_add_fast(task_root, "input", input_value)
+	dict_add_fast(task_root, "last_input", input_value)
+	dict_add_fast(task_frame, "evalstack", create_node())
+	dict_add_fast(task_frame, "returnvalue", create_node())
+	dict_add_fast(task_frame, "phase", "init")
+	dict_add_fast(task_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
+	dict_add_fast(task_frame, "symbols", create_node())
+
+	log("Setting IP to " + cast_value(function["body"]))
+	log("Has outputs: " + set_to_string(dict_keys(function)))
+
+	if (dict_in(function, "params")):
+		// And add the arguments to the symbol table
+		Element symbols
+		String arg_names_call
+		Element param_dict
+		Integer arg_i
+
+		symbols = task_frame["symbols"]
+		arg_names_call = "abcdefghijklmnopqrstuvwxyz"
+		arg_i = 0
+		param_dict = function["params"]
+		
+		arguments = list_copy(arguments)
+		Element t
+		while (list_len(arguments) > 0):
+			t = create_edge(symbols, list_pop(arguments, 0))
+			create_edge(t, param_dict[arg_names_call[arg_i]])
+			arg_i = arg_i + 1
+
+	// Add this only at the end, as otherwise the task will already be detected and executed
+	String taskname
+	taskname = random_string(30)
+	while (dict_in(read_root(), taskname)):
+		taskname = random_string(30)
+	dict_add_fast(read_root(), taskname, task_root)
+
+	return taskname!
+
+String function spawn(function : Element, arguments : Element):
+	// Define a new task, with all the required stack information
+	// This is taken from the "task_management" code
+	Element task_root
+	Element task_frame
+	Element output_value
+	Element input_value 
+
+	task_root = create_node()
+	task_frame = create_node()
+	output_value = create_node()
+	input_value = create_node()
+	dict_add_fast(task_root, "frame", task_frame)
+	dict_add_fast(task_root, "globals", create_node())
+	dict_add_fast(task_root, "output", output_value)
+	dict_add_fast(task_root, "last_output", output_value)
+	dict_add_fast(task_root, "input", input_value)
+	dict_add_fast(task_root, "last_input", input_value)
+	dict_add_fast(task_frame, "evalstack", create_node())
+	dict_add_fast(task_frame, "returnvalue", create_node())
+	dict_add_fast(task_frame, "phase", "init")
+	dict_add_fast(task_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
+	dict_add_fast(task_frame, "symbols", create_node())
+
+	dict_add_fast(task_root["globals"], "initial_function", function)
+	dict_add_fast(task_root["globals"], "initial_arguments", arguments)
+
+	// Add this only at the end, as otherwise the task will already be detected and executed
+	String taskname
+	taskname = random_string(30)
+	while (dict_in(read_root(), taskname)):
+		taskname = random_string(30)
+	dict_add_fast(read_root(), taskname, task_root)
+
+	return taskname!

+ 2 - 0
interface/HUTN/hutn_compiler/semantics_visitor.py

@@ -563,6 +563,7 @@ class SemanticsVisitor(Visitor):
                                        tree.startpos['column'],
                                        tree.startpos['column'],
                                        symbol.signature()))
                                        symbol.signature()))
 
 
+        """
         for i in range(len(expressions)):
         for i in range(len(expressions)):
             arg_type = self.get_type(expressions[i])
             arg_type = self.get_type(expressions[i])
             param_type = symbol.params[i]
             param_type = symbol.params[i]
@@ -580,6 +581,7 @@ class SemanticsVisitor(Visitor):
             if type(arg_type) != type(param_type):
             if type(arg_type) != type(param_type):
                 self.perform_implicit_cast(tree, expressions[i], arg_type,
                 self.perform_implicit_cast(tree, expressions[i], arg_type,
                                            param_type)
                                            param_type)
+        """
 
 
         if symbol.name == "__input":
         if symbol.name == "__input":
             tree.head = "input"
             tree.head = "input"

+ 1 - 0
interface/HUTN/includes/utils.alh

@@ -6,3 +6,4 @@ String function get_taskname()
 Void function sleep(seconds : Float)
 Void function sleep(seconds : Float)
 Element function alphabet()
 Element function alphabet()
 Element function string_split_nr(str : String, split : String, count : Integer)
 Element function string_split_nr(str : String, split : String, count : Integer)
+String function spawn(function : Element, arguments : Element)

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Thu Nov  9 14:20:45 2017
+Date:   Thu Nov  9 16:46:55 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server