Browse Source

Add a way to update the core library from within the Modelverse itself,
although it consumes quite a bit of memory

Yentl Van Tendeloo 3 years ago
parent
commit
177006c5ba
3 changed files with 20 additions and 10 deletions
  1. 5 5
      bootstrap/constructors.alc
  2. 5 5
      kernel/modelverse_kernel/primitives.py
  3. 10 0
      scripts/upload_core.py

+ 5 - 5
bootstrap/constructors.alc

@@ -99,8 +99,7 @@ String function construct_global(model : Element, list : Element):
 		create_al_link(model, "assign_var", assign, resolve, "var")
 		create_al_link(model, "resolve_var", resolve, declared_element, "var")
 		if (op == "deref"):
-			value = instantiate_value(model, "constant", "", create_value(!constant))
-			create_al_link(model, "constant_node", value, instantiate_value(model, "String", "", list_pop_final(list)), "node")
+			value = construct_deref(model, list)
 		elif (op == "empty"):
 			value = instantiate_value(model, "call", "", create_value(!call))
 			String res
@@ -358,8 +357,7 @@ String function construct_declare(model : Element, list : Element):
 		create_al_link(model, "assign_var", assign, resolve, "var")
 		create_al_link(model, "resolve_var", resolve, declared_element, "var")
 		if (op == "deref"):
-			value = instantiate_value(model, "constant", "", create_value(!constant))
-			create_al_link(model, "constant_node", value, reuse_element(model, "Element", "", import_node(list_pop_final(list))), "node")
+			value = construct_deref(model, list)
 		elif (op == "empty"):
 			value = instantiate_value(model, "call", "", create_value(!call))
 			Element res
@@ -396,7 +394,9 @@ String function construct_output(model : Element, list : Element):
 String function construct_deref(model : Element, list : Element):
 	String this_element
 	this_element = instantiate_value(model, "constant", "", create_value(!constant))
-	create_al_link(model, "constant_node", this_element, reuse_element(model, "Element", "", import_node(list_pop_final(list))), "node")
+	String val
+	val = list_pop_final(list)
+	create_al_link(model, "constant_node", this_element, reuse_element(model, "Element", "", import_node(val)), "node")
 	return this_element!
 
 String function construct_break(model : Element, list : Element):

+ 5 - 5
kernel/modelverse_kernel/primitives.py

@@ -83,11 +83,6 @@ def bool_or(a, b, **remainder):
         b['value'], = yield [("RV", [b['id']])]
     yield [("RETURN", [{'value': a['value'] or b['value']}])]
 
-def bool_not(a, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    yield [("RETURN", [{'value': not a['value']}])]
-
 def float_subtraction(a, b, **remainder):
     if 'value' not in a:
         a['value'], = yield [("RV", [a['id']])]
@@ -453,3 +448,8 @@ def list_sort(a, **remainder):
     yield [("CD", [new_list, i, v]) for i, v in enumerate(values)]
 
     yield [("RETURN", [{'id': new_list}])]
+
+def bool_not(a, **remainder):
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    yield [("RETURN", [{'value': not a['value']}])]

+ 10 - 0
scripts/upload_core.py

@@ -0,0 +1,10 @@
+import sys
+sys.path.append("wrappers")
+from modelverse import *
+
+init()
+login("admin", "admin")
+transformation_add_AL({}, {}, "models/core_library", open("bootstrap/merged.alm", 'r').read() + """
+Boolean function main(model : Element):
+\treturn False!
+""")