Jelajahi Sumber

Fix self-removing users

Yentl Van Tendeloo 8 tahun lalu
induk
melakukan
8e9c6f1445

TEMPAT SAMPAH
bootstrap/bootstrap.m.gz


+ 2 - 0
bootstrap/bootstrap.py

@@ -117,6 +117,7 @@ def bootstrap():
     \troot = root["__hierarchy"]["objects"]
     \texec(root["bootstrap/user_manager.alc"]["initializers"])
     \tuser_management()
+    \treturn!
     '''
 
     code_new_users = \
@@ -137,6 +138,7 @@ def bootstrap():
     \texec(root["bootstrap/modelling.alc"]["initializers"])
     \texec(root["bootstrap/user_interface.alc"]["initializers"])
     \tnew_user()
+    \treturn!
     '''
 
     ### Actual script to generate the file

+ 2 - 0
bootstrap/user_interface.alc

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

+ 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:

+ 46 - 38
kernel/modelverse_kernel/main.py

@@ -43,45 +43,50 @@ class ModelverseKernel(object):
 
     def execute_rule(self, username):
         user_root, =    yield [("RD", [self.root, username])]
-        user_frame, =   yield [("RD", [user_root, "frame"])]
-        inst, phase =   yield [("RD", [user_frame, "IP"]),
-                               ("RD", [user_frame, "phase"]),
-                              ]
-        self.new_debug, phase_v, inst_v = \
-                        yield [("RD", [inst, "__debug"]),
-                               ("RV", [phase]),
-                               ("RV", [inst]),
-                              ]
-        if self.new_debug is not None:
-            self.debug_info, = yield [("RV", [self.new_debug])]
-
-        if phase_v == "finish":
-            gen = self.helper_init(user_root)
-        elif inst is None:
-            raise Exception("Instruction pointer could not be found!")
-        elif isinstance(phase_v, string_types):
-            if phase_v == "init" and inst in self.compiled:
-                #print("%-30s(%s)" % ("COMPILED " + str(self.compiled[inst]), phase_v))
-                gen = self.execute_primitive(user_root, inst, username)
+        if user_root is None:
+            self.success = False
+            self.returnvalue = None
+            yield None
+        else:
+            user_frame, =   yield [("RD", [user_root, "frame"])]
+            inst, phase =   yield [("RD", [user_frame, "IP"]),
+                                   ("RD", [user_frame, "phase"]),
+                                  ]
+            self.new_debug, phase_v, inst_v = \
+                            yield [("RD", [inst, "__debug"]),
+                                   ("RV", [phase]),
+                                   ("RV", [inst]),
+                                  ]
+            if self.new_debug is not None:
+                self.debug_info, = yield [("RV", [self.new_debug])]
+
+            if phase_v == "finish":
+                gen = self.helper_init(user_root)
+            elif inst is None:
+                raise Exception("Instruction pointer could not be found!")
+            elif isinstance(phase_v, string_types):
+                if phase_v == "init" and inst in self.compiled:
+                    #print("%-30s(%s)" % ("COMPILED " + str(self.compiled[inst]), phase_v))
+                    gen = self.execute_primitive(user_root, inst, username)
+                elif inst_v is None:
+                    raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info, inst_v, phase_v))
+                else:
+                    #print("%-30s(%s) -- %s" % (inst_v["value"], phase_v, username))
+                    gen = getattr(self, "%s_%s" % (inst_v["value"], phase_v))(user_root)
             elif inst_v is None:
                 raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info, inst_v, phase_v))
+            elif inst_v["value"] == "call":
+                #print("%-30s(%s)" % ("call", "param"))
+                gen = self.call_param(user_root)
             else:
-                #print("%-30s(%s) -- %s" % (inst_v["value"], phase_v, username))
-                gen = getattr(self, "%s_%s" % (inst_v["value"], phase_v))(user_root)
-        elif inst_v is None:
-            raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info, inst_v, phase_v))
-        elif inst_v["value"] == "call":
-            #print("%-30s(%s)" % ("call", "param"))
-            gen = self.call_param(user_root)
-        else:
-            raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info, inst_v, phase_v))
+                raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info, inst_v, phase_v))
 
-        try:
-            inp = None
-            while 1:
-                inp = yield gen.send(inp)
-        except StopIteration:
-            pass
+            try:
+                inp = None
+                while 1:
+                    inp = yield gen.send(inp)
+            except StopIteration:
+                pass
 
     ##########################
     ### Process primitives ###
@@ -524,9 +529,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"]),

+ 1 - 0
scripts/check_objects.py

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

+ 3 - 0
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,7 +12,9 @@ def do_compile(address, filename, username, modulename, mode, optionals=[], gram
     except urllib2.URLError:
         return 2
     except:
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '-1', "username": username}))).read()
         return 1
+    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '-1', "username": username}))).read()
     return 0
 
 if __name__ == "__main__":