compilation_manager.alc 3.3 KB

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