瀏覽代碼

Added memory in the MvI, such that it can also be used for compilation

Yentl Van Tendeloo 9 年之前
父節點
當前提交
5452579dba
共有 1 個文件被更改,包括 26 次插入3 次删除
  1. 26 3
      model/model.py

+ 26 - 3
model/model.py

@@ -133,6 +133,7 @@ class MvIState():
     def __init__(self):
         self.operations = []
         self.output = []
+        self.memory = {}
 
 class ModelverseInterface(AtomicDEVS):
     def __init__(self, operations):
@@ -144,16 +145,38 @@ class ModelverseInterface(AtomicDEVS):
         self.from_mvk = self.addInPort("from_MvK")
 
     def intTransition(self):
-        self.state.operations = []
+        while self.state.operations:
+            i = self.state.operations[0]
+            if isinstance(i, int) and i not in self.memory:
+                break
+            self.state.operations.pop(0)
         return self.state
 
     def extTransition(self, inputs):
         for inp in inputs[self.from_mvk]:
-            self.state.output.append(inp)
+            if inp["value"] == "None" and isinstance(self.state.processing[0], int) and self.state.processing[0] not in self.memory:
+                self.state.memory[self.state.processing.pop(0)] = int(inp["id"])
+            else:
+                self.state.output.append(inp)
         return self.state
 
     def outputFnc(self):
-        return {self.to_mvk: [json.dumps(self.state.operations)]}
+        send = []
+        for i in self.state.operations:
+            if isinstance(i, int) and i not in self.memory:
+                break
+            elif isinstance(i, int) and i in self.memory:
+                # Pass a reference!
+                send.append(("R", self.memory[i]))
+            elif not isinstance(i, int):
+                send.append(("V", i))
+        return {self.to_mvk: [json.dumps(send)]}
+
+    def timeAdvance(self):
+        if self.state.processing and (not isinstance(self.state.processing[0], int) or self.state.processing[0] in self.memory):
+            return 0
+        else:
+            return float("inf")
 
 class NetworkState(object):
     def __init__(self):