瀏覽代碼

Fixed everything

Yentl Van Tendeloo 8 年之前
父節點
當前提交
41c0641a66

二進制
bootstrap/bootstrap.m.gz


+ 10 - 53
bootstrap/bootstrap.py

@@ -7,7 +7,10 @@ import gzip
 def bootstrap():
     root = ["__hierarchy"]
 
+    user_manager = "user_manager"
     bootstrap_files = glob.glob("bootstrap/*.alc")
+    initial_code_manager = "bootstrap/initial_code_manager.alc"
+    initial_code_user = "bootstrap/initial_code_user.alc"
 
     user_data = [   "input",
                     "output",
@@ -105,40 +108,6 @@ def bootstrap():
                     "time": ["Float"],
                 }
 
-    initial_user = "user_manager"
-    initial_user_code = \
-    '''
-    include "bootstrap/primitives.alc"
-    include "user_manager.alh"
-
-    Void function __main():
-    \tElement root
-    \troot = read_root()
-    \troot = root["__hierarchy"]["objects"]
-    \texec(root["bootstrap/user_manager.alc"]["initializers"])
-    \tuser_management()
-    '''
-
-    code_new_users = \
-    '''
-    include "bootstrap/primitives.alc"
-    include "user_interface.alh"
-
-    Void function __main():
-    \tElement root
-    \troot = read_root()
-    \troot = root["__hierarchy"]["objects"]
-    \texec(root["bootstrap/compilation_manager.alc"]["initializers"])
-    \texec(root["bootstrap/constructors.alc"]["initializers"])
-    \texec(root["bootstrap/library.alc"]["initializers"])
-    \texec(root["bootstrap/object_operations.alc"]["initializers"])
-    \texec(root["bootstrap/conformance_scd.alc"]["initializers"])
-    \texec(root["bootstrap/metamodels.alc"]["initializers"])
-    \texec(root["bootstrap/modelling.alc"]["initializers"])
-    \texec(root["bootstrap/user_interface.alc"]["initializers"])
-    \tnew_user()
-    '''
-
     ### Actual script to generate the file
     import os
     import sys
@@ -222,24 +191,15 @@ def bootstrap():
                     f.write("Edge __user_last_%s(_user_last_%s, ___user_last_%s)\n" % (data, data, data))
                     
                 # Bind user to the root
-                f.write('Node ___new_user("%s")\n' % initial_user)
+                f.write('Node ___new_user("%s")\n' % user_manager)
                 f.write("Edge _new_user(root, user_root)\n")
                 f.write("Edge __new_user(_new_user, ___new_user)\n")
 
-                def compile_code_AL(code, target, prepend="", is_file=False, main=False, symbols=None):
+                def compile_code_AL(filename, target, prepend="", main=False, symbols=None):
                     import sys
                     sys.path.append("interface/HUTN/")
                     from hutn_compiler.compiler import main as compile_code
-
-                    if not is_file:
-                        f = tempfile.NamedTemporaryFile(delete=False)
-                        f.write(code)
-                        f.flush()
-                        filename = f.name
-                        f.close()
-                    else:
-                        filename = code
-                    code = compile_code(filename, "interface/HUTN/grammars/actionlanguage.g", "BS", ["--prepend:%s" % prepend, "--main" if main else "--not-main"], symbols=symbols)
+                    code = compile_code(filename, "interface/HUTN/grammars/actionlanguage.g", "BS", ["--debug", "--prepend:%s" % prepend, "--main" if main else "--not-main"], symbols=symbols)
                     return code.replace("auto_initial_IP", target)
 
                 # Create all library code
@@ -255,8 +215,7 @@ def bootstrap():
                     bootstrap_file = bootstrap_file.replace("\\", "/")
                     print("[COMP] %s" % bootstrap_file)
                     symbols = {}
