task_manager.alc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. include "io.alh"
  2. include "primitives.alh"
  3. include "metamodels.alh"
  4. include "core_algorithm.alh"
  5. include "random.alh"
  6. Void function task_management():
  7. String taskname
  8. Element task_root
  9. Element task_frame
  10. Element output_value
  11. Element input_value
  12. Boolean gen_output
  13. // Initialize the basic formalisms before allowing new users
  14. initialize_MMs()
  15. initialize_core()
  16. taskname = "task_manager"
  17. while (True):
  18. gen_output = True
  19. while (True):
  20. if (bool_not(other_has_output("task_manager"))):
  21. while (dict_in(read_root(), taskname)):
  22. taskname = cast_string(random_string(20))
  23. break!
  24. elif (has_input()):
  25. taskname = input()
  26. if (dict_in(read_root(), taskname)):
  27. sleep(0.05)
  28. else:
  29. gen_output = False
  30. break!
  31. else:
  32. sleep(0.05)
  33. // Task is gone, so make sure that we create a new one already
  34. task_root = create_node()
  35. task_frame = create_node()
  36. output_value = create_node()
  37. input_value = create_node()
  38. dict_add_fast(task_root, "frame", task_frame)
  39. dict_add_fast(task_root, "globals", create_node())
  40. dict_add_fast(task_root, "output", output_value)
  41. dict_add_fast(task_root, "last_output", output_value)
  42. dict_add_fast(task_root, "input", input_value)
  43. dict_add_fast(task_root, "last_input", input_value)
  44. dict_add_fast(task_frame, "evalstack", create_node())
  45. dict_add_fast(task_frame, "returnvalue", create_node())
  46. dict_add_fast(task_frame, "phase", "init")
  47. dict_add_fast(task_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
  48. dict_add_fast(task_frame, "symbols", create_node())
  49. //Add this only at the end, as otherwise the task will already be detected
  50. dict_add_fast(read_root(), taskname, task_root)
  51. if (gen_output):
  52. output(taskname)
  53. return!