Преглед на файлове

First port to ID/value tuples instead of just IDs

Yentl Van Tendeloo преди 7 години
родител
ревизия
6b9987af5d

+ 0 - 2
bootstrap/bootstrap.py

@@ -46,8 +46,6 @@ def bootstrap():
                     "cast_integer": ["Integer", "Element"],
                     "cast_value": ["String", "Element"],
                     "cast_id": ["String", "Element"],
-                    "list_insert": ["Element", "Element", "Integer", "Element"],
-                    "list_delete": ["Element", "Element", "Integer"],
                     "dict_add_fast": ["Element", "Element", "Element", "Element"],
                     "dict_delete": ["Element", "Element", "Element"],
                     "dict_delete_node": ["Element", "Element", "Element"],

+ 2 - 2
bootstrap/semi_primitives.alc

@@ -563,7 +563,7 @@ Element function list_insert(a : Element, b : Element, c : Integer):
 	prev = b
 
 	while (current < list_len(a)):
-		new_prev = list_get(a, current)
+		new_prev = list_read(a, current)
 		dict_delete(a, current)
 		dict_add_fast(a, current, prev)
 		prev = new_prev
@@ -574,7 +574,7 @@ Element function list_insert(a : Element, b : Element, c : Integer):
 Element function list_delete(a : Element, b : Integer):
 	Integer current
 
-	current = c
+	current = b
 	
 	while (current < (list_len(a) - 1)):
 		dict_delete(a, current)

+ 39 - 13
kernel/modelverse_kernel/main.py

@@ -97,6 +97,7 @@ class ModelverseKernel(object):
     def execute_jit_internal(self, task_root, inst, taskname, params):
         inst, = yield [("RD", [inst, "body"])]
         result, = yield [("CALL_ARGS", [self.execute_jit, [task_root, inst, taskname, params, False]])]
+        #print("Setting result of call to " + str(result))
         raise primitive_functions.PrimitiveFinished(result)
         
     def get_inst_phase_generator(self, inst_v, phase_v, task_root):
@@ -149,7 +150,13 @@ class ModelverseKernel(object):
             else:
                 false = ""
 
-            instruction = prev_cond + "  " * indent + "val_%s, = yield [('RV', [%s])]\n" % (instruction_cond, instruction_cond) + "  " * indent + "if (val_%s):\n" % instruction_cond + prev_true + instruction_true + false
+            instruction = prev_cond + \
+                            "  " * indent + "if 'value' not in %s:\n" % instruction_cond + \
+                            "  " * (indent + 1) + "%s['value'], = yield [('RV', [%s['id']])]\n" % (instruction_cond, instruction_cond) + \
+                            "  " * indent + "if (%s['value']):\n" % instruction_cond + \
+                                prev_true + \
+                                instruction_true + \
+                                false
 
         elif inst_type["value"] == "constant":
             node, = yield [("RD", [inst, "node"])]
@@ -162,7 +169,7 @@ class ModelverseKernel(object):
                     value = str(node_value)
                 instruction = "constant_" + str(ModelverseKernel.counter)
                 ModelverseKernel.counter += 1
-                prev = "  " * nested_indent + instruction + ", = yield [('CNV', [" + value + "])]\n"
+                prev = "  " * nested_indent + instruction + " = {'value': " + value + "}\n"
             else:
                 # Node is None, meaning that it was not about the value, but the node itself...
                 instruction = str(node)
@@ -196,7 +203,7 @@ class ModelverseKernel(object):
                    "  " * (nested_indent + 2) + "_, val_e = yield [('DE', [val_e]), ('RDE', [_root, 'input'])]\n" + \
                    "  " * (nested_indent + 2) + "_, nxt = yield [('DE', [val_e]), ('RD', [_inputs, 'next'])]\n" + \
                    "  " * (nested_indent + 2) + "yield [('CD', [_root, 'input', nxt])]\n" + \
-                   "  " * (nested_indent + 2) + "_result = val\n" + \
+                   "  " * (nested_indent + 2) + "_result = {'id': val}\n" + \
                    "  " * (nested_indent + 2) + "break\n" + \
                    "  " * (nested_indent + 1) + "else:\n" + \
                    "  " * (nested_indent + 2) + "yield None\n"
@@ -206,8 +213,10 @@ class ModelverseKernel(object):
             value, = yield [("RD", [inst, "value"])]
             (prev, inst), = yield [("CALL_ARGS", [self.print_instruction, (value, 0, indent)])]
             instruction = prev + \
+                          "  " * indent + "if 'value' not in %s:\n" % inst + \
+                          "  " * (indent + 1) + "%s['value'], = yield [('CNV', [%s['id']])]\n" % (inst, inst) + \
                           "  " * indent + "_outputs, _outputs_e = yield [('RD', [_root, 'last_output']), ('RDE', [_root, 'last_output'])]\n" + \
-                          "  " * indent + "_, _new = yield [('CD', [_outputs, 'value', %s]), ('CN', [])]\n" % inst+ \
+                          "  " * indent + "_, _new = yield [('CD', [_outputs, 'value', %s['id']]), ('CN', [])]\n" % inst+ \
                           "  " * indent + "yield [('CD', [_outputs, 'next', _new]), ('DE', [_outputs_e]), ('CD', [_root, 'last_output', _new])]\n"
 
         elif inst_type["value"] == "resolve":