-                    result = compile_code_AL(bootstrap_file, "initial_IP", prepend=bootstrap_file, is_file=True, symbols=symbols)
-                    f.write(result, both=False)
+                    f.write(compile_code_AL(bootstrap_file, "initial_IP", prepend=bootstrap_file, symbols=symbols, main = bootstrap_file in [initial_code_manager, initial_code_user]), both=False)
 
                     # Now link the code with the compilation manager structure
                     f.write("Node elem()\n", both=False)
@@ -285,10 +244,9 @@ def bootstrap():
                         f.write('Edge _(_, k)\n', both=False)
 
                 # Create code for initial user
-                print("[BOOT] initial_user")
-                f.write(compile_code_AL(initial_user_code, "initial_IP", prepend="user_manager", main=True), both=False)
+                print("[BOOT] user_manager")
                 f.write('Node _IP_str("IP")\n', both=False)
-                f.write("Edge _user_frame(user_frame, user_manager_initial_IP)\n", both=False)
+                f.write("Edge _user_frame(user_frame, %s_initial_IP)\n" % initial_code_manager, both=False)
                 f.write("Edge __user_frame(_user_frame, _IP_str)\n", both=False)
 
                 f.write('Node __phase("init")\n', both=False)
@@ -298,9 +256,8 @@ def bootstrap():
 
                 # Create code for new users to start at
                 print("[BOOT] new_user")
-                f.write(compile_code_AL(code_new_users, "initial_IP", prepend="new_user", main=True), both=False)
                 f.write('Node __IP_str("__IP")\n', both=False)
-                f.write("Edge _user_IP(__hierarchy, new_user_initial_IP)\n", both=False)
+                f.write("Edge _user_IP(__hierarchy, %s_initial_IP)\n" % initial_code_user, both=False)
                 f.write("Edge __user_IP(_user_IP, __IP_str)\n", both=False)
     except:
         os.remove("bootstrap/bootstrap.m.gz")

+ 10 - 0
bootstrap/initial_code_manager.alc

@@ -0,0 +1,10 @@
+include "bootstrap/primitives.alc"
+include "user_manager.alh"
+
+Void function __main():
+	Element root
+	root = read_root()
+	root = root["__hierarchy"]["objects"]
+	exec(root["bootstrap/user_manager.alc"]["initializers"])
+	user_management()
+	return!

+ 17 - 0
bootstrap/initial_code_user.alc

@@ -0,0 +1,17 @@
+include "bootstrap/primitives.alc"
+include "user_interface.alh"
+
+Void function __main():
+	Element root
+	root = read_root()
+	root = root["__hierarchy"]["objects"]
+	exec(root["bootstrap/compilation_manager.alc"]["initializers"])
+	exec(root["bootstrap/constructors.alc"]["initializers"])
+	exec(root["bootstrap/library.alc"]["initializers"])
+	exec(root["bootstrap/object_operations.alc"]["initializers"])
+	exec(root["bootstrap/conformance_scd.alc"]["initializers"])
+	exec(root["bootstrap/metamodels.alc"]["initializers"])
+	exec(root["bootstrap/modelling.alc"]["initializers"])
+	exec(root["bootstrap/user_interface.alc"]["initializers"])
+	new_user()
+	return!

+ 4 - 0
bootstrap/user_interface.alc

@@ -19,5 +19,9 @@ Void function new_user():
 			compilation_manager()
 		elif (interface == 4):
 			construct_model()
+		elif (interface == -1):
+			return!
 		else:
 			log("Unsupported interface!")
+
+	return!

+ 2 - 0
bootstrap/user_manager.alc

@@ -29,3 +29,5 @@ Void function user_management():
 
 			//Add this only at the end, as otherwise the user will already be detected
 			dict_add(read_root(), username, user_root)
+
+	return!

+ 0 - 1
hybrid_server/classes/server.xml

@@ -88,7 +88,6 @@
                             <parameter expr="instancename"/>
                         </raise>
                     </transition>
-                    <transition after="1.0" target="."/>
                 </state>
             </state>
 

