123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- include "primitives.alh"
- include "constructors.alh"
- Element function read_symbols(root : Element, object_name : String):
- Element keys
- Element node
- String rv
- String key
- node = root[object_name]["symbols"]
- keys = dict_keys(node)
- rv = ""
- while (0 < read_nr_out(keys)):
- key = set_pop(keys)
- if (node[key]):
- rv = (rv + key) + ":1\n"
- else:
- rv = (rv + key) + ":0\n"
- return rv
- Element function compilation_manager():
- String operation
- String object_name
- Element root
- Element mv_root
- Element node
- mv_root = read_root()
- if (dict_in(mv_root["__hierarchy"], "objects")):
- root = mv_root["__hierarchy"]["objects"]
- else:
- root = create_node()
- dict_add(mv_root["__hierarchy"], "objects", root)
- operation = input()
- if (operation == "upload"):
- object_name = input()
- node = create_node()
- dict_add(root, object_name, node)
- dict_add(node, "hash_md5", input())
- if (input()):
- dict_add(node, "initializers", construct_top())
- else:
- dict_add(node, "initializers", deserialize(input()))
- Element symbols
- symbols = create_node()
- dict_add(node, "symbols", symbols)
- while (input()):
- dict_add(symbols, input(), input())
- elif (operation == "remove_obj"):
- dict_delete(root, input())
- elif (operation == "read_symbols"):
- output(read_symbols(root, input()))
- elif (operation == "read_initializers"):
- node = root[input()]["initializers"]
- output(node)
- elif (operation == "check_symbols"):
- Element objs
- String obj
- objs = create_node()
- obj = input()
- log("Checking symbols")
- 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(check_symbols(root, objs))
- elif (operation == "is_defined"):
- object_name = input()
- if (dict_in(root, object_name)):
- output(root[object_name]["hash_md5"])
- else:
- output(create_node())
- else:
- log("Failed to understand command")
- return operation
- Boolean function check_symbols(root : Element, objs : Element):
- Element symbols
- String obj
- Element keys
- String key
- Element copy_objs
- // We always need a main variable
- symbols = create_node()
- dict_add(symbols, "main", False)
- // Resolve all symbols
- copy_objs = set_copy(objs)
- while (0 < list_len(copy_objs)):
- obj = set_pop(copy_objs)
- log("CHECK " + obj)
- keys = dict_keys(root[obj]["symbols"])
- while (0 < list_len(keys)):
- key = set_pop(keys)
- if (root[obj]["symbols"][key]):
- log(" SYMB " + key)
- // Defines
- if (bool_not(dict_in(symbols, key))):
- // Not yet in dictionary
- dict_add(symbols, key, True)
- elif (symbols[key]):
- // Already in dictionary, and it was already defined
- log("ERROR: multiple definition of symbol " + key)
- return False
- else:
- // Already in dictionary, but only used
- dict_delete(symbols, key)
- dict_add(symbols, key, True)
- else:
- // Uses
- if (bool_not(dict_in(symbols, key))):
- dict_add(symbols, key, False)
- // Check whether we have everything
- keys = dict_keys(symbols)
- while (0 < list_len(keys)):
- key = set_pop(keys)
- if (bool_not(symbols[key])):
- if (bool_not(bool_or(key == "output", key == "input"))):
- log(cast_e2s(symbols[key]))
- log("ERROR: undefined symbol " + key)
- return False
- log("Symbol checking OK")
- return True
|