Browse Source

Auto-resolve and assign globals upon use

Yentl Van Tendeloo 7 years ago
parent
commit
1915ded426
2 changed files with 18 additions and 9 deletions
  1. 17 4
      kernel/modelverse_kernel/main.py
  2. 1 5
      wrappers/modelverse_SCCD.py

+ 17 - 4
kernel/modelverse_kernel/main.py

@@ -247,8 +247,13 @@ class ModelverseKernel(object):
             value, = yield [("RD", [inst, "var"])]
             str_value, = yield [("RV", [value])]
             if str_value:
+                # Is a global
+                prev = "  " * nested_indent + "_globs, = yield [('RD', [kwargs['root'], '__globals'])]\n" + \
+                       "  " * nested_indent + "%s, = yield [('RD', [_globs, '%s'])]\n" % (str_value, str_value)
                 instruction = str_value
+                print("Resolving global: " + str(str_value))
             else:
+                # Is a local
                 instruction = "var_%s" % value
 
         elif inst_type["value"] == "assign":
@@ -259,9 +264,17 @@ class ModelverseKernel(object):
                                ("CALL_ARGS", [self.print_instruction, (val, 0, indent)])]
             instruction = prev_val + "  " * indent + instruction_var + " = " + instruction_val + "\n"
 
+            if prev_var:
+                # Got something to do before the variable is usable, so this is a global!
+                # Therefore we actually do the operation in the Modelverse as well!
+                prev = "  " * nested_indent + "_globs = yield [('RD', [kwargs['root'], '__globals'])]\n" + \
+                       "  " * nested_indent + "_old_edge = yield [('RDE', [_globs, '%s'])]\n" % (instruction_var) + \
+                       "  " * nested_indent + "yield [('DE', [_old_edge])]\n" + \
+                       "  " * nested_indent + "yield [('CD', [_globs, '%s', %s])]\n" % (instruction_var, instruction_val)
+
         elif inst_type["value"] == "call":
             func_name, = yield [("RD", [inst, "func"])]
-            (prev_func_name, func_name), = yield [("CALL_ARGS", [self.print_instruction, (func_name, 0, nested_indent)])]
+            (prev_func_name, func_name), = yield [("CALL_ARGS", [self.print_instruction, (func_name, nested_indent, nested_indent)])]
             param_list = {}
 
             param, = yield [("RD", [inst, "params"])]
@@ -289,15 +302,15 @@ class ModelverseKernel(object):
                 if indent == 0:
                     # No indent, meaning that we use it inline
                     # Therefore, we output the prev and value individually
-                    prev, instruction = computation + "  " * nested_indent + actual_computation, value
+                    prev, instruction = prev_func_name + computation + "  " * nested_indent + actual_computation, value
                 else:
                     # Some indentation, meaning that we don't even use the return value
                     # Therefore, we only do the yield
-                    prev, instruction = computation, "  " * indent + actual_computation
+                    prev, instruction = prev_func_name + computation, "  " * indent + actual_computation
 
         elif inst_type["value"] == "access":
             value, = yield [("RD", [inst, "var"])]
-            (prev_instruction, instruction), = yield [("CALL_ARGS", [self.print_instruction, (value, 0, indent)])]
+            (prev, instruction), = yield [("CALL_ARGS", [self.print_instruction, (value, 0, indent)])]
 
         elif inst_type["value"] == "while":
             cond, body = yield [("RD", [inst, "cond"]),

+ 1 - 5
wrappers/modelverse_SCCD.py

@@ -1,11 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-<<<<<<< HEAD
-Date:   Fri Apr  6 07:27:15 2018
-=======
-Date:   Fri Apr  6 10:27:34 2018
->>>>>>> testing
+Date:   Mon Apr  9 11:16:51 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server