Bladeren bron

Fixed bootstrap file: everything loads

Yentl Van Tendeloo 8 jaren geleden
bovenliggende
commit
46dfcb1bc6

+ 9 - 56
bootstrap/core_algorithm.alc

@@ -12,6 +12,9 @@ include "metamodels.alh"
 
 Element core = ?
 
+String admin_username = "admin"
+String admin_password = "admin"
+
 String core_location = "models/CoreFormalism"
 String core_model_location = "core"
 
@@ -68,7 +71,7 @@ String function JSON_print(model : Element):
 
 	return result!
 
-Void function main():
+Void function initialize_core():
 	// Initialize the Core Formalism
 	String core_model
 	String core_formalism_model
@@ -108,18 +111,6 @@ Void function main():
 	export_node(core_model_location, core)
 	export_node(coreM_model_location, core["model"])
 
-	// Switch all new users to the user_function
-	// This accesses the bootstrap level, so do not change this unless you know what you are doing
-	Element root
-	Element prev
-	root = read_root()
-	root = root["__hierarchy"]["__IP"]
-	while (value_neq(root, !call)):
-		prev = root
-		root = root["next"]
-	dict_delete(prev, "next")
-	dict_add(prev, "next", user_function["body"])
-
 	// Create admin group
 	admin_group = instantiate_node(core, "Group", "")
 	instantiate_attribute(core, admin_group, "name", "admin")
@@ -130,23 +121,10 @@ Void function main():
 
 	// Create admin user
 	admin_user = instantiate_node(core, "User", "")
-	output("Desired username for admin user?")
-	instantiate_attribute(core, admin_user, "name", input())
+	instantiate_attribute(core, admin_user, "name", admin_username)
 	instantiate_attribute(core, admin_user, "admin", True)
 
-	String password
-
-	while (True):
-		output("Desired password for admin user?")
-		password = hash(input())
-
-		output("Please repeat the password")
-		if (password == hash(input())):
-			output("Passwords match!")
-			instantiate_attribute(core, admin_user, "password", password)
-			break!
-		else:
-			output("Not the same password, please try again!")
+	instantiate_attribute(core, admin_user, "password", hash(admin_password))
 
 	// Create link between admin user and group
 	instantiate_link(core, "ownedBy", "", admin_group, admin_user)
@@ -241,12 +219,7 @@ Void function main():
 	instantiate_link(core, "owner", "", core_model, admin_user)
 
 	// Call this for ourselves as well
-	log("MvC is ready!")
-	user_function_skip_init(admin_user)
-
-	// Done, so finish up
-	// Admin user will have been deleted by the user_function as usual
-	// Note that if there are no admin users left, it will be very difficult to manage, as nobody will have admin permissions!
+	//log("MvC is ready!")
 	return !
 
 String function get_instanceOf_link(model_id : String):
@@ -370,28 +343,11 @@ Element function extract_ftg(user_id : String):
 
 	return create_node()!
 
-Element function user_function():
+Void function new_task():
 	String username
 	String user_id
 	String password
 
-	// Load in all global variables, as this code is hotloaded!
-	Element root
-	root = read_root()
-	root = root["__hierarchy"]["objects"]
-	exec(root["bootstrap/modelling.alc"]["initializers"])
-	exec(root["bootstrap/library.alc"]["initializers"])
-	exec(root["bootstrap/constructors.alc"]["initializers"])
-	exec(root["bootstrap/object_operations.alc"]["initializers"])
-	exec(root["core/mini_modify.alc"]["initializers"])
-	exec(root["bootstrap/model_management.alc"]["initializers"])
-	exec(root["bootstrap/ramify.alc"]["initializers"])
-	exec(root["bootstrap/transform.alc"]["initializers"])
-	exec(root["bootstrap/conformance_scd.alc"]["initializers"])
-	exec(root["bootstrap/metamodels.alc"]["initializers"])
-	exec(root["bootstrap/random.alc"]["initializers"])
-	exec(root["core/core_algorithm.alc"]["initializers"])
-
 	// Load in a hard-reference to the previously created model
 	core = import_node(core_model_location)
 
@@ -426,8 +382,7 @@ Element function user_function():
 	user_function_skip_init(user_id)
 
 	// User destroyed already, so just stop execution
-	// TODO return a fresh node as otherwise the compiler doesn't take this
-	return create_node()!
+	return!
 
 String function get_model_id(name : String):
 	Element models
@@ -1159,7 +1114,6 @@ String function cmd_model_delete(user_id : String, model_name : String):
 
 String function cmd_model_list():
 	// List all models
-	log("Start model list @ " + cast_v2s(time()))
 	Element models
 	String result
 	String m
