Browse Source

Fixed bootstrapper

Yentl Van Tendeloo 9 years ago
parent
commit
a61648ff2e

+ 2 - 1
bootstrap/bootstrap.py

@@ -79,10 +79,11 @@ primitives = {  "integer_addition": ["Integer", "Integer", "Integer"],
                 "set_in": ["Boolean", "Element", "Element"],
                 "set_in_node": ["Boolean", "Element", "Element"],
                 "is_physical_int": ["Boolean", "Element"],
-                "is_physical_bool": ["Boolean", "Element"],
+                "is_physical_boolean": ["Boolean", "Element"],
                 "is_physical_string": ["Boolean", "Element"],
                 "is_physical_action": ["Boolean", "Element"],
                 "is_physical_float": ["Boolean", "Element"],
+                "has_value": ["Boolean", "Element"],
                 "create_node": ["Element"],
                 "create_edge": ["Element", "Element", "Element"],
                 "create_value": ["Element", "Element"],

+ 2 - 5
bootstrap/conformance_scd.alc

@@ -200,7 +200,7 @@ Element function instantiate_model_lib(model : Element, type : Element, name : S
 		// Create a new edge from "optionals[0]" to "optionals[1]"
 		new_element = instantiate_bottom_edge(model, name, list_read(optionals, 0), list_read(optionals, 1))
 	else:
-		if (typeof(type) == Type):
+		if (has_value(type)):
 			new_element = instantiate_bottom_value(model, name, list_read(optionals, 0))
 		else:
 			new_element = instantiate_bottom_node(model, name)
@@ -307,9 +307,6 @@ Element function generate_bottom_type_mapping(model : Element):
 		if (is_edge(elem)):
 			dict_add(tm, elem, mm["Edge"])
 		else:
-			if (cast_v2s(elem) != "None"):
-				dict_add(tm, elem, mm[cast_v2s(typeof(elem))])
-			else:
-				dict_add(tm, elem, mm["Node"])
+			dict_add(tm, elem, mm["Node"])
 
 	return model

+ 1 - 1
bootstrap/constructors.alc

@@ -363,7 +363,7 @@ Void function instantiate_model(model : Element):
 	if (is_edge(type)):
 		list_append(params, model["model"][input()])
 		list_append(params, model["model"][input()])
-	elif (type_eq(typeof(type), Type)):
+	elif (has_value(type)):
 		list_append(params, input())
 
 	Element attribute_types

+ 3 - 3
bootstrap/object_operations.alc

@@ -127,8 +127,8 @@ Element function getAttributeList(model : Element, mm : Element):
 	Element e
 	while (0 < read_nr_out(set_own)):
 		e = set_pop(set_own)
-		if (typeof(e) == String):
-			if (typeof(mm[e]) == Type):
+		if (is_physical_string(e)):
+			if (has_value(mm[e])):
 				// This is a primitive type, so add to the list
 				dict_add(result, e, mm[e])
 
@@ -162,7 +162,7 @@ Element function getInstantiatableAttributes(model : Element, element : Element)
 	Element e
 	while (0 < read_nr_out(set_own)):
 		e = set_pop(set_own)
-		if (bool_and(typeof(e) == String, typeof(element[e]) == Type)):
+		if (bool_and(is_physical_string(e), has_value(element[e]))):
 			// This is a primitive type, so add to the list
 			dict_add(result, e, element[e])
 

+ 1 - 1
bootstrap/primitives.alc

@@ -30,7 +30,6 @@ Float function cast_b2f(a: Boolean) = ?primitives/cast_b2f
 String function cast_b2s(a: Boolean) = ?primitives/cast_b2s
 String function cast_e2s(a: Element) = ?primitives/cast_e2s
 String function cast_a2s(a: Action) = ?primitives/cast_a2s
-String function cast_t2s(a: Type) = ?primitives/cast_t2s
 String function cast_v2s(a: Element) = ?primitives/cast_v2s
 String function cast_id2s(a: Element) = ?primitives/cast_id2s
 Element function dict_add(a: Element, b: Element, c: Element) = ?primitives/dict_add
@@ -85,6 +84,7 @@ Boolean function is_physical_float(a: Element) = ?primitives/is_physical_float
 Boolean function is_physical_string(a: Element) = ?primitives/is_physical_string
 Boolean function is_physical_boolean(a: Element) = ?primitives/is_physical_boolean
 Boolean function is_physical_action(a: Element) = ?primitives/is_physical_action
+Boolean function has_value(a: Element) = ?primitives/has_value
 
 Element function exec(first_instr : Element):
 	// This does very ugly things, so beware!

+ 5 - 5
interface/HUTN/hutn_compiler/semantics_visitor.py

@@ -294,15 +294,15 @@ class SemanticsVisitor(Visitor):
         if str(operand_type) == "String":
             if operator.head == "PLUS":
                 return "string_join"
-        elif operator.head == "EQ":
+
+        if operator.head == "EQ":
             return "value_eq"
         elif operator.head == "NEQ":
             return "value_neq"
-        else:
-            call_name = "{}_{}".format(SemanticsVisitor.types[str(operand_type)],
-                                       SemanticsVisitor.binary_ops[operator.head])
 
-            return call_name
+        call_name = "{}_{}".format(SemanticsVisitor.types[str(operand_type)],
+                                   SemanticsVisitor.binary_ops[operator.head])
+        return call_name
 
     @staticmethod
     def call_name_unary(operand_type, operator):

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

@@ -88,3 +88,4 @@ Boolean function is_physical_float(a : Element)
 Boolean function is_physical_string(a : Element)
 Boolean function is_physical_action(a : Element)
 Boolean function is_physical_boolean(a : Element)
+Boolean function has_value(a : Element)

+ 6 - 1
kernel/modelverse_kernel/primitives.py

@@ -348,11 +348,16 @@ def is_physical_float(a, **remainder):
     result = yield [("CNV", [isinstance(t, float)])]
     raise PrimitiveFinished(result)
 
-def is_physical_bool(a, **remainder):
+def is_physical_boolean(a, **remainder):
     t = yield [("RV", [a])]
     result = yield [("CNV", [isinstance(t, bool)])]
     raise PrimitiveFinished(result)
 
+def has_value(a, **remainder):
+    t = yield [("RV", [a])]
+    result = yield [("CNV", [t is not None])]
+    raise PrimitiveFinished(result)
+
 def is_physical_action(a, **remainder):
     t = yield [("RV", [a])]
     result = yield [("CNV", [isinstance(t, dict) and t["value"] in ["if", "while", "assign", "call", "break", "continue", "return", "resolve", "access", "constant", "global", "declare"]])]