+ 2 - 0
integration/code/binary_to_decimal.alc

@@ -21,3 +21,5 @@ Integer function b2d(param : String):
 Void function main():
 	while(True):
 		output(b2d(input()))
+
+	return!

+ 2 - 0
integration/code/cbd_semantics.alc

@@ -659,3 +659,5 @@ Void function main():
 
 	while (True):
 		execute_cbd(instantiate_model(import_node("models/CausalBlockDiagrams_Design")))
+
+	return!

+ 2 - 0
integration/code/factorial.alc

@@ -9,3 +9,5 @@ Integer function factorial(n : Integer):
 Void function main():
 	while(True):
 		output(factorial(input()))
+
+	return!

+ 2 - 0
integration/code/fibonacci.alc

@@ -9,3 +9,5 @@ Integer function fib(param : Integer):
 Void function main():
 	while(True):
 		output(fib(input()))
+
+	return!

+ 2 - 0
integration/code/fibonacci_smart.alc

@@ -15,3 +15,5 @@ Void function main():
 	list_append(numbers, 1)
 	while(True):
 		output(fib(input()))
+
+	return!

+ 2 - 0
integration/code/fsa_semantics.alc

@@ -252,3 +252,5 @@ Void function main():
 
 	while (True):
 		execute_fsa(instantiate_model(import_node("models/FiniteStateAutomata_Design")))
+
+	return!

+ 2 - 0
integration/code/if_elif.alc

@@ -10,3 +10,5 @@ Integer function compare_with_zero(n : Integer):
 Void function main():
 	while(True):
 		output(compare_with_zero(input()))
+
+	return!

+ 2 - 0
integration/code/if_elif_else.alc

@@ -11,3 +11,5 @@ Integer function compare_with_zero(n : Integer):
 Void function main():
 	while(True):
 		output(compare_with_zero(input()))
+
+	return!

+ 2 - 0
integration/code/leap_year.alc

@@ -14,3 +14,5 @@ Boolean function leap_year(year : Integer):
 Void function main():
 	while (True):
 		output(leap_year(input()))
+
+	return!

+ 2 - 0
integration/code/mini_modify.alc

@@ -250,3 +250,5 @@ Element function modify(model : Element):
 		else:
 			output("Unknown command: " + cast_v2s(cmd))
 			output("Use command 'help' to get a list of available commands")
+
+	return model!

+ 5 - 1
integration/code/pn_interface.alc

@@ -277,7 +277,9 @@ Element function model_loaded(model : Element):
 			output("Unknown command: " + cast_v2s(cmd))
 			output("Use command 'help' to get a list of available commands")
 
-Element function main():
+	return model!
+
+Void function main():
 	output("Welcome to the Model Management Interface, running live on the Modelverse!")
 	output("Use 'help' command for a list of possible commands")
 	String command
@@ -361,3 +363,5 @@ Element function main():
 			output("Back in model manager!")
 		else:
 			output("Command not recognized, use 'help' for a list of possible commands")
+
+	return!

+ 4 - 0
integration/code/pn_semantics.alc

@@ -123,6 +123,8 @@ Void function main():
 			else:
 				output("Non-conforming model: " + verify_result)
 
+	return!
+
 Void function execute_petrinet(model : Element):
 	String cmd
 	while (True):
@@ -147,3 +149,5 @@ Void function execute_petrinet(model : Element):
 		else:
 			output("Did not understand command!")
 			output("Use 'help' for a list of available options")
+
+	return!

+ 2 - 0
integration/code/power.alc

@@ -9,3 +9,5 @@ Integer function power(base : Integer, exponent : Integer):
 Void function main():
 	while (True):
 		output(power(input(), input()))
+
+	return!

+ 2 - 0
integration/code/remainder.alc

@@ -3,3 +3,5 @@ include "lib_remainder.alc"
 Void function main():
 	while(True):
 		output(remainder(input(), input()))
+
+	return!

