Yentl Van Tendeloo 9 роки тому
батько
коміт
4426160ea0

+ 3 - 22
bootstrap/conformance_scd.alc

@@ -173,9 +173,9 @@ String function conformance_scd(model : Element):
 			constraint_function = read_attribute(model["metamodel"], reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], element)), "constraint")
 			if (element_neq(constraint_function, read_root())):
 				String result
-				// TODO define the local_constraint execution function
-				log("Exec constraint!")
-				result = execute_local_constraint(model, model_name)
+				log("Calling constraint function!")
+				result = constraint_function(model, model_name)
+				log("Done: result " + result)
 				if (result != "OK"):
 					return result
 
@@ -236,22 +236,3 @@ Element function generate_bottom_type_mapping(model : Element):
 			dict_add(tm, elem, mm["Node"])
 
 	return model
-
-String function execute_local_constraint(model : Element, element : String):
-	Element action
-	Element params
-	Element param
-	Element second_param
-
-	action = read_attribute(model, element, "constraint")
-	params = create_node()
-	param = create_node()
-	dict_add(param, "name", "a")
-	dict_add(param, "value", model)
-	second_param = create_node()
-	dict_add(second_param, "name", "b")
-	dict_add(second_param, "value", element)
-	dict_add(param, "next_param", second_param)
-	dict_add(params, "params", param)
-	dict_add(params, "last_param", second_param)
-	return eval(action, params)

+ 1 - 0
bootstrap/constructors.alc

@@ -288,6 +288,7 @@ Action function construct_function():
 	counter = 0
 	func = create_node()
 	arg_names_decl = "abcdefghijklmnopqrstuvwxyz"
+	dict_add(func, "params", params)
 
 	while (counter < nrParams):
 		param = create_node()

+ 0 - 30
bootstrap/primitives.alc

@@ -104,36 +104,6 @@ Element function exec(first_instr : Element):
 
 	return n()
 
-Element function eval(funcdef : Element, params : Element):
-	// This does some even more ugly things, so don't touch this unless you know what you are doing!
-	Action ret_value
-	Action call
-	Action cons_value
-	Element n
-	Element result
-	log("Eval")
-
-	ret_value = create_value(!return)
-	call = create_value(!call)
-	cons_value = create_value(!constant)
-	n = create_node()
-
-	dict_add(n, "params", create_node())
-	dict_add(n, "body", ret_value)
-	dict_add(ret_value, "value", call)
-	dict_add(call, "func", cons_value)
-	dict_add(cons_value, "node", funcdef)
-
-	if (list_len(params) > 0):
-		dict_add(call, "params", params["params"])
-		dict_add(call, "last_param", params["last_param"])
-
-	log("Ready eval!")
-	result = n()
-	log("Got result: " + cast_e2s(result))
-
-	return result
-
 Boolean function string_startswith(a: String, b: String):
 	Integer i
 	i = 0

+ 21 - 17
hybrid_server/classes/mvkcontroller.xml

@@ -91,25 +91,29 @@
                         <parameter name="data"/>
                         <script>
                             # No JSON encoding necessary, as it is not complex
-                            if data["op"] == "set_input":
-                                if "element_type" in data:
-                                    if data["element_type"] == "V":
-                                        value = json.loads(data["value"])
+                            try:
+                                if data["op"] == "set_input":
+                                    if "element_type" in data:
+                                        if data["element_type"] == "V":
+                                            value = json.loads(data["value"])
+                                        else:
+                                            value = data["value"]
+                                        args = [data["element_type"], value]
+                                        self.input_queue[data["username"]].append((source, [args]))
                                     else:
-                                        value = data["value"]
-                                    args = [data["element_type"], value]
-                                    self.input_queue[data["username"]].append((source, [args]))
+                                        d = []
+                                        for t, v in json.loads(data["data"]):
+                                            if t == "V":
+                                                v = json.loads(v)
+                                            d.append([t, v])
+                                        self.input_queue[data["username"]].append((source, d))
+                                elif data["op"] == "get_output":
+                                    self.output_queue[data["username"]].append(source)
                                 else:
-                                    d = []
-                                    for t, v in json.loads(data["data"]):
-                                        if t == "V":
-                                            v = json.loads(v)
-                                        d.append([t, v])
-                                    self.input_queue[data["username"]].append((source, d))
-                            elif data["op"] == "get_output":
-                                self.output_queue[data["username"]].append(source)
-                            else:
-                                raise Exception("DROPPING unknown operation: " + str(data["op"]))
+                                    raise Exception("DROPPING unknown operation: " + str(data["op"]))
+                            except ValueError:
+                                print("Error when deserializing request: " + str(data))
+                                raise
                         </script>
                     </transition>
                 </state>

+ 11 - 3
integration/test_constructors_models.py

@@ -162,7 +162,7 @@ def add_constraints(model):
             '"model"',
             '"add_constraint"', model, '"Integer"',
                 '2', model*100, model*100+1,
-                    '"return"', 'true',
+                    '"if"',
                         '"call"',
                             '"access"', '"resolve"', '"is_physical_int"',
                             '1',
@@ -172,12 +172,20 @@ def add_constraints(model):
                                 '"call"',
                                     '"access"', '"resolve"', '"dict_read"',
                                     '2',
-                                    '"const"', model*100,
+                                    '"access"', '"resolve"', model*100,
                                     '"const"', '"model"',
                                     'false',
-                                '"const"', model*100+1,
+                                '"access"', '"resolve"', model*100+1,
                                 'false',
                             'false',
+                        '"return"',
+                            'true',
+                                '"const"', '"OK"',
+                        'true',
+                        '"return"',
+                            'true',
+                                '"const"', '"Integer instance is not an integer."',
+                        'false',
             '"exit"',
         ]
 

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

@@ -90,4 +90,3 @@ Boolean function has_value(a : Element)
 Element function dict_reverse(a : Element, b : Element)
 
 Element function exec(a : Element)
-Element function eval(a : Element, b : Element)

+ 3 - 0
kernel/modelverse_kernel/primitives.py

@@ -315,7 +315,10 @@ def dict_reverse(a, b, **remainder):
 def is_physical_int(a, **remainder):
     print("REQUEST PHYSICAL INT")
     t = yield [("RV", [a])]
+    print(a)
+    print(t)
     result = yield [("CNV", [isinstance(t, int) or isinstance(t, long)])]
+    print(type(t))
     raise PrimitiveFinished(result)
 
 def is_physical_string(a, **remainder):