compiler.alc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. include "primitives.alh"
  2. include "services.alh"
  3. include "constructors.alh"
  4. include "modelling.alh"
  5. Element function generic_compile(code : String, port : String):
  6. comm_set(port, code)
  7. String response
  8. response = comm_get(port)
  9. if (response == "OK"):
  10. Element lst
  11. lst = comm_get_list(port)
  12. comm_close(port)
  13. return lst!
  14. else:
  15. log("Compilation error: " + response)
  16. comm_close(port)
  17. return read_root()!
  18. Element function compile_code(code : String):
  19. String port
  20. port = ""
  21. while (port == ""):
  22. port = comm_connect("compiler")
  23. comm_set(port, "code")
  24. Element list
  25. list = generic_compile(code, port)
  26. if (element_eq(list, read_root())):
  27. return read_root()!
  28. else:
  29. return construct_function_list(list)!
  30. Element function compile_model(code : String, metamodel : Element):
  31. if (code == "__LOCAL__"):
  32. Element list
  33. Integer length
  34. list = list_create()
  35. length = input()
  36. while (list_len(list) < length):
  37. list_append(list, input())
  38. return construct_model_list(instantiate_model(metamodel), list)!
  39. else:
  40. String port
  41. port = ""
  42. while (port == ""):
  43. port = comm_connect("compiler")
  44. sleep(0.5)
  45. comm_set(port, "model")
  46. Element list
  47. list = generic_compile(code, port)
  48. if (element_eq(list, read_root())):
  49. return read_root()!
  50. else:
  51. return construct_model_list(instantiate_model(metamodel), list)!