Browse Source

Write set_len as a manually compiled function

Yentl Van Tendeloo 7 years ago
parent
commit
5c6cde5ddc

+ 7 - 0
kernel/modelverse_kernel/compiled.py

@@ -349,3 +349,10 @@ def list_delete(a, b, **remainder):
     yield [("CD", [a['id'], b['value'] + index, value]) for index, value in enumerate(values[1:])] + \
     yield [("CD", [a['id'], b['value'] + index, value]) for index, value in enumerate(values[1:])] + \
           [("DE", [i]) for i in edges]
           [("DE", [i]) for i in edges]
     yield [("RETURN", [a])]
     yield [("RETURN", [a])]
+
+def set_len(a, **remainder):
+    if "id" not in a:
+        yield [("RETURN", [{'value': 0}])]
+    else:
+        outgoing, = yield [("RO", [a['id']])]
+        yield [("RETURN", [{'value': len(outgoing)}])]

+ 1 - 2
kernel/modelverse_kernel/main.py

@@ -319,8 +319,7 @@ class ModelverseKernel(object):
             param, = yield [("RD", [inst, "params"])]
             param, = yield [("RD", [inst, "params"])]
             computation = ""
             computation = ""
             while param:
             while param:
-                value, = yield [("RD", [param, "value"])]
-                name, = yield [("RD", [param, "name"])]
+                value, name = yield [("RD", [param, "value"]), ("RD", [param, "name"])]
                 name, = yield [("RV", [name])]
                 name, = yield [("RV", [name])]
                 (prev_res, instruction_res), = yield [("CALL_ARGS", [self.print_instruction, (value, 0, nested_indent)])]
                 (prev_res, instruction_res), = yield [("CALL_ARGS", [self.print_instruction, (value, 0, nested_indent)])]
                 param, = yield [("RD", [param, "next_param"])]
                 param, = yield [("RD", [param, "next_param"])]

+ 8 - 6
kernel/modelverse_kernel/primitives.py

@@ -331,9 +331,10 @@ def create_value(a, **remainder):
 
 
 def read_nr_out(a, **remainder):
 def read_nr_out(a, **remainder):
     if "id" not in a:
     if "id" not in a:
-        a['id'], = yield [("CNV", [a['value']])]
-    outgoing, = yield [("RO", [a['id']])]
-    yield [("RETURN", [{'value': len(outgoing)}])]
+        yield [("RETURN", [{'value': 0}])]
+    else:
+        outgoing, = yield [("RO", [a['id']])]
+        yield [("RETURN", [{'value': len(outgoing)}])]
 
 
 def read_out(a, b, root, **remainder):
 def read_out(a, b, root, **remainder):
     if "id" not in a:
     if "id" not in a:
@@ -346,9 +347,10 @@ def read_out(a, b, root, **remainder):
 
 
 def read_nr_in(a, **remainder):
 def read_nr_in(a, **remainder):
     if "id" not in a:
     if "id" not in a:
-        a['id'], = yield [("CNV", [a['value']])]
-    incoming, = yield [("RI", [a['id']])]
-    yield [("RETURN", [{'value': len(incoming)}])]
+        yield [("RETURN", [{'value': 0}])]
+    else:
+        incoming, = yield [("RI", [a['id']])]
+        yield [("RETURN", [{'value': len(incoming)}])]
 
 
 def read_in(a, b, root, **remainder):
 def read_in(a, b, root, **remainder):
     if "id" not in a:
     if "id" not in a:

+ 1 - 2
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Wed May 23 11:52:01 2018
+Date:   Wed May 23 14:43:46 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server
@@ -2599,7 +2599,6 @@ class Modelverse(RuntimeClassBase):
     
     
     def _initialized_behaviour_operations_model_overwrite_search_0_exec(self, parameters):
     def _initialized_behaviour_operations_model_overwrite_search_0_exec(self, parameters):
         self.registered_metamodel[self.parameters[0]] = set(self.split_response(self.responses.pop(0))).pop()
         self.registered_metamodel[self.parameters[0]] = set(self.split_response(self.responses.pop(0))).pop()
-        #print("Registering " + str(self.parameters[0]))
     
     
     def _initialized_behaviour_operations_model_overwrite_search_0_guard(self, parameters):
     def _initialized_behaviour_operations_model_overwrite_search_0_guard(self, parameters):
         return self.expect_response_partial('Success: ')
         return self.expect_response_partial('Success: ')