compiler.alc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. comm_close(port)
  17. return lst!
  18. else:
  19. log("Compilation error: " + response)
  20. comm_close(port)
  21. return read_root()!
  22. Element function compile_code(code : String):
  23. String port
  24. port = comm_connect("compiler")
  25. comm_set(port, "code")
  26. Element list
  27. list = generic_compile(code, port)
  28. if (element_eq(list, read_root())):
  29. return read_root()!
  30. else:
  31. return construct_function_list(list)!
  32. Element function compile_model(code : String, metamodel : Element):
  33. String 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(metamodel, list)!