@@ -1169,7 +1123,6 @@ String function cmd_model_list():
 	while (read_nr_out(models) > 0):
 		m = set_pop(models)
 		result = (result + string_join((string_join("  ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name"))) + "\n"
-	log("Finish model list @ " + cast_v2s(time()))
 	return result!
 
 String function cmd_model_list_full():

+ 2 - 1
bootstrap/initial_code_manager.alc

@@ -10,8 +10,9 @@ Void function __main():
 	exec(root["bootstrap/library.alc"]["initializers"])
 	exec(root["bootstrap/object_operations.alc"]["initializers"])
 	exec(root["bootstrap/conformance_scd.alc"]["initializers"])
-	exec(root["bootstrap/metamodels.alc"]["initializers"])
+	exec(root["bootstrap/.metamodels.alc"]["initializers"])
 	exec(root["bootstrap/modelling.alc"]["initializers"])
 	exec(root["bootstrap/task_manager.alc"]["initializers"])
+	exec(root["bootstrap/core_algorithm.alc"]["initializers"])
 	task_management()
 	return!

+ 10 - 5
bootstrap/initial_code_task.alc

@@ -1,17 +1,22 @@
 include "bootstrap/primitives.alc"
-include "task_interface.alh"
+include "bootstrap/core_algorithm.alc"
 
 Void mutable function __main():
 	Element root
 	root = read_root()
 	root = root["__hierarchy"]["objects"]
 	exec(root["bootstrap/compilation_manager.alc"]["initializers"])
-	exec(root["bootstrap/constructors.alc"]["initializers"])
+	exec(root["bootstrap/.metamodels.alc"]["initializers"])
+	exec(root["bootstrap/mini_modify.alc"]["initializers"])
+	exec(root["bootstrap/core_algorithm.alc"]["initializers"])
+	exec(root["bootstrap/modelling.alc"]["initializers"])
 	exec(root["bootstrap/library.alc"]["initializers"])
+	exec(root["bootstrap/constructors.alc"]["initializers"])
 	exec(root["bootstrap/object_operations.alc"]["initializers"])
+	exec(root["bootstrap/model_management.alc"]["initializers"])
+	exec(root["bootstrap/ramify.alc"]["initializers"])
+	exec(root["bootstrap/transform.alc"]["initializers"])
 	exec(root["bootstrap/conformance_scd.alc"]["initializers"])
-	exec(root["bootstrap/metamodels.alc"]["initializers"])
-	exec(root["bootstrap/modelling.alc"]["initializers"])
-	exec(root["bootstrap/task_interface.alc"]["initializers"])
+	exec(root["bootstrap/random.alc"]["initializers"])
 	new_task()
 	return!

+ 0 - 27
bootstrap/task_interface.alc

@@ -1,27 +0,0 @@
-// Do this only in the bootstrapper
-include "io.alh"
-include "primitives.alh"
-include "compilation_manager.alh"
-include "constructors.alh"
-include "modelling.alh"
-
-Void mutable function new_task():
-	Integer interface
-	while (True):
-		interface = input()
-		if (interface == 0):
-			exec(deserialize(input()))
-		elif (interface == 1):
-			exec(construct_unknown())
-		elif (interface == 2):
-			output("DONE")
-		elif (interface == 3):
-			compilation_manager()
-		elif (interface == 4):
-			construct_model()
-		elif (interface == -1):
-			return!
-		else:
-			log("Unsupported interface!")
-
-	return!

+ 2 - 0
bootstrap/task_manager.alc

@@ -1,6 +1,7 @@
 include "io.alh"
 include "primitives.alh"
 include "metamodels.alh"
+include "core_algorithm.alh"
 
 Void function task_management():
 	String taskname
@@ -11,6 +12,7 @@ Void function task_management():
 
 	// Initialize the basic formalisms before allowing new users
 	initialize_MMs()
+	initialize_core()
 	
 	while (True):
 		taskname = input()

+ 2 - 2
interface/HUTN/hutn_compiler/model_bootstrap_visitor.py

@@ -44,7 +44,7 @@ class ModelBootstrapVisitor(Visitor):
         url = tree.get_children("MV_URL")[0]
         target = tree.get_children("MODEL_ID")[0]
         #self.constructors.extend(["export_node", target.get_text(), url.get_text()])
-        self.code += '\texport_node(%s, "%s")\n' % (target.get_text(), url.get_text())
+        self.code += '\texport_node("%s", %s)\n' % (url.get_text(), target.get_text())
 
     def visit_model(self, tree):
         children = tree.get_children("MODEL_ID")
@@ -52,7 +52,7 @@ class ModelBootstrapVisitor(Visitor):
         model_name = children[-1].get_text()
         #self.constructors.extend(["instantiate_model", model_type, model_name])
         self.code += "\tElement %s\n" % model_name
-        self.code += '\t%s = instantiate_model("%s")\n' % (model_name, model_type)
+        self.code += '\t%s = instantiate_model(%s)\n' % (model_name, model_type)
         self.current_model = model_name
         self.names = set()
         for element in tree.get_children("model_element"):

+ 2 - 0
interface/HUTN/includes/core_algorithm.alh

@@ -0,0 +1,2 @@
+Void function initialize_core()
+Void function new_task()