00_rapid_js.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Tue Aug 09 09:35:54 2016
  3. Model author: Herr Joeri Exelmans
  4. Model name: rapid
  5. Model description:
  6. After event with a very small timeout.*/
  7. // package "rapid"
  8. var rapid = {};
  9. (function() {
  10. var c = function(controller) {
  11. RuntimeClassBase.call(this, controller);
  12. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  13. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  14. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  15. this.semantics.priority = StatechartSemantics.SourceParent;
  16. this.semantics.concurrency = StatechartSemantics.Single;
  17. // build Statechart structure
  18. this.build_statechart_structure();
  19. // user defined attributes
  20. this.i = null;
  21. // call user defined constructor
  22. c.prototype.user_defined_constructor.call(this);
  23. };
  24. c.prototype = new Object();
  25. (function() {
  26. var proto = new RuntimeClassBase();
  27. for (prop in proto) {
  28. c.prototype[prop] = proto[prop];
  29. }
  30. })();
  31. c.prototype.user_defined_constructor = function() {
  32. this.i = 0;
  33. };
  34. c.prototype.user_defined_destructor = function() {
  35. };
  36. // builds Statechart structure
  37. c.prototype.build_statechart_structure = function() {
  38. // state <root>
  39. this.states[""] = new State(0, this);
  40. // state /a
  41. this.states["/a"] = new State(1, this);
  42. this.states["/a"].setEnter(this._a_enter);
  43. this.states["/a"].setExit(this._a_exit);
  44. // add children
  45. this.states[""].addChild(this.states["/a"]);
  46. this.states[""].fixTree();
  47. this.states[""].default_state = this.states["/a"];
  48. // transition /a
  49. var _a_0 = new Transition(this, this.states["/a"], [this.states["/a"]]);
  50. _a_0.setAction(this._a_0_exec);
  51. _a_0.setTrigger(new Event("_0after"));
  52. _a_0.setGuard(this._a_0_guard);
  53. this.states["/a"].addTransition(_a_0);
  54. };
  55. c.prototype._a_enter = function() {
  56. this.addTimer(0, 1e-10);
  57. this.big_step.outputEvent(new Event("entered_a", "out", new Array()));
  58. };
  59. c.prototype._a_exit = function() {
  60. this.removeTimer(0);
  61. };
  62. c.prototype._a_0_exec = function(parameters) {
  63. this.i++;
  64. };
  65. c.prototype._a_0_guard = function(parameters) {
  66. return this.i < 2;
  67. };
  68. c.prototype.initializeStatechart = function() {
  69. // enter default state
  70. this.default_targets = this.states["/a"].getEffectiveTargetStates();
  71. RuntimeClassBase.prototype.initializeStatechart.call(this);
  72. };
  73. // add symbol 'c' to package 'rapid'
  74. rapid.c = c;
  75. var ObjectManager = function(controller) {
  76. ObjectManagerBase.call(this, controller);
  77. };
  78. ObjectManager.prototype = new Object();
  79. (function() {
  80. var proto = new ObjectManagerBase();
  81. for (prop in proto) {
  82. ObjectManager.prototype[prop] = proto[prop];
  83. }
  84. })();
  85. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  86. if (class_name === "c") {
  87. var instance = new c(this.controller);
  88. instance.associations = new Object();
  89. } else {
  90. throw new Error("Cannot instantiate class " + class_name);
  91. }
  92. return instance;
  93. };
  94. // add symbol 'ObjectManager' to package 'rapid'
  95. rapid.ObjectManager = ObjectManager;
  96. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  97. if (finished_callback === undefined) finished_callback = null;
  98. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  99. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  100. this.addInputPort("in");
  101. this.addOutputPort("out");
  102. this.object_manager.createInstance("c", new Array());
  103. };
  104. Controller.prototype = new Object();
  105. (function() {
  106. var proto = new EventLoopControllerBase();
  107. for (prop in proto) {
  108. Controller.prototype[prop] = proto[prop];
  109. }
  110. })();
  111. // add symbol 'Controller' to package 'rapid'
  112. rapid.Controller = Controller;
  113. var InputEvent = function(name, port, parameters, time_offset) {
  114. this.name = name;
  115. this.port = port;
  116. this.parameters = parameters;
  117. this.time_offset = time_offset;
  118. };
  119. // add symbol 'InputEvent' to package 'rapid'
  120. rapid.InputEvent = InputEvent;
  121. var Test = function() {
  122. };
  123. Test.prototype.input_events = new Array();
  124. Test.prototype.expected_events = [[new Event("entered_a", "out", new Array())], [new Event("entered_a", "out", new Array())], [new Event("entered_a", "out", new Array())]];
  125. // add symbol 'Test' to package 'rapid'
  126. rapid.Test = Test;
  127. })();