|
@@ -56,6 +56,23 @@ Element function compilation_manager():
|
|
|
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)):
|
|
@@ -65,3 +82,55 @@ Element function compilation_manager():
|
|
|
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
|