compilation_manager.alc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. include "primitives.alh"
  2. include "constructors.alh"
  3. Element function compilation_manager():
  4. String operation
  5. String object_name
  6. Element root
  7. Element mv_root
  8. Element node
  9. mv_root = read_root()
  10. if (dict_in(mv_root["__hierarchy"], "objects")):
  11. root = mv_root["__hierarchy"]["objects"]
  12. else:
  13. root = create_node()
  14. dict_add(mv_root["__hierarchy"], "objects", root)
  15. operation = input()
  16. if (operation == "upload"):
  17. object_name = input()
  18. node = create_node()
  19. dict_add(root, object_name, node)
  20. dict_add(node, "hash_md5", input())
  21. if (input()):
  22. dict_add(node, "initializers", construct_top())
  23. else:
  24. dict_add(node, "initializers", deserialize(input()))
  25. Element symbols
  26. symbols = create_node()
  27. dict_add(node, "symbols", symbols)
  28. while (input()):
  29. dict_add(symbols, input(), input())
  30. elif (operation == "remove_obj"):
  31. dict_delete(root, input())
  32. elif (operation == "read_initializers"):
  33. node = root[input()]["initializers"]
  34. output(node)
  35. elif (operation == "check_symbols"):
  36. Element objs
  37. String obj
  38. objs = create_node()
  39. obj = input()
  40. log("Checking symbols")
  41. while (obj != ""):
  42. if (dict_in(root, obj)):
  43. set_add(objs, obj)
  44. log("Will check " + obj)
  45. else:
  46. log("ERROR: couldn't find obj " + obj)
  47. obj = input()
  48. log("Start check!")
  49. output(True)
  50. //output(check_symbols(root, objs))
  51. elif (operation == "is_defined"):
  52. object_name = input()
  53. if (dict_in(root, object_name)):
  54. output(root[object_name]["hash_md5"])
  55. else:
  56. output(create_node())
  57. else:
  58. log("Failed to understand command")
  59. return operation
  60. Boolean function check_symbols(root : Element, objs : Element):
  61. Element symbols
  62. String obj
  63. Element keys
  64. String key
  65. Element copy_objs
  66. // We always need a main variable
  67. symbols = create_node()
  68. dict_add(symbols, "main", False)
  69. // Resolve all symbols
  70. copy_objs = set_copy(objs)
  71. while (0 < list_len(copy_objs)):
  72. obj = set_pop(copy_objs)
  73. keys = dict_keys(root[obj]["symbols"])
  74. while (0 < list_len(keys)):
  75. key = set_pop(keys)
  76. if (root[obj]["symbols"][key]):
  77. // Defines
  78. if (bool_not(dict_in(symbols, key))):
  79. // Not yet in dictionary
  80. dict_add(symbols, key, True)
  81. elif (symbols[key]):
  82. // Already in dictionary, and it was already defined
  83. log("ERROR: multiple definition of symbol " + key)
  84. return False
  85. else:
  86. // Already in dictionary, but only used
  87. dict_delete(symbols, key)
  88. dict_add(symbols, key, True)
  89. else:
  90. // Uses
  91. if (bool_not(dict_in(symbols, key))):
  92. dict_add(symbols, key, False)
  93. // Check whether we have everything
  94. keys = dict_keys(symbols)
  95. while (0 < list_len(keys)):
  96. key = set_pop(keys)
  97. if (bool_not(symbols[key])):
  98. if (bool_not(bool_or(key == "output", key == "input"))):
  99. log("ERROR: undefined symbol " + key)
  100. return False
  101. log("Symbol checking OK")
  102. return True