Browse Source

Partially pre-compile instantiate_link

Yentl Van Tendeloo 5 years ago
parent
commit
47a45b8c57
3 changed files with 50 additions and 4 deletions
  1. BIN
      bootstrap/bootstrap.m.gz
  2. 5 4
      bootstrap/modelling.alc
  3. 45 0
      kernel/modelverse_kernel/compiled.py

BIN
bootstrap/bootstrap.m.gz


+ 5 - 4
bootstrap/modelling.alc

@@ -308,8 +308,6 @@ Void function instantiate_existing_attribute(model : Element, element : String,
 
 String function instantiate_link(model : Element, type : String, name : String, source : String, destination : String):
 	// Create a typed link between two nodes
-	String actual_name
-
 	if (type == ""):
 		// Have to find the type ourselves, as it isn't defined
 		Element out
@@ -332,20 +330,23 @@ String function instantiate_link(model : Element, type : String, name : String,
 
 	if (bool_not(dict_in(model["model"], source))):
 		log("ERROR: source of link undefined: " + source)
-		set_pop(create_node())
 		return ""!
 
 	if (bool_not(dict_in(model["model"], destination))):
 		log("ERROR: destination of link undefined: " + destination)
-		set_pop(create_node())
 		return ""!
 
 	if (bool_not(dict_in(model["metamodel"]["model"], type))):
 		log("ERROR: (instantiate_link) no such type in metamodel: " + type)
 		log("    for " + name)
 		return ""!
+
+	return instantiate_typed_link(model, type, name, source, destination)!
 	
+String function instantiate_typed_link(model : Element, type : String, name : String, source : String, destination : String):
 	Element v
+	String actual_name
+
 	v = create_edge(model["model"][source], model["model"][destination])
 	actual_name = instantiated_name(v, name)
 	dict_add_fast(model["model"], actual_name, v)

+ 45 - 0
kernel/modelverse_kernel/compiled.py

@@ -373,6 +373,51 @@ def instantiate_node(a, b, c, **remainder):
 
     yield [("RETURN", [name_node])]
 
+def instantiate_typed_link(a, b, c, d, e, **remainder):
+    if "value" not in b:
+        b['value'], = yield [("RV", [b['id']])]
+
+    if "value" not in c:
+        c['value'], = yield [("RV", [c['id']])]
+        
+    if "value" not in d:
+        d['value'], = yield [("RV", [d['id']])]
+        
+    if "value" not in e:
+        e['value'], = yield [("RV", [e['id']])]
+        
+    dict_entry, tm = yield [\
+               ("RD", [a['id'], "model"]),
+               ("RD", [a['id'], "type_mapping"]),
+              ]
+    src, dst = yield [\
+                ("RD", [dict_entry, d['value']]),
+                ("RD", [dict_entry, e['value']]),
+              ]
+    node, = yield [("CE", [src, dst])]
+    if c['value'] == "":
+        name = "__" + str(node)
+        name_node = {'value': name}
+    else:
+        name = c['value']
+        name_node = c
+
+    _, root = yield [("CD", [dict_entry, name, node]),
+                     ("RD", [tm, "root"])]
+
+    # Create new type links
+    type_elem, instance_elem = yield [("CNV", [b['value']]), ("CNV", [name])]
+    type_link, = yield [("CE", [root, type_elem])]
+    instance_link, = yield [("CE", [type_link, instance_elem])]
+
+    # Add them to the model
+    yield  [("CD", [tm, str(type_elem), type_elem]),
+            ("CD", [tm, str(instance_elem), instance_elem]),
+            ("CD", [tm, str(type_link), type_link]),
+            ("CD", [tm, str(instance_link), instance_link])]
+
+    yield [("RETURN", [name_node])]
+
 def list_insert(a, b, c, **remainder):
     if "id" not in b:
         b["id"], = yield [("CNV", [b['value']])]