+ 2 - 0
integration/code/revert.alc

@@ -19,3 +19,5 @@ String function revert_string(a : String):
 Void function main():
 	while (True):
 		output(revert_string(input()))
+
+	return!

+ 2 - 0
integration/code/rpgame_semantics.alc

@@ -27,6 +27,8 @@ Void function main():
 			else:
 				output("Non-conforming model: " + verify_result)
 
+	return!
+
 String function getHeroTile(model : Element, hero : String):
 	return set_pop(followAssociation(model, hero, "Character_on_tile"))!
 

+ 2 - 0
interface/HUTN/hutn_compiler/bootstrap_visitor.py

@@ -33,6 +33,8 @@ class BootstrapVisitor(PrimitivesVisitor):
             self.dict(access, "var", resolve)
             self.dict(call, "func", access)
             self.dict(self.last_instruction, "next", call)
+            ret = self.value(Action("return"))
+            self.dict(call, "next", ret)
 
         output = []
         for t, data in self.output:

+ 3 - 1
interface/HUTN/hutn_compiler/primitives_visitor.py

@@ -12,9 +12,11 @@ class PrimitivesVisitor(Visitor):
         self.output = []
         self.free_id = 0
         self.function_values = dict()
+        self.debug_symbols = "--debug" in args
 
     def debug(self, node, tree, msg=""):
-        self.dict(node, "__debug", self.value("[%s] %s" % (tree.get_reference_line(), msg)))
+        if self.debug_symbols:
+            self.dict(node, "__debug", self.value("[%s] %s" % (tree.get_reference_line(), msg)))
 
     def node(self):
         self.output.append(("N", self.free_id))

+ 12 - 7
kernel/modelverse_kernel/main.py

@@ -44,7 +44,11 @@ class ModelverseKernel(object):
 
     def execute_rule(self, username):
         user_root, =    yield [("RD", [self.root, username])]
