|
@@ -5,7 +5,6 @@ sys.path.append("interface/HUTN")
|
|
|
from modelverse_state.main import ModelverseState as MvS
|
|
|
from modelverse_kernel.main import ModelverseKernel as MvK
|
|
|
from hutn_compiler.compiler import main as do_compile
|
|
|
-from hutn_compiler.linker import link
|
|
|
|
|
|
from pypdevs.DEVS import AtomicDEVS, CoupledDEVS
|
|
|
from pypdevs.simulator import Simulator
|
|
@@ -14,18 +13,6 @@ import json
|
|
|
import random
|
|
|
|
|
|
random.seed(1)
|
|
|
-max_used_id = 0
|
|
|
-
|
|
|
-def get_object_constructor(code, filename):
|
|
|
- with open(".code.alc", "w") as f:
|
|
|
- f.write(code)
|
|
|
- f.flush()
|
|
|
- constructors = do_compile(".code.alc", "interface/HUTN/grammars/actionlanguage.g", "CS")
|
|
|
- constructors = [3, "upload", filename, str(random.random()), True] + constructors + [False]
|
|
|
- return constructors
|
|
|
-
|
|
|
-def link_code(main_function, taskname, objects):
|
|
|
- return [3, "link_and_load"] + objects + ["", main_function]
|
|
|
|
|
|
def translate(operation):
|
|
|
return {
|
|
@@ -182,9 +169,11 @@ class ModelverseKernel(AtomicDEVS):
|
|
|
def extTransition(self, inputs):
|
|
|
if self.from_mvi in inputs:
|
|
|
# Got input from MvI, so we queue it
|
|
|
+ print("Inputs: " + str(inputs[self.from_mvi]))
|
|
|
for inp in inputs[self.from_mvi]:
|
|
|
taskname = inp[0]
|
|
|
data = inp[1]
|
|
|
+ print("Got operation for taskname %s: %s" % (taskname, data))
|
|
|
if data is not None:
|
|
|
self.state.inputs.setdefault(taskname, []).extend(data)
|
|
|
else:
|
|
@@ -193,13 +182,12 @@ class ModelverseKernel(AtomicDEVS):
|
|
|
if self.from_mvs in inputs:
|
|
|
# Got input from MvS, so we can continue processing
|
|
|
for mvs_input in inputs[self.from_mvs]:
|
|
|
- mvs_stripped = [i[0] for i in mvs_input]
|
|
|
if self.state.mvk is None:
|
|
|
# No MvK, so set it with the root we have just received (or should have received)
|
|
|
- self.state.root = mvs_stripped[0]
|
|
|
+ self.state.root = mvs_input[0]
|
|
|
self.state.mvk = MvK(self.state.root)
|
|
|
else:
|
|
|
- self.state.reply = mvs_stripped
|
|
|
+ self.state.reply = mvs_input
|
|
|
self.state.waiting = False
|
|
|
|
|
|
return self.state
|
|
@@ -242,8 +230,8 @@ class ModelverseKernel(AtomicDEVS):
|
|
|
elif self.state.phase == "input":
|
|
|
# Process inputs
|
|
|
if self.state.inputs.get(self.state.current_task, None):
|
|
|
- element_type, value = self.state.inputs[self.state.current_task][0]
|
|
|
- commands = self.state.mvk.execute_yields(self.state.current_task, "set_input", [element_type, value], self.state.reply)
|
|
|
+ value = self.state.inputs[self.state.current_task]
|
|
|
+ commands = self.state.mvk.execute_yields(self.state.current_task, "set_input", [value], self.state.reply)
|
|
|
if commands is None:
|
|
|
self.state.inputs[self.state.current_task].pop(0)
|
|
|
else:
|
|
@@ -309,7 +297,6 @@ class MvIState():
|
|
|
self.operations = []
|
|
|
self.output = []
|
|
|
self.processing = []
|
|
|
- self.memory = {}
|
|
|
self.init = True
|
|
|
|
|
|
class ModelverseInterface(AtomicDEVS):
|
|
@@ -324,28 +311,24 @@ class ModelverseInterface(AtomicDEVS):
|
|
|
|
|
|
def intTransition(self):
|
|
|
self.state.init = False
|
|
|
- while self.state.operations:
|
|
|
- i = self.state.operations[0]
|
|
|
- if isinstance(i, int) and i not in self.state.memory:
|
|
|
- break
|
|
|
- self.state.operations.pop(0)
|
|
|
+ self.state.operations = []
|
|
|
return self.state
|
|
|
|
|
|
def extTransition(self, inputs):
|
|
|
for inp in inputs[self.from_mvk]:
|
|
|
- if inp["value"] == "None" and isinstance(self.state.processing[0], int) and self.state.processing[0] not in self.state.memory:
|
|
|
- self.state.memory[self.state.processing.pop(0)] = int(inp["id"])
|
|
|
- else:
|
|
|
- self.state.output.append(inp)
|
|
|
+ self.state.output.append(inp)
|
|
|
return self.state
|
|
|
|
|
|
def outputFnc(self):
|
|
|
- return {self.to_mvk: [(self.taskname, self.state.operations)]}
|
|
|
+ if self.state.operations:
|
|
|
+ return {self.to_mvk: [(self.taskname, self.state.operations)]}
|
|
|
+ else:
|
|
|
+ return {}
|
|
|
|
|
|
def timeAdvance(self):
|
|
|
if self.state.init:
|
|
|
return 0
|
|
|
- elif self.state.processing and (not isinstance(self.state.processing[0], int) or self.state.processing[0] in self.state.memory):
|
|
|
+ elif self.state.processing:
|
|
|
return 0
|
|
|
else:
|
|
|
return float("inf")
|
|
@@ -483,23 +466,9 @@ class System(CoupledDEVS):
|
|
|
self.connectPorts(self.mvk.to_mvi, self.mvk2mvi.input_port)
|
|
|
self.connectPorts(self.mvk2mvi.output_port, self.mvi.from_mvk)
|
|
|
|
|
|
-files = ["bootstrap/primitives.alc"]
|
|
|
-code = \
|
|
|
- """
|
|
|
-include "primitives.alh"
|
|
|
-
|
|
|
-Void function main():
|
|
|
-\tlog("Executed the code!")
|
|
|
-\treturn !
|
|
|
- """
|
|
|
taskname = "test_task"
|
|
|
|
|
|
-operations = [get_object_constructor(open(f, 'r').read(), str(f)) for f in files] + \
|
|
|
- get_object_constructor(code, "main") + \
|
|
|
- link_code("main", taskname, files + ["code.alc"])
|
|
|
-
|
|
|
-print("Generated operations:")
|
|
|
-print(operations)
|
|
|
+operations = ["admin", "admin"]
|
|
|
|
|
|
args = {
|
|
|
"taskname": taskname,
|