compiler.alc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. comm_set(port, "model")
  36. Element list
  37. list = generic_compile(code, port)
  38. if (element_eq(list, read_root())):
  39. return read_root()!
  40. else:
  41. return construct_model_list(instantiate_model(metamodel), list)!