|
@@ -11,27 +11,17 @@ from pypdevs.DEVS import AtomicDEVS, CoupledDEVS
|
|
|
from pypdevs.simulator import Simulator
|
|
|
|
|
|
import json
|
|
|
+import random
|
|
|
|
|
|
+random.seed(1)
|
|
|
max_used_id = 0
|
|
|
|
|
|
-def get_object_constructor(code):
|
|
|
+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")
|
|
|
- global max_used_id
|
|
|
- initial_id = max_used_id
|
|
|
- for i, v in enumerate(constructors):
|
|
|
- if isinstance(v, int):
|
|
|
- # Integer, so rename
|
|
|
- constructors[i] += initial_id
|
|
|
- v = constructors[i]
|
|
|
- if v > max_used_id:
|
|
|
- max_used_id += 1
|
|
|
-
|
|
|
- # Keep a gap for safety purposes!
|
|
|
- max_used_id += 10
|
|
|
-
|
|
|
+ constructors = ['3', '"upload"', '"%s"' % filename, '"%s"' % random.random(), 'true'] + constructors + ['false']
|
|
|
return constructors
|
|
|
|
|
|
def translate(operation):
|
|
@@ -510,8 +500,8 @@ Void function main():
|
|
|
"""
|
|
|
username = "test_user"
|
|
|
|
|
|
-operations = [get_object_constructor(open(f, 'r').read()) for f in files] + \
|
|
|
- get_object_constructor(code) + \
|
|
|
+operations = [get_object_constructor(open(f, 'r').read(), str(f)) for f in files] + \
|
|
|
+ get_object_constructor(code, "main") + \
|
|
|
link_code("main", username, files + ["code.alc"])
|
|
|
|
|
|
print("Generated operations:")
|