@@ -217,7 +226,8 @@ class ModelverseKernel(object):
                 # Is a global
                 prev = \
                        "  " * nested_indent + "%s, = yield [('RD', [_globs, '%s'])]\n" % (str_value, str_value) + \
-                       "  " * nested_indent + "%s, = yield [('RD', [%s, 'value'])]\n" % (str_value, str_value)
+                       "  " * nested_indent + "%s, = yield [('RD', [%s, 'value'])]\n" % (str_value, str_value) + \
+                       "  " * nested_indent + "%s = {'id': %s}\n" % (str_value, str_value)
                 instruction = str_value
 
                 if self.jit.get_global_body_id(str_value) is None:
@@ -275,10 +285,11 @@ class ModelverseKernel(object):
 
             if func_name in intrinsics:
                 #TODO test and fix
-                actual_computation = value + " = " + intrinsics[func_name](*param_list)
+                #actual_computation = value + " = " + intrinsics[func_name](*param_list)
+                pass
             else:
                 param_list = "{" + ", ".join(["'%s': %s" % (k, v) for k, v in param_list.items()]) + "}"
-                actual_computation = "%s, = yield [('CALL_ARGS', [_mvk.execute_jit_internal, (_root, %s, _taskname, %s)])]\n" % (value, func_name, param_list)
+                actual_computation = "%s, = yield [('CALL_ARGS', [_mvk.execute_jit_internal, (_root, %s['id'], _taskname, %s)])]\n" % (value, func_name, param_list)
 
             if indent == 0:
                 # No indent, meaning that we use it inline
@@ -300,8 +311,9 @@ class ModelverseKernel(object):
                         yield [("CALL_ARGS", [self.print_instruction, (cond, 0, indent+1)]),
                                ("CALL_ARGS", [self.print_instruction, (body, indent+1)])]
             instruction = "  " * indent + "while 1:\n" + prev_cond + \
-                          "  " * (indent + 1) + "val_%s, = yield [('RV', [%s])]\n" % (instruction_cond, instruction_cond) + \
-                          "  " * (indent + 1) + "if not (val_%s):\n" % instruction_cond + \
+                          "  " * (indent + 1) + "if 'value' not in %s:\n" % instruction_cond + \
+                          "  " * (indent + 2) + "%s['value'], = yield [('RV', [%s['id']])]\n" % (instruction_cond, instruction_cond) + \
+                          "  " * (indent + 1) + "if not (%s['value']):\n" % instruction_cond + \
                           "  " * (indent + 2) + "break\n" + \
                           prev_body + instruction_body
 
@@ -336,11 +348,11 @@ class ModelverseKernel(object):
         else:
             func = "def " + suggested_name + "(**kwargs):\n" + printed
         
-        #print(func)
+        print(func)
 
         # To write out all generated functions
-        #with open('/tmp/junk/%s' % suggested_name, 'w') as f:
-        #    f.write(func)
+        with open('/tmp/junk/%s' % suggested_name, 'w') as f:
+            f.write(func)
 
         raise primitive_functions.PrimitiveFinished(func)
 
@@ -349,6 +361,7 @@ class ModelverseKernel(object):
         suggested_name = self.jit.get_global_name(inst)
         if suggested_name is None:
             suggested_name = "func_%s" % str(inst)
+        #print("Exec function " + str(suggested_name))
 
         # Have the JIT compile the function.
         if inst is None:
@@ -382,6 +395,12 @@ class ModelverseKernel(object):
         except:
             parameters = params
 
+        for p in parameters.keys():
+            if not isinstance(parameters[p], dict):
+                parameters[p] = {'id': parameters[p]}
+                #print("CONVERSION REQUIRED...")
+        #print("Calling with parameters:" + str(parameters))
+
         parameters["root"] = self.root
         parameters["task_root"] = task_root
         parameters["taskname"] = taskname
@@ -396,6 +415,13 @@ class ModelverseKernel(object):
         else:
             result, = results
 
