|
@@ -1,8 +1,11 @@
|
|
|
### Configuration for creating the bootstrap model using conformance_bottom.
|
|
|
+import glob
|
|
|
|
|
|
def bootstrap():
|
|
|
root = ["__hierarchy"]
|
|
|
|
|
|
+ bootstrap_files = glob.glob("bootstrap/*.alc")
|
|
|
+
|
|
|
user_data = [ "input",
|
|
|
"output",
|
|
|
"globals",
|
|
@@ -100,82 +103,39 @@ def bootstrap():
|
|
|
initial_user = "user_manager"
|
|
|
initial_user_code = \
|
|
|
'''
|
|
|
- Element function read_root() = ?primitives/read_root
|
|
|
- Element function dict_read(a: Element, b: Element) = ?primitives/dict_read
|
|
|
- Element function create_node() = ?primitives/create_node
|
|
|
- Element function create_value(a: Element) = ?primitives/create_value
|
|
|
- Element function dict_add(a: Element, b: Element, c: Element) = ?primitives/dict_add
|
|
|
- Boolean function value_eq(a: String, b: String) = ?primitives/value_eq
|
|
|
- Boolean function delete_element(a: Element) = ?primitives/delete_element
|
|
|
- Boolean function bool_not(a: Boolean) = ?primitives/bool_not
|
|
|
- Boolean function dict_in(a: Element, b: Element) = ?primitives/dict_in
|
|
|
-
|
|
|
- Element function input()
|
|
|
+ include "primitives.alc"
|
|
|
+ include "user_manager.alh"
|
|
|
|
|
|
Void function __main():
|
|
|
- \tString username
|
|
|
- \tElement user_root
|
|
|
- \tElement user_frame
|
|
|
- \tElement output_value
|
|
|
- \tElement input_value
|
|
|
- \t
|
|
|
- \twhile (True):
|
|
|
- \t\tusername = input()
|
|
|
- \t\tif (value_eq(username, "__delete")):
|
|
|
- \t\t\tuser_root = dict_read(read_root(), input())
|
|
|
- \t\t\tdelete_element(user_root)
|
|
|
- \t\telse:
|
|
|
- \t\t\tif (bool_not(dict_in(read_root(), username))):
|
|
|
- \t\t\t\tuser_root = create_node()
|
|
|
- \t\t\t\tuser_frame = create_node()
|
|
|
- \t\t\t\toutput_value = create_node()
|
|
|
- \t\t\t\tinput_value = create_node()
|
|
|
- \t\t\t\tdict_add(user_root, "frame", user_frame)
|
|
|
- \t\t\t\tdict_add(user_root, "globals", create_node())
|
|
|
- \t\t\t\tdict_add(user_root, "output", output_value)
|
|
|
- \t\t\t\tdict_add(user_root, "last_output", output_value)
|
|
|
- \t\t\t\tdict_add(user_root, "input", input_value)
|
|
|
- \t\t\t\tdict_add(user_root, "last_input", input_value)
|
|
|
- \t\t\t\tdict_add(user_frame, "evalstack", create_node())
|
|
|
- \t\t\t\tdict_add(user_frame, "returnvalue", create_node())
|
|
|
- \t\t\t\tdict_add(user_frame, "phase", "init")
|
|
|
- \t\t\t\tdict_add(user_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
|
|
|
- \t\t\t\tdict_add(user_frame, "symbols", create_node())
|
|
|
- \t\t\t\t//Add this only at the end, as otherwise the user will already be detected
|
|
|
- \t\t\t\tdict_add(read_root(), username, user_root)
|
|
|
+ \tlog("In __main")
|
|
|
+ \tElement root
|
|
|
+ \troot = read_root()
|
|
|
+ \troot = root["__hierarchy"]["objects"]
|
|
|
+ \tlog("Call exec")
|
|
|
+ \texec(root["bootstrap/user_manager.alc"])
|
|
|
+ \tlog("Called exec")
|
|
|
+ \tuser_management()
|
|
|
'''
|
|
|
|
|
|
code_new_users = \
|
|
|
'''
|
|
|
- Element main
|
|
|
-
|
|
|
- // Do this only in the bootstrapper
|
|
|
- include "io.alh"
|
|
|
include "primitives.alc"
|
|
|
- include "compilation_manager.alc"
|
|
|
- include "constructors.alc"
|
|
|
- include "library.alc"
|
|
|
- include "object_operations.alc"
|
|
|
- include "conformance_scd.alc"
|
|
|
- include "modelling.alc"
|
|
|
- include "metamodels.alc"
|
|
|
+ include "user_interface.alh"
|
|
|
|
|
|
Void function __main():
|
|
|
- \tInteger interface
|
|
|
- \twhile (True):
|
|
|
- \t\tinterface = input()
|
|
|
- \t\tif (interface == 0):
|
|
|
- \t\t\texec(deserialize(input()))
|
|
|
- \t\telif (interface == 1):
|
|
|
- \t\t\texec(construct_unknown())
|
|
|
- \t\telif (interface == 2):
|
|
|
- \t\t\toutput("DONE")
|
|
|
- \t\telif (interface == 3):
|
|
|
- \t\t\tcompilation_manager()
|
|
|
- \t\telif (interface == 4):
|
|
|
- \t\t\tconstruct_model()
|
|
|
- \t\telse:
|
|
|
- \t\t\tlog("Unsupported interface!")
|
|
|
+ \tElement root
|
|
|
+ \troot = read_root()
|
|
|
+ \troot = root["__hierarchy"]["objects"]
|
|
|
+ \texec(root["bootstrap/primitives.alc"])
|
|
|
+ \texec(root["bootstrap/compilation_manager.alc"])
|
|
|
+ \texec(root["bootstrap/constructors.alc"])
|
|
|
+ \texec(root["bootstrap/library.alc"])
|
|
|
+ \texec(root["bootstrap/object_operations.alc"])
|
|
|
+ \texec(root["bootstrap/conformance_scd.alc"])
|
|
|
+ \texec(root["bootstrap/metamodels.alc"])
|
|
|
+ \texec(root["bootstrap/modelling.alc"])
|
|
|
+ \texec(root["bootstrap/user_interface.alc"])
|
|
|
+ \tnew_user()
|
|
|
'''
|
|
|
|
|
|
### Actual script to generate the file
|
|
@@ -265,21 +225,45 @@ def bootstrap():
|
|
|
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):
|
|
|
+ def compile_code_AL(code, target, prepend="", is_file=False, main=False):
|
|
|
import sys
|
|
|
sys.path.append("interface/HUTN/")
|
|
|
from hutn_compiler.compiler import main as compile_code
|
|
|
|
|
|
- with open("bootstrap/bootstrap.al", "w") as f:
|
|
|
- f.write(code)
|
|
|
- code = compile_code("bootstrap/bootstrap.al", "interface/HUTN/grammars/actionlanguage.g", "BS", ["--debug"])
|
|
|
- os.remove("bootstrap/bootstrap.al")
|
|
|
+ if not is_file:
|
|
|
+ with open("bootstrap/bootstrap.al", "w") as f:
|
|
|
+ f.write(code)
|
|
|
+ filename = "bootstrap/bootstrap.al"
|
|
|
+ else:
|
|
|
+ filename = code
|
|
|
+ code = compile_code(filename, "interface/HUTN/grammars/actionlanguage.g", "BS", ["--debug", "--prepend:%s" % prepend, "--main" if main else "--not-main"])
|
|
|
+ if not is_file:
|
|
|
+ os.remove("bootstrap/bootstrap.al")
|
|
|
return code.replace("auto_initial_IP", target)
|
|
|
|
|
|
+ # Create all library code
|
|
|
+ # But first create the structure to hold compiled data
|
|
|
+ f.write("Node __objects()\n", both=False)
|
|
|
+ f.write('Node __objects_name("objects")\n', both=False)
|
|
|
+ f.write("Edge __obj_link(__hierarchy, __objects)\n", both=False)
|
|
|
+ f.write("Edge _name_obj_link(__obj_link, __objects_name)\n", both=False)
|
|
|
+
|
|
|
+ # Compile all files and add to structure manually
|
|
|
+ for bootstrap_file in bootstrap_files:
|
|
|
+ # Compile the subfile
|
|
|
+ print("[COMP] %s" % bootstrap_file)
|
|
|
+ result = compile_code_AL(bootstrap_file, "initial_IP", prepend=bootstrap_file, is_file=True)
|
|
|
+ f.write(result, both=False)
|
|
|
+ # Now link the code with the compilation manager structure
|
|
|
+ f.write('Node filename("%s")\n' % bootstrap_file, both=False)
|
|
|
+ f.write("Edge _(__objects, %s_initial_IP)\n" % bootstrap_file, both=False)
|
|
|
+ f.write("Edge _(_, filename)\n", both=False)
|
|
|
+
|
|
|
# Create code for initial user
|
|
|
- f.write(compile_code_AL(initial_user_code, "IP_initial"), both=False)
|
|
|
+ print("[BOOT] initial_user")
|
|
|
+ f.write(compile_code_AL(initial_user_code, "initial_IP", prepend="user_manager", main=True), both=False)
|
|
|
f.write('Node _IP_str("IP")\n', both=False)
|
|
|
- f.write("Edge _user_frame(user_frame, IP_initial)\n", both=False)
|
|
|
+ f.write("Edge _user_frame(user_frame, user_manager_initial_IP)\n", both=False)
|
|
|
f.write("Edge __user_frame(_user_frame, _IP_str)\n", both=False)
|
|
|
|
|
|
f.write('Node __phase("init")\n', both=False)
|
|
@@ -288,9 +272,10 @@ def bootstrap():
|
|
|
f.write("Edge __user_phase(_user_phase, __phase_str)\n", both=False)
|
|
|
|
|
|
# Create code for new users to start at
|
|
|
- f.write(compile_code_AL(code_new_users, "IP_new"), both=False)
|
|
|
+ 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, IP_new)\n", both=False)
|
|
|
+ f.write("Edge _user_IP(__hierarchy, new_user_initial_IP)\n", both=False)
|
|
|
f.write("Edge __user_IP(_user_IP, __IP_str)\n", both=False)
|
|
|
except:
|
|
|
os.remove("bootstrap/bootstrap.m")
|