-        if user_root is not None:
+        if user_root is None:
+            self.success = False
+            self.returnvalue = None
+            yield None
+        else:
             user_frame, =   yield [("RD", [user_root, "frame"])]
             self.inst, phase =   yield [("RD", [user_frame, "IP"]),
                                    ("RD", [user_frame, "phase"]),
@@ -60,7 +64,7 @@ class ModelverseKernel(object):
             if self.phase_v == "finish":
                 gen = self.helper_init(user_root)
             elif self.inst is None:
-                raise Exception("Instruction pointer could not be found for user %s!" % username)
+                raise Exception("Instruction pointer could not be found!")
             elif isinstance(self.phase_v, string_types):
                 if self.phase_v == "init" and self.inst in self.compiled:
                     #print("%-30s(%s)" % ("COMPILED " + str(self.compiled[self.inst]), self.phase_v))
@@ -84,8 +88,6 @@ class ModelverseKernel(object):
                     inp = yield gen.send(inp)
             except StopIteration:
                 pass
-        else:
-            print("Trying to execute non-existing user %s; ignored" % username)
 
     ##########################
     ### Process primitives ###
@@ -528,9 +530,12 @@ class ModelverseKernel(object):
 
         if value is None:
             prev_frame, =   yield [("RD", [user_frame, "prev"])]
-            _, _ =          yield [("CD", [user_root, "frame", prev_frame]),
-                                   ("DN", [user_frame]),
-                                  ]
+            if prev_frame is None:
+                _, =            yield [("DN", [user_root])]
+            else:
+                _, _ =          yield [("CD", [user_root, "frame", prev_frame]),
+                                       ("DN", [user_frame]),
+                                      ]
         else:
             evalstack, evalstack_link, ip_link, new_evalstack, evalstack_phase = \
                             yield [("RD", [user_frame, "evalstack"]),

+ 5 - 0
kernel/mvk_server/classes/mvkcontroller.xml

@@ -92,6 +92,7 @@
                         <parameter name="data"/>
                         <script>                                
                             # No JSON encoding necessary, as it is not complex
+                            print("Got from MVI")
                             try:
                                 args = None
                                 if data["op"] == "set_input":
@@ -102,7 +103,9 @@
                                     for v in value[:-1]:
                                         self.input_queue.append((None, data["op"], [v], data["username"]))
                                     self.input_queue.append((source, data["op"], [value[-1]], data["username"]))
+                                    print("Added to input queue")
                                 else:
+                                    print("Appending " + data["op"])
                                     self.input_queue.append((source, data["op"], args, data["username"]))
                             except ValueError:
                                 print("Error when deserializing request: " + str(data))
@@ -119,6 +122,7 @@
                     <transition cond="self.input_queue and self.input_queue[0][3] not in self.user_statecharts" target=".">
                         <!-- Move it to the back of the list, so we can process other users first -->
                         <script>
+                            print("Queue user")
                             self.user_queue.setdefault(self.input_queue[0][3], []).append(self.input_queue.pop(0))
                         </script>
                         <!-- Force a refresh too -->
@@ -150,6 +154,7 @@
                     
                     <transition cond="self.input_queue[0][1] == 'pause'" target="../wait">
                         <script>
+                            print("Sending pause")
                             source, op, args, username = self.input_queue.pop(0)
                         </script>
                         <raise event="pause" scope="narrow" target="self.user_statecharts[username]">

+ 0 - 1
kernel/mvk_server/classes/server.xml

@@ -88,7 +88,6 @@
                             <parameter expr="instancename"/>
                         </raise>
                     </transition>
-                    <transition after="1.0" target="."/>
                 </state>
             </state>
 

+ 6 - 12
kernel/mvk_server/server.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:   Thu Feb  9 16:49:58 2017
+Date:   Fri Feb 10 10:24:39 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
@@ -297,6 +297,7 @@ class MvKController(RuntimeClassBase):
         source = parameters[0]
         data = parameters[1]
         # No JSON encoding necessary, as it is not complex
+        print("Got from MVI")
         try:
             args = None
             if data["op"] == "set_input":
@@ -307,7 +308,9 @@ class MvKController(RuntimeClassBase):
                 for v in value[:-1]:
                     self.input_queue.append((None, data["op"], [v], data["username"]))
                 self.input_queue.append((source, data["op"], [value[-1]], data["username"]))
+                print("Added to input queue")
             else:
+                print("Appending " + data["op"])
                 self.input_queue.append((source, data["op"], args, data["username"]))
         except ValueError:
             print("Error when deserializing request: " + str(data))
@@ -317,6 +320,7 @@ class MvKController(RuntimeClassBase):
         return self.input_queue and self.input_queue[0][3] in self.user_statecharts
     
     def _running_push_wait_1_exec(self, parameters):
+        print("Queue user")
         self.user_queue.setdefault(self.input_queue[0][3], []).append(self.input_queue.pop(0))
         self.raiseInternalEvent(Event("force_user_refresh", None, []))
     
@@ -338,6 +342,7 @@ class MvKController(RuntimeClassBase):
         return self.input_queue[0][1] == 'get_output'
     
     def _running_push_process_2_exec(self, parameters):
+        print("Sending pause")
         source, op, args, username = self.input_queue.pop(0)
         self.big_step.outputEventOM(Event("narrow_cast", None, [self, self.user_statecharts[username], Event("pause", None, [source, args])]))
     
@@ -456,8 +461,6 @@ class Server(RuntimeClassBase):
         
         # state /main/server/accepting
         self.states["/main/server/accepting"] = State(8, self)
-        self.states["/main/server/accepting"].setEnter(self._main_server_accepting_enter)
-        self.states["/main/server/accepting"].setExit(self._main_server_accepting_exit)
         
         # state /main/close_socket
         self.states["/main/close_socket"] = State(9, self)
@@ -516,9 +519,6 @@ class Server(RuntimeClassBase):
         _main_server_accepting_1.setAction(self._main_server_accepting_1_exec)
         _main_server_accepting_1.setTrigger(Event("instance_created", None))
         self.states["/main/server/accepting"].addTransition(_main_server_accepting_1)
-        _main_server_accepting_2 = Transition(self, self.states["/main/server/accepting"], [self.states["/main/server/accepting"]])
-        _main_server_accepting_2.setTrigger(Event("_0after"))
-        self.states["/main/server/accepting"].addTransition(_main_server_accepting_2)
         
         # transition /main/close_socket/close
         _main_close_socket_close_0 = Transition(self, self.states["/main/close_socket/close"], [self.states["/main/close_socket/close"]])
@@ -535,12 +535,6 @@ class Server(RuntimeClassBase):
     def _main_server_listening_enter(self):
         self.big_step.outputEvent(Event("listen_socket", "socket_out", [self.socket]))
     
-    def _main_server_accepting_enter(self):
-        self.addTimer(0, 1.0)
-    
-    def _main_server_accepting_exit(self):
-        self.removeTimer(0)
-    
     def _main_forward_forward_0_exec(self, parameters):
         association_name = parameters[0]
         data = parameters[1]

+ 1 - 2
scripts/check_objects.py

@@ -43,6 +43,5 @@ def to_recompile(address, files):
             # Different, so rebuild
             rebuild.append(f)
 
-    # Remove user again
-    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"__%s"' % username, "username": "user_manager"}))).read()
+    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '-1', "username": username}))).read()
     return rebuild

