compiler.alc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. String port
  32. port = ""
  33. while (port == ""):
  34. port = comm_connect("compiler")
  35. sleep(0.5)
  36. comm_set(port, "model")
  37. Element list
  38. list = generic_compile(code, port)
  39. if (element_eq(list, read_root())):
  40. return read_root()!
  41. else:
  42. return construct_model_list(instantiate_model(metamodel), list)!