compiler.alc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. log("Got response: " + response)
  10. if (response == "OK"):
  11. Integer count
  12. Element lst
  13. lst = list_create()
  14. count = comm_get(port)
  15. while (count > 0):
  16. list_append(lst, comm_get(port))
  17. count = count - 1
  18. comm_close(port)
  19. return lst!
  20. else:
  21. log("Compilation error: " + response)
  22. comm_close(port)
  23. return read_root()!
  24. Element function compile_code(code : String):
  25. String port
  26. port = comm_connect("compiler")
  27. comm_set(port, "code")
  28. Element list
  29. list = generic_compile(code, port)
  30. if (element_eq(list, read_root())):
  31. return read_root()!
  32. else:
  33. log("Compiling: " + list_to_string(list))
  34. return construct_function_list(list)!
  35. Element function compile_model(code : String, metamodel : Element):
  36. String port
  37. port = comm_connect("compiler")
  38. comm_set(port, "model")
  39. Element list
  40. list = generic_compile(code, port)
  41. if (element_eq(list, read_root())):
  42. return read_root()!
  43. else:
  44. log("Compiling: " + list_to_string(list))
  45. return construct_model_list(metamodel, list)!