+ 3 - 2
scripts/compile.py

@@ -1,6 +1,7 @@
 import sys
 import os
 import urllib2
+import urllib
 import subprocess
 
 def do_compile(address, filename, username, modulename, mode, optionals=[], grammar="grammars/actionlanguage.g"):
@@ -11,9 +12,9 @@ def do_compile(address, filename, username, modulename, mode, optionals=[], gram
     except urllib2.URLError:
         return 2
     except:
-        urllib2.urlopen(urllib2.Request(address, 'op=set_input&username=user_manager&value="__%s"' % username)).read()
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '-1', "username": username}))).read()
         return 1
-    urllib2.urlopen(urllib2.Request(address, 'op=set_input&username=user_manager&value="__%s"' % username)).read()
+    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '-1', "username": username}))).read()
     return 0
 
 if __name__ == "__main__":

+ 1 - 1
scripts/debug_prompt.py

@@ -42,4 +42,4 @@ while 1:
         local_print("Received quit: breaking connection to Modelverse immediately!")
         break
 
-    print urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "username": username}))).read()
+    print (urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "username": username}))).read())

+ 1 - 1
scripts/execute_model.py

@@ -41,7 +41,7 @@ def initialize_SCD():
     print("Initialized!")
 
 def do_compile_wrapper(filename, mode, grammar):
-    do_compile(address, filename, str(random.random()), filename, mode, [], grammar=grammar)
+    do_compile(address, filename, str(random.random()), filename, mode, ["--debug"], grammar=grammar)
 
 # Parse all models and upload them
 initialize_SCD()

+ 1 - 1
scripts/make_all.py

@@ -17,6 +17,6 @@ if __name__ == "__main__":
 
         new_files = to_recompile(address, files)
         for f in new_files:
-            do_compile(address, f, str(random.random()), f, "PO")
+            do_compile(address, f, str(random.random()), f, "PO", ["--debug"])
 
         link_and_load(address, username, files)

+ 1 - 1
scripts/make_parallel.py

@@ -9,7 +9,7 @@ import glob
 
 def main(address, username, files):
     def do_compile_wrapper(filename):
-        do_compile(address, filename, str(random.random()), filename, "PO")
+        do_compile(address, filename, str(random.random()), filename, "PO", ["--debug"])
 
     p = multiprocessing.Pool(multiprocessing.cpu_count() * 2)
     new_files = to_recompile(address, files)