compiler.alc 1.1 KB

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