+        #print("Got result: " + str(result))
+        if result is None:
+            result = {'id': None, 'value': None}
+
+        if "id" not in result:
+            result['id'], = yield [("CNV", [result['value']])]
+
         if store:
             # Clean up the current stack, as if a return happened
             old_frame, exception_return = yield [
@@ -414,7 +440,7 @@ class ModelverseKernel(object):
                 raise primitive_functions.InterpretedFunctionFinished(result)
             else:
                 lnk, =          yield [("RDE", [old_frame, "returnvalue"])]
-                _, _, _, _ =    yield [("CD", [old_frame, "returnvalue", result]),
+                _, _, _, _ =    yield [("CD", [old_frame, "returnvalue", result['id']]),
                                        ("CD", [task_root, "frame", old_frame]),
                                        ("DE", [lnk]),
                                        ("DN", [task_frame]),

+ 0 - 413
kernel/modelverse_kernel/new_primitives.py

@@ -1,413 +0,0 @@
-import time as python_time
-import json
-import sys
-
-class PrimitiveFinished(Exception):
-    """Exception to indicate the result value of a primitive, as a return cannot be used."""
-    def __init__(self, value):
-        Exception.__init__(self)
-        self.result = value
-
-class InterpretedFunctionFinished(Exception):
-    """Exception to indicate the result value of an interpreted function, as a return
-       cannot be used."""
-    def __init__(self, value):
-        Exception.__init__(self)
-        self.result = value
-
-class SleepKernel(Exception):
-    """Exception to indicate the kernel to sleep for some time."""
-    def __init__(self, timeout, interruptable):
-        Exception.__init__(self)
-        self.timeout = timeout
-        self.interruptable = interruptable
-
-# Functions annotated with __exception_return use the JIT's calling convention instead of
-# the kernel's: returns are handled by throwing a PrimitiveFinished exception; the caller's
-# returnvalue is not modified.
-#
-# ### Rationale for __exception_return
-#
-# __exception_return is a useful mechanism because it allows us to have a __call_function
-# implementation that has O(1) state read overhead. A previous implementation of
-# __call_function checked if the caller's frame had been popped whenever
-# ModelverseKernel.execute_yield threw a StopIteration exception. However, that incurs O(n) overhead
-# _per call,_ where n is the number of StopIteration exceptions that are thrown during the call.
-# O(n) is pretty bad, but this actually becomes O(n * m) when m calls to __call_function are
-# nested. And that's just not acceptable.
-# __exception_return requires kernel support, but I think the complexity gains are well worth it;
-# I reckon JIT-to-interpreter switches aren't going to get a whole lot cheaper than this.
-EXCEPTION_RETURN_KEY = "__exception_return"
-"""A dictionary key for functions which request that the kernel throw a InterpretedFunctionFinished
-   exception with the return value instead of injecting the return value in the caller's frame."""
-
-def integer_subtraction(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] - b['value']})
-
-def integer_addition(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] + b['value']})
-
-def integer_multiplication(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] * b['value']})
-
-def integer_division(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': int(a['value']) // b['value']})
-
-def integer_lt(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] < b['value']})
-
-def bool_and(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] and b['value']})
-
-def bool_or(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] or b['value']})
-
-def bool_not(a, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    raise PrimitiveFinished({'value': not a['value']})
-
-def float_subtraction(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] - b['value']})
-
-def float_addition(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] + b['value']})
-
-def float_multiplication(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] * b['value']})
-
-def float_division(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': float(a['value']) / float(b['value'])})
-
-def float_lt(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] < b['value']})
-
-def string_join(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': str(a['value']) + str(b['value'])})
-
-def string_split(a, b, **remainder):
-    # TODO make non-primitive, though compiled
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    result = a['value'].split(b['value'])
-    elems = yield [("CN", [])] + [("CNV", [v]) for v in result]
-    new_val = elems[0]
-    yield [("CD", [new_val, i, v]) for i, v in enumerate(elems[1:])]
-    raise PrimitiveFinished({'id': new_val})
-
-def string_get(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'][b['value']]})
-
-def string_len(a, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    raise PrimitiveFinished({'value': len(a['value'])})
-
-def value_eq(a, b, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if 'value' not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    raise PrimitiveFinished({'value': a['value'] == b['value']})
-
-def element_eq(a, b, **remainder):
-    if "id" not in a:
-        print("MATERIALIZING A element_eq")
-        if "value" in a:
-            a['id'], = yield [("CNV", [a['value']])]
-    if "id" not in b:
-        print("MATERIALIZING B element_eq")
-        if "value" in b:
-            b['id'], = yield [("CNV", [b['value']])]
-    raise PrimitiveFinished({'value': a['id'] == b['id']})
-
-def cast_string(a, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if isinstance(a_value, dict):
-        raise PrimitiveFinished({'value': str(a['value']['value'])})
-    else:
-        raise PrimitiveFinished({'value': str(a['value'])})
-
-def cast_float(a, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    raise PrimitiveFinished({'value': float(a['value'])})
-
-def cast_boolean(a, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    raise PrimitiveFinished({'value': bool(a['value'])})
-
-def cast_integer(a, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    raise PrimitiveFinished({'value': int(a['value'])})
-
-def cast_value(a, **remainder):
-    if 'value' not in a:
-        a['value'], = yield [("RV", [a['id']])]
-    if isinstance(a_value, dict):
-        raise PrimitiveFinished({'value': str(a['value']['value'])})
-    else:
-        raise PrimitiveFinished({'value': json.dumps(a['value'])})
-
-def cast_id(a, **remainder):
-    if "id" not in a:
-        print("MATERIALIZING A cast_id")
-        if "value" in a:
-            a['id'], = yield [("CNV", [a['value']])]
-        else:
-            a['id'], = yield [("CN", [])]
-    raise PrimitiveFinished({'value': str(a['id'])})
-
-def dict_add_fast(a, b, c, **remainder):
-    # TODO deprecate, as dict_add is now also efficient
-    if "value" not in b:
-        b['value'], = yield [("RV", [b['id']])]
-    if "id" not in c:
-        print("MATERIALIZING C dict_add_fast")
-        c['id'], = yield [("CNV", [c['value']])]
-
-    yield [("CD", [a['id'], b['value'], c['id']])]
-    raise PrimitiveFinished(a)
-
-def dict_delete(a, b, **remainder):
-    b_value, = yield [("RV", [b])]
-    edge, = yield [("RDE", [a, b_value])]
-    if edge is None:
-        print("Failed dict_delete for value '%s'!" % b_value)
-        keys, = yield [("RDK", [a])]
-        keys = yield [("RV", [i]) for i in keys]
-        print("Keys: " + str(keys))
-        raise Exception()
-    yield [("DE", [edge])]
-    raise PrimitiveFinished(a)
-
-def dict_delete_node(a, b, **remainder):
-    edge, = yield [("RDNE", [a, b])]
-    if edge is None:
-        print("Failed dict_delete_node!")
-    yield [("DE", [edge])]
-    raise PrimitiveFinished(a)
-
-def dict_read(a, b, **remainder):
-    b_value, = yield [("RV", [b])]
-    result, = yield [("RD", [a, b_value])]
-    raise PrimitiveFinished(result)
-
-def dict_read_edge(a, b, **remainder):
-    b_value, = yield [("RV", [b])]
-    result, = yield [("RDE", [a, b_value])]
-    raise PrimitiveFinished(result)
-
-def dict_read_node(a, b, **remainder):
-    result, = yield [("RDN", [a, b])]
-    raise PrimitiveFinished(result)
-
-def dict_in(a, b, **remainder):
-    b_value, = yield [("RV", [b])]
-    value, = yield [("RD", [a, b_value])]
-    is_in = value is not None
-    result, = yield [("CNV", [is_in])]
-    raise PrimitiveFinished(result)
-
-def dict_in_node(a, b, **remainder):
-    value, = yield [("RDN", [a, b])]
-    result, = yield [("CNV", [value is not None])]
-    raise PrimitiveFinished(result)
-
-def dict_keys(a, **remainder):
-    keys, result = yield [("RDK", [a]), ("CN", [])]
-    edges = yield [("CE", [result, result]) for _ in keys]
-    _ = yield [("CE", [edge, key]) for edge, key in zip(edges, keys)]
-    raise PrimitiveFinished(result)
-
-def is_physical_int(a, **remainder):
-    t, = yield [("RV", [a])]
-    try:
-        result, = yield [("CNV", [isinstance(t, int) or isinstance(t, long)])]
-    except NameError:
-        result, = yield [("CNV", [isinstance(t, int)])]
-
-    raise PrimitiveFinished(result)
-
-def is_physical_string(a, **remainder):
-    t, = yield [("RV", [a])]
-    try:
-        result, = yield [("CNV", [isinstance(t, str) or isinstance(t, unicode)])]
-    except NameError:
-        result, = yield [("CNV", [isinstance(t, str)])]
-
-    raise PrimitiveFinished(result)
-
-def is_physical_float(a, **remainder):
-    t, = yield [("RV", [a])]
-    result, = yield [("CNV", [isinstance(t, float)])]
-    raise PrimitiveFinished(result)
-
-def is_physical_boolean(a, **remainder):
-    t, = yield [("RV", [a])]
-    result, = yield [("CNV", [isinstance(t, bool)])]
-    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"]])]
-    raise PrimitiveFinished(result)
-
-def is_physical_none(a, **remainder):
-    t, = yield [("RV", [a])]
-    result, = yield [("CNV", [isinstance(t, dict) and t["value"] == "none"])]
-    raise PrimitiveFinished(result)
-
-def create_node(**remainder):
-    result, = yield [("CN", [])]
-    raise PrimitiveFinished(result)
-
-def create_edge(a, b, **remainder):
-    result, = yield [("CE", [a, b])]
-    raise PrimitiveFinished(result)
-
-def create_value(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    result, = yield [("CNV", [a_value])]
-    raise PrimitiveFinished(result)
-
-def read_nr_out(a, **remainder):
-    outgoing, = yield [("RO", [a])]
-    result, = yield [("CNV", [len(outgoing)])]
-    raise PrimitiveFinished(result)
-
-def read_out(a, b, root, **remainder):
-    outgoing, b_value = yield [("RO", [a]), ("RV", [b])]
-    raise PrimitiveFinished(sorted(outgoing)[b_value] if len(outgoing) > b_value else root)
-
-def read_nr_in(a, **remainder):
-    incoming, = yield [("RI", [a])]
-    result, = yield [("CNV", [len(incoming)])]
-    raise PrimitiveFinished(result)
-
-def read_in(a, b, root, **remainder):
-    incoming, b_value = yield [("RI", [a]), ("RV", [b])]
-    raise PrimitiveFinished(sorted(incoming)[b_value] if len(incoming) > b_value else root)
-
-def read_edge_src(a, **remainder):
-    result, = yield [("RE", [a])]
-    raise PrimitiveFinished(result[0])
-
-def read_edge_dst(a, **remainder):
-    result, = yield [("RE", [a])]
-    raise PrimitiveFinished(result[1])
-
-def delete_element(a, **remainder):
-    edge, = yield [("RE", [a])]
-    if edge[0] is None:
-        # Not an edge:
-        yield [("DN", [a])]
-        result, = yield [("CNV", [False])]
-        raise PrimitiveFinished(result)
-    else:
-        yield [("DE", [a])]
-        result, = yield [("CNV", [True])]
-        raise PrimitiveFinished(result)
-
-def read_root(root, **remainder):
-    raise PrimitiveFinished(root)
-
-def is_edge(a, **remainder):
-    edge, = yield [("RE", [a])]
-    result, = yield [("CNV", [edge[0] is not None])]
-    raise PrimitiveFinished(result)
-
-def log(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    print("== LOG == " + str(a_value))
-    raise PrimitiveFinished(a)
-
-def read_taskroot(task_root, **remainder):
-    raise PrimitiveFinished(task_root)
-
-def time(**remainder):
-    a, = yield [("CNV", [python_time.time()])]
-    raise PrimitiveFinished(a)
-
-def hash(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    import hashlib
-    try:
-        b_value = hashlib.sha512(a_value).hexdigest()
-    except TypeError:
-        b_value = hashlib.sha512(a_value.encode()).hexdigest()
-    b, = yield [("CNV", [b_value])]
-    raise PrimitiveFinished(b)
-
-def __sleep(a, b, **remainder):
-    timeout, interruptable = yield [("RV", [a]), ("RV", [b])]
-    yield [("SLEEP", [timeout, interruptable])]
-    raise PrimitiveFinished(a)
-
-def is_error(a, **remainder):
-    if a is None:
-        result, = yield [("CNV", [True])]
-    else:
-        result, = yield [("CNV", [False])]
-    raise PrimitiveFinished(result)

+ 242 - 205
kernel/modelverse_kernel/primitives.py

@@ -42,187 +42,197 @@ EXCEPTION_RETURN_KEY = "__exception_return"
    exception with the return value instead of injecting the return value in the caller's frame."""
 
 def integer_subtraction(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value - b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] - b['value']})
 
 def integer_addition(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value + b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] + b['value']})
 
 def integer_multiplication(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value * b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] * b['value']})
 
 def integer_division(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [int(a_value) // b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': int(a['value']) // b['value']})
 
 def integer_lt(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value < b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] < b['value']})
 
 def bool_and(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value and b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] and b['value']})
 
 def bool_or(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value or b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] or b['value']})
 
 def bool_not(a, **remainder):
-    a_value, =          yield [("RV", [a])]
-    result, = yield [("CNV", [not a_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': not a['value']})
 
 def float_subtraction(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value - b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] - b['value']})
 
 def float_addition(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value + b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] + b['value']})
 
 def float_multiplication(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value * b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] * b['value']})
 
 def float_division(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [float(a_value) / float(b_value)])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': float(a['value']) / float(b['value'])})
 
 def float_lt(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value < b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] < b['value']})
 
 def string_join(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [str(a_value) + str(b_value)])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': str(a['value']) + str(b['value'])})
 
 def string_split(a, b, **remainder):
     # TODO make non-primitive, though compiled
