Browse Source

Explicitly modelled linking process

Yentl Van Tendeloo 9 years ago
parent
commit
fc5bd6b534
2 changed files with 23 additions and 59 deletions
  1. 22 6
      bootstrap/compilation_manager.alc
  2. 1 53
      interface/HUTN/hutn_compiler/linker.py

+ 22 - 6
bootstrap/compilation_manager.alc

@@ -37,24 +37,22 @@ Element function compilation_manager():
 	elif (operation == "read_initializers"):
 		node = root[input()]["initializers"]
 		output(node)
-	elif (operation == "check_symbols"):
+	elif (operation == "link_and_load"):
 		Element objs
 		String obj
 
 		objs = create_node()
 		obj = input()
-		log("Checking symbols")
+		log("linking and loading")
 		while (obj != ""):
 			if (dict_in(root, obj)):
 				set_add(objs, obj)
-				log("Will check " + obj)
 			else:
 				log("ERROR: couldn't find obj " + obj)
 			obj = input()
 
-		log("Start check!")
-		output(True)
-		//output(check_symbols(root, objs))
+		log("Start link and load!")
+		link_and_load(root, objs)
 	elif (operation == "is_defined"):
 		object_name = input()
 		if (dict_in(root, object_name)):
@@ -113,3 +111,21 @@ Boolean function check_symbols(root : Element, objs : Element):
 
 	log("Symbol checking OK")
 	return True
+
+Void function link_and_load(root : Element, objs : Element):
+	String obj
+	Element func
+
+	if (check_symbols(root, objs)):
+		output(True)
+		log("Linking")
+		while (0 < list_len(objs)):
+			obj = set_pop(objs)
+			func = root[obj]["initializers"]
+			exec(func)
+
+		log("Loading")
+		main()
+	else:
+		output(False)
+	return

+ 1 - 53
interface/HUTN/hutn_compiler/linker.py

@@ -15,7 +15,7 @@ def link(address, username, objects):
     data = []
 
     data.append(("V", '3'))
-    data.append(("V", '"check_symbols"'))
+    data.append(("V", '"link_and_load"'))
     for obj in objects:
         data.append(("V", '"%s"' % obj))
     data.append(("V", '""'))
@@ -25,58 +25,6 @@ def link(address, username, objects):
     if "False" in v:
         raise Exception("Linking error")
 
-    # Ok, we know that all symbols can be defined with this set of files, now link their initializers together
-    initializers = []
-    for obj in objects:
-        data.append(("V", '3'))
-        data.append(("V", '"read_initializers"'))
-        data.append(("V", '"%s"' % obj))
-
-    data = flush_data(address, data, username)
-
-    for obj in objects:
-        print("[LINK] %s" % (obj))
-        v = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read()
-        start = str(v.split("&", 1)[0].split("=")[1])
-        initializers.append(start)
-
-    # Bind all initializers together
-    if definers:
-        print("[LOAD] %s:main()" % definers["main"])
-    else:
-        print("[LOAD] main()")
-
-    # Set interface to constructors
-    commands = [("V", '1')]
-
-    # Link all initializers together
-    for init in initializers:
-        commands.extend([
-                ("V", '"call"'),
-                    ("V", '"access"'),
-                        ("V", '"resolve"'),
-                            ("V", '"exec"'),
-                    ("V", '1'),
-                    ("V", '"const"'),
-                        ("R", str(init)),
-                    ("V", 'true'),
-            ])
-
-    # Load main function
-    commands.extend([
-                ("V", '"return"'),
-                    ("V", 'true'),
-                    ("V", '"call"'),
-                        ("V", '"access"'),
-                            ("V", '"resolve"'),
-                                ("V", '"main"'),
-                        ("V", '0'),
-                        ("V", 'false'),
-            ])
-
-    import json
-    urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(commands), "username": username}))).read()
-
 if __name__ == "__main__":
     if len(sys.argv) == 1:
         print("No username defined")