compiler.alc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. log("ERROR IN CODE COMPILATION")
  28. return read_root()!
  29. else:
  30. return construct_function_list(list)!
  31. Element function compile_model(code : String, metamodel : Element):
  32. String port
  33. port = ""
  34. while (port == ""):
  35. port = comm_connect("compiler")
  36. comm_set(port, "model")
  37. Element list
  38. list = generic_compile(code, port)
  39. if (element_eq(list, read_root())):
  40. log("ERROR in model compile")
  41. return read_root()!
  42. else:
  43. log("Creating model...")
  44. return construct_model_list(instantiate_model(metamodel), list)!