-    a_value, b_value = yield [("RV", [a]), ("RV", [b])]
-    result = a_value.split(b_value)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    result = a['value'].split(b['value'])
     elems = yield [("CN", [])] + [("CNV", [v]) for v in result]
     new_val = elems[0]
     yield [("CD", [new_val, i, v]) for i, v in enumerate(elems[1:])]
-    raise PrimitiveFinished(new_val)
+    raise PrimitiveFinished({'id': new_val})
 
 def string_get(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value[b_value]])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'][b['value']]})
 
 def string_len(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    result, = yield [("CNV", [len(a_value)])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': len(a['value'])})
 
 def value_eq(a, b, **remainder):
-    a_value, b_value =  yield [("RV", [a]), ("RV", [b])]
-    result, = yield [("CNV", [a_value == b_value])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    if 'value' not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    raise PrimitiveFinished({'value': a['value'] == b['value']})
 
 def element_eq(a, b, **remainder):
-    result, = yield [("CNV", [a == b])]
-    raise PrimitiveFinished(result)
+    if "id" not in a:
+        print("MATERIALIZING A element_eq")
+        a['id'], = yield [("CNV", [a['value']])]
+    if "id" not in b:
+        print("MATERIALIZING B element_eq")
+        b['id'], = yield [("CNV", [b['value']])]
+    raise PrimitiveFinished({'value': a['id'] == b['id']})
 
 def cast_string(a, **remainder):
-    a_value, = yield [("RV", [a])]
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
     if isinstance(a_value, dict):
-        result, = yield [("CNV", [str(a_value["value"])])]
+        raise PrimitiveFinished({'value': str(a['value']['value'])})
     else:
-        result, = yield [("CNV", [str(a_value)])]
-    raise PrimitiveFinished(result)
+        raise PrimitiveFinished({'value': str(a['value'])})
 
 def cast_float(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    result, = yield [("CNV", [float(a_value)])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': float(a['value'])})
 
 def cast_boolean(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    result, = yield [("CNV", [bool(a_value)])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': bool(a['value'])})
 
 def cast_integer(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    result, = yield [("CNV", [int(a_value)])]
-    raise PrimitiveFinished(result)
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': int(a['value'])})
 
 def cast_value(a, **remainder):
-    a_value, = yield [("RV", [a])]
+    if 'value' not in a:
+        a['value'], = yield [("RV", [a['id']])]
     if isinstance(a_value, dict):
-        # Action or type
-        value = a_value["value"]
+        raise PrimitiveFinished({'value': str(a['value']['value'])})
     else:
-        value = json.dumps(a_value)
-    result, = yield [("CNV", [value])]
-    raise PrimitiveFinished(result)
+        raise PrimitiveFinished({'value': json.dumps(a['value'])})
 
 def cast_id(a, **remainder):
-    result, = yield [("CNV", ["%s" % (a)])]
-    raise PrimitiveFinished(result)
-
-def list_insert(a, b, c, **remainder):
-    # TODO make non-primitive, though compiled
-    a_outgoing, c_value = yield [("RO", [a]), ("RV", [c])]
-    links = yield [("RD", [a, i]) for i in range(c_value, len(a_outgoing))] + \
-                  [("RDE", [a, i]) for i in range(c_value, len(a_outgoing))]
-
-    if sys.version_info[0] < 3:
-        values = links[:len(links)/2]
-        edges = links[len(links)/2:]
-    else:
-        values = links[:len(links) // 2]
-        edges = links[len(links) // 2:]
-
-    yield [("CD", [a, c_value, b])] + \
-          [("CD", [a, c_value + 1 + index, value]) for index, value in enumerate(values)] + \
-          [("DE", [i]) for i in edges]
-    raise PrimitiveFinished(a)
-
-def list_delete(a, b, **remainder):
-    # TODO make non-primitive, though compiled
-    a_outgoing, b_value = yield [("RO", [a]), ("RV", [b])]
-    links = yield [("RD", [a, i]) for i in range(b_value, len(a_outgoing))] + \
-                  [("RDE", [a, i]) for i in range(b_value, len(a_outgoing))]
-
-    if sys.version_info[0] < 3:
-        values = links[:len(links) / 2]
-        edges = links[len(links) / 2:]
-    else:
-        values = links[:len(links) // 2]
-        edges = links[len(links) // 2:]
-
-    yield [("CD", [a, b_value + index, value]) for index, value in enumerate(values[1:])] + \
-          [("DE", [i]) for i in edges]
-    raise PrimitiveFinished(a)
+    if "id" not in a:
+        print("MATERIALIZING A cast_id")
+        a['id'], = yield [("CNV", [a['value']])]
+    raise PrimitiveFinished({'value': str(a['id'])})
 
 def dict_add_fast(a, b, c, **remainder):
     # TODO deprecate, as dict_add is now also efficient
-    v, = yield [("RV", [b])]
-    yield [("CD", [a, v, c])]
+    if "value" not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    if "id" not in c:
+        print("MATERIALIZING C dict_add_fast")
+        c['id'], = yield [("CNV", [c['value']])]
+
+    yield [("CD", [a['id'], b['value'], c['id']])]
     raise PrimitiveFinished(a)
 
 def dict_delete(a, b, **remainder):
-    b_value, = yield [("RV", [b])]
-    edge, = yield [("RDE", [a, b_value])]
+    if "value" not in b:
+        b['value'], = yield [("RV", [b['id']])]
+
+    edge, = yield [("RDE", [a['id'], b['value']])]
     if edge is None:
-        print("Failed dict_delete for value '%s'!" % b_value)
-        keys, = yield [("RDK", [a])]
+        print("Failed dict_delete for value '%s'!" % b['value'])
+        keys, = yield [("RDK", [a['id']])]
         keys = yield [("RV", [i]) for i in keys]
         print("Keys: " + str(keys))
         raise Exception()
@@ -230,171 +240,198 @@ def dict_delete(a, b, **remainder):
     raise PrimitiveFinished(a)
 
 def dict_delete_node(a, b, **remainder):
-    edge, = yield [("RDNE", [a, b])]
+    edge, = yield [("RDNE", [a['id'], b['id']])]
     if edge is None:
         print("Failed dict_delete_node!")
     yield [("DE", [edge])]
     raise PrimitiveFinished(a)
 
 def dict_read(a, b, **remainder):
-    b_value, = yield [("RV", [b])]
-    result, = yield [("RD", [a, b_value])]
-    raise PrimitiveFinished(result)
+    if "value" not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    result, = yield [("RD", [a['id'], b['value']])]
+    raise PrimitiveFinished({'id': result})
 
 def dict_read_edge(a, b, **remainder):
-    b_value, = yield [("RV", [b])]
-    result, = yield [("RDE", [a, b_value])]
-    raise PrimitiveFinished(result)
+    if "value" not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    result, = yield [("RDE", [a['id'], b['value']])]
+    raise PrimitiveFinished({'id': result})
 
 def dict_read_node(a, b, **remainder):
-    result, = yield [("RDN", [a, b])]
-    raise PrimitiveFinished(result)
+    result, = yield [("RDN", [a['id'], b['id']])]
+    raise PrimitiveFinished({'id': result})
 
 def dict_in(a, b, **remainder):
-    b_value, = yield [("RV", [b])]
-    value, = yield [("RD", [a, b_value])]
-    is_in = value is not None
-    result, = yield [("CNV", [is_in])]
-    raise PrimitiveFinished(result)
+    if "value" not in b:
+        b['value'], = yield [("RV", [b['id']])]
+    value, = yield [("RD", [a['id'], b['value']])]
+    raise PrimitiveFinished({'value': value is not None})
 
 def dict_in_node(a, b, **remainder):
-    value, = yield [("RDN", [a, b])]
-    result, = yield [("CNV", [value is not None])]
-    raise PrimitiveFinished(result)
+    if "id" not in b:
+        # Not even allocated the node, so it is certain not to be in the dictionary
+        raise PrimitiveFinished({'value': False})
+    value, = yield [("RDN", [a['id'], b['id']])]
+    raise PrimitiveFinished({'value': value is not None})
 
 def dict_keys(a, **remainder):
-    keys, result = yield [("RDK", [a]), ("CN", [])]
+    keys, result = yield [("RDK", [a['id']]), ("CN", [])]
     edges = yield [("CE", [result, result]) for _ in keys]
     _ = yield [("CE", [edge, key]) for edge, key in zip(edges, keys)]
-    raise PrimitiveFinished(result)
+    raise PrimitiveFinished({'id': result})
 
 def is_physical_int(a, **remainder):
-    t, = yield [("RV", [a])]
+    if "value" not in a:
+        a['value'], = yield [("RV", [a['id']])]
     try:
-        result, = yield [("CNV", [isinstance(t, int) or isinstance(t, long)])]
+        raise PrimitiveFinished({'value': isinstance(a['value'], int) or isinstance(a['value'], long)})
     except NameError:
-        result, = yield [("CNV", [isinstance(t, int)])]
-
-    raise PrimitiveFinished(result)
+        raise PrimitiveFinished({'value': isinstance(a['value'], int)})
 
 def is_physical_string(a, **remainder):
-    t, = yield [("RV", [a])]
+    if "value" not in a:
+        a['value'], = yield [("RV", [a['id']])]
     try:
-        result, = yield [("CNV", [isinstance(t, str) or isinstance(t, unicode)])]
+        raise PrimitiveFinished({'value': isinstance(a['value'], str) or isinstance(a['value'], unicode)})
     except NameError:
-        result, = yield [("CNV", [isinstance(t, str)])]
-
-    raise PrimitiveFinished(result)
+        raise PrimitiveFinished({'value': isinstance(a['value'], str)})
 
 def is_physical_float(a, **remainder):
-    t, = yield [("RV", [a])]
-    result, = yield [("CNV", [isinstance(t, float)])]
-    raise PrimitiveFinished(result)
+    if "value" not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': isinstance(a['value'], float)})
 
 def is_physical_boolean(a, **remainder):
-    t, = yield [("RV", [a])]
-    result, = yield [("CNV", [isinstance(t, bool)])]
-    raise PrimitiveFinished(result)
+    if "value" not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': isinstance(a['value'], bool)})
 
 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"]])]
-    raise PrimitiveFinished(result)
+    if "value" not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': isinstance(a['value'], dict) and a['value']["value"] in ["if", "while", "assign", "call", "break", "continue", "return", "resolve", "access", "constant", "global", "declare"]})
 
 def is_physical_none(a, **remainder):
-    t, = yield [("RV", [a])]
-    result, = yield [("CNV", [isinstance(t, dict) and t["value"] == "none"])]
-    raise PrimitiveFinished(result)
+    if "value" not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    raise PrimitiveFinished({'value': isinstance(a['value'], dict) and a['value']["value"] == "none"})
 
 def create_node(**remainder):
     result, = yield [("CN", [])]
-    raise PrimitiveFinished(result)
+    raise PrimitiveFinished({'id': result})
 
 def create_edge(a, b, **remainder):
-    result, = yield [("CE", [a, b])]
-    raise PrimitiveFinished(result)
+    if "id" not in a:
+        print("MATERIALIZING A create_edge")
+        a['id'], = yield [("CNV", [a['value']])]
+    if "id" not in b:
+        print("MATERIALIZING B create_edge")
+        b['id'], = yield [("CNV", [b['value']])]
+    result, = yield [("CE", [a['id'], b['id']])]
+    raise PrimitiveFinished({'id': result})
 
 def create_value(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    result, = yield [("CNV", [a_value])]
-    raise PrimitiveFinished(result)
+    if "value" not in a:
+        a['value'], = yield [("RV", [a])]
+    raise PrimitiveFinished({'value': a['value']})
 
 def read_nr_out(a, **remainder):
-    outgoing, = yield [("RO", [a])]
-    result, = yield [("CNV", [len(outgoing)])]
-    raise PrimitiveFinished(result)
+    if "id" not in a:
+        a['id'], = yield [("CNV", [a['value']])]
+    outgoing, = yield [("RO", [a['id']])]
+    raise PrimitiveFinished({'value': len(outgoing)})
 
 def read_out(a, b, root, **remainder):
-    outgoing, b_value = yield [("RO", [a]), ("RV", [b])]
-    raise PrimitiveFinished(sorted(outgoing)[b_value] if len(outgoing) > b_value else root)
+    if "id" not in a:
+        a['id'], = yield [("CNV", [a['value']])]
+    if "value" not in b:
+        b['value'], = yield [("RV", [b['id']])]
+
+    outgoing, = yield [("RO", [a['id']])]
+    raise PrimitiveFinished({'id': sorted(outgoing)[b['value']] if len(outgoing) > b['value'] else root})
 
 def read_nr_in(a, **remainder):
-    incoming, = yield [("RI", [a])]
-    result, = yield [("CNV", [len(incoming)])]
-    raise PrimitiveFinished(result)
+    if "id" not in a:
+        a['id'], = yield [("CNV", [a['value']])]
+    incoming, = yield [("RI", [a['id']])]
+    raise PrimitiveFinished({'value': len(incoming)})
 
 def read_in(a, b, root, **remainder):
-    incoming, b_value = yield [("RI", [a]), ("RV", [b])]
-    raise PrimitiveFinished(sorted(incoming)[b_value] if len(incoming) > b_value else root)
+    if "id" not in a:
+        a['id'], = yield [("CNV", [a['value']])]
+    if "value" not in b:
+        b['value'], = yield [("RV", [b['id']])]
+
+    incoming, = yield [("RI", [a['id']])]
+    raise PrimitiveFinished({'id': sorted(incoming)[b['value']] if len(incoming) > b['value'] else root})
 
 def read_edge_src(a, **remainder):
-    result, = yield [("RE", [a])]
-    raise PrimitiveFinished(result[0])
+    result, = yield [("RE", [a['id']])]
+    raise PrimitiveFinished({'id': result[0]})
 
 def read_edge_dst(a, **remainder):
-    result, = yield [("RE", [a])]
-    raise PrimitiveFinished(result[1])
+    result, = yield [("RE", [a['id']])]
+    raise PrimitiveFinished({'id': result[1]})
 
 def delete_element(a, **remainder):
-    edge, = yield [("RE", [a])]
+    if "id" not in a:
+        raise PrimitiveFinished({'value': False})
+
+    edge, = yield [("RE", [a['id']])]
     if edge[0] is None:
         # Not an edge:
-        yield [("DN", [a])]
-        result, = yield [("CNV", [False])]
-        raise PrimitiveFinished(result)
+        yield [("DN", [a['id']])]
+        raise PrimitiveFinished({'value': False})
     else:
-        yield [("DE", [a])]
-        result, = yield [("CNV", [True])]
-        raise PrimitiveFinished(result)
+        yield [("DE", [a['id']])]
+        raise PrimitiveFinished({'value': True})
 
 def read_root(root, **remainder):
-    raise PrimitiveFinished(root)
+    raise PrimitiveFinished({'id': root})
 
 def is_edge(a, **remainder):
-    edge, = yield [("RE", [a])]
-    result, = yield [("CNV", [edge[0] is not None])]
-    raise PrimitiveFinished(result)
+    if "id" not in a:
+        raise PrimitiveFinished({'value': False})
+
+    edge, = yield [("RE", [a['id']])]
+    raise PrimitiveFinished({'value': edge[0] is not None})
 
 def log(a, **remainder):
-    a_value, = yield [("RV", [a])]
-    print("== LOG == " + str(a_value))
+    if "value" not in a:
+        a['value'], = yield [("RV", [a['id']])]
+    print("== LOG == " + str(a['value']))
     raise PrimitiveFinished(a)
 
 def read_taskroot(task_root, **remainder):
-    raise PrimitiveFinished(task_root)
+    raise PrimitiveFinished({'id': task_root})
 
 def time(**remainder):
-    a, = yield [("CNV", [python_time.time()])]
-    raise PrimitiveFinished(a)
+    raise PrimitiveFinished({'value': python_time.time()})
 
 def hash(a, **remainder):
-    a_value, = yield [("RV", [a])]
+    if "value" not in a:
+        a['value'], = yield [("RV", [a['id']])]
     import hashlib
+
     try:
-        b_value = hashlib.sha512(a_value).hexdigest()
+        value = hashlib.sha512(a_value).hexdigest()
     except TypeError:
-        b_value = hashlib.sha512(a_value.encode()).hexdigest()
-    b, = yield [("CNV", [b_value])]
-    raise PrimitiveFinished(b)
+        value = hashlib.sha512(a_value.encode()).hexdigest()
+    raise PrimitiveFinished({'value': value})
 
 def __sleep(a, b, **remainder):
-    timeout, interruptable = yield [("RV", [a]), ("RV", [b])]
+    if "value" not in a:
+        a['value'], = yield [("RV", [a])]
+    if "value" not in b:
+        b['value'], = yield [("RV", [b])]
+    timeout = a['value']
+    interruptable = b['value']
     yield [("SLEEP", [timeout, interruptable])]
     raise PrimitiveFinished(a)
 
 def is_error(a, **remainder):
-    if a is None:
-        result, = yield [("CNV", [True])]
+    if a['id'] is None:
+        raise PrimitiveFinished({'value': True})
     else:
-        result, = yield [("CNV", [False])]
-    raise PrimitiveFinished(result)
+        raise PrimitiveFinished({'value': False})

+ 1 - 1
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)
 
-Date:   Wed Apr 25 09:27:00 2018
+Date:   Wed Apr 25 14:33:14 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server