compiler.alc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. comm_close(port)
  16. return response!
  17. Element function compile_code(code : String):
  18. String port
  19. port = ""
  20. while (port == ""):
  21. port = comm_connect("compiler")
  22. comm_set(port, "code")
  23. Element list
  24. list = generic_compile(code, port)
  25. if (is_physical_string(list)):
  26. return list!
  27. else:
  28. Element model
  29. model = construct_function_list(list)
  30. dict_add(model, "__text", code)
  31. return model!
  32. Element function compile_model(code : String, metamodel : Element):
  33. String port
  34. port = ""
  35. while (port == ""):
  36. port = comm_connect("compiler")
  37. sleep(0.5)
  38. comm_set(port, "model")
  39. Element list
  40. list = generic_compile(code, port)
  41. if (is_physical_string(list)):
  42. return list!
  43. else:
  44. return construct_model_list(instantiate_model(metamodel), list)!