compiler.alc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. if (code == "__LOCAL__"):
  20. Element list
  21. Integer length
  22. list = list_create()
  23. length = input()
  24. while (list_len(list) < length):
  25. list_append(list, input())
  26. return construct_function_list(list)!
  27. else:
  28. String port
  29. port = ""
  30. while (port == ""):
  31. port = comm_connect("compiler")
  32. comm_set(port, "code")
  33. Element list
  34. list = generic_compile(code, port)
  35. if (element_eq(list, read_root())):
  36. return read_root()!
  37. else:
  38. return construct_function_list(list)!
  39. Element function compile_model(code : String, metamodel : Element):
  40. if (code == "__LOCAL__"):
  41. Element list
  42. Integer length
  43. list = list_create()
  44. length = input()
  45. while (list_len(list) < length):
  46. list_append(list, input())
  47. return construct_model_list(instantiate_model(metamodel), list)!
  48. else:
  49. String port
  50. port = ""
  51. while (port == ""):
  52. port = comm_connect("compiler")
  53. sleep(0.5)
  54. comm_set(port, "model")
  55. Element list
  56. list = generic_compile(code, port)
  57. if (element_eq(list, read_root())):
  58. return read_root()!
  59. else:
  60. return construct_model_list(instantiate_model(metamodel), list)!