Kaynağa Gözat

Load an AL model at startup to potentially overwrite bootstrap files

Yentl Van Tendeloo 7 yıl önce
ebeveyn
işleme
4c82bdecab
2 değiştirilmiş dosya ile 16 ekleme ve 0 silme
  1. 7 0
      bootstrap/bootstrap.py
  2. 9 0
      bootstrap/core_algorithm.alc

+ 7 - 0
bootstrap/bootstrap.py

@@ -184,6 +184,7 @@ def bootstrap():
                     return model_code + "\n"
 
                 # Compile all model definitions to ALC directly
+                single_file = ""
                 total_alc = []
                 binding_alc = 'Void function initialize_MMs():\n\tinitialize_SCD("models/SimpleClassDiagrams")\n'
 
@@ -208,10 +209,12 @@ def bootstrap():
 
                 # Compile all files and add to structure manually
                 bootstrap_files = sorted(glob.glob("bootstrap/*.alc") + glob.glob("bootstrap/.*.alc"))
+                all_code = ""
                 for bootstrap_file in bootstrap_files:
                     # Compile the subfile
                     bootstrap_file = bootstrap_file.replace("\\", "/")
                     print("[ALC] %s" % bootstrap_file)
+                    all_code += open(bootstrap_file, 'r').read()
                     f.write(compile_code_AL(bootstrap_file, "initial_IP", prepend=bootstrap_file, main=bootstrap_file==main_file), both=False)
 
                     # TODO all assigns stored in:
@@ -219,6 +222,10 @@ def bootstrap():
 
                     # Now link the code with the compilation manager structure
 
+                print("[MERGE]")
+                with open("bootstrap/merged.alm", 'w') as merged:
+                    merged.write(all_code)
+
                 # Stitch all IPs together
                 print("[LINK]")
                 counter = 0

+ 9 - 0
bootstrap/core_algorithm.alc

@@ -2582,6 +2582,15 @@ Void function new_task():
 
 		current_user_id = user_id
 
+		// Load the new core library, thereby overwriting the bootstrapped code
+		String core_model
+		core_model = get_entry_id("models/core_library")
+		if (core_model != ""):
+			// Execute it directly
+			Element func
+			func = get_func_AL_model(get_full_model(core_model, get_entry_id("formalisms/ActionLanguage")))
+			func(read_root())
+
 		output("Welcome to the Model Management Interface v2.0!")
 		output("Use the 'help' command for a list of possible commands")