Просмотр исходного кода

Restructure bootstrap compiler to make initial code fully transparent
(and thus have line numbers!)

Yentl Van Tendeloo 8 лет назад
Родитель
Сommit
db0825fb12
3 измененных файлов с 36 добавлено и 53 удалено
  1. 9 53
      bootstrap/bootstrap.py
  2. 10 0
      bootstrap/initial_code_manager.alc
  3. 17 0
      bootstrap/initial_code_user.alc

+ 9 - 53
bootstrap/bootstrap.py

@@ -105,41 +105,9 @@ 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()
-    \treturn!
-    '''
-
-    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()
-    \treturn!
-    '''
+    user_manager = "user_manager"
+    initial_code_manager = "bootstrap/initial_code_manager.alc"
+    initial_code_user = "bootstrap/initial_code_user.alc"
 
     ### Actual script to generate the file
     import os
@@ -224,23 +192,14 @@ 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", ["--debug", "--prepend:%s" % prepend, "--main" if main else "--not-main"], symbols=symbols)
                     return code.replace("auto_initial_IP", target)
 
@@ -257,8 +216,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)
@@ -287,10 +245,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)
@@ -300,9 +257,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!