compiler.alc 996 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 = comm_connect("compiler")
  21. comm_set(port, "code")
  22. Element list
  23. list = generic_compile(code, port)
  24. if (element_eq(list, read_root())):
  25. return read_root()!
  26. else:
  27. return construct_function_list(list)!
  28. Element function compile_model(code : String, model : Element):
  29. String port
  30. port = comm_connect("compiler")
  31. comm_set(port, "model")
  32. Element list
  33. list = generic_compile(code, port)
  34. if (element_eq(list, read_root())):
  35. return read_root()!
  36. else:
  37. return construct_model_list(model, list)!