00_rapid_js.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Mon Aug 08 09:49:21 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. var states = this.states["/a"].getEffectiveTargetStates();
  71. this.updateConfiguration(states);
  72. for (var state_idx in states) {
  73. if (!states.hasOwnProperty(state_idx)) continue;
  74. var state = states[state_idx]
  75. if (state.enter) {
  76. state.enter();
  77. }
  78. }
  79. };
  80. // add symbol 'c' to package 'rapid'
  81. rapid.c = c;
  82. var ObjectManager = function(controller) {
  83. ObjectManagerBase.call(this, controller);
  84. };
  85. ObjectManager.prototype = new Object();
  86. (function() {
  87. var proto = new ObjectManagerBase();
  88. for (prop in proto) {
  89. ObjectManager.prototype[prop] = proto[prop];
  90. }
  91. })();
  92. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  93. if (class_name === "c") {
  94. var instance = new c(this.controller);
  95. instance.associations = new Object();
  96. } else {
  97. throw new Error("Cannot instantiate class " + class_name);
  98. }
  99. return instance;
  100. };
  101. // add symbol 'ObjectManager' to package 'rapid'
  102. rapid.ObjectManager = ObjectManager;
  103. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  104. if (finished_callback === undefined) finished_callback = null;
  105. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  106. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  107. this.addInputPort("in");
  108. this.addOutputPort("out");
  109. this.object_manager.createInstance("c", new Array());
  110. };
  111. Controller.prototype = new Object();
  112. (function() {
  113. var proto = new EventLoopControllerBase();
  114. for (prop in proto) {
  115. Controller.prototype[prop] = proto[prop];
  116. }
  117. })();
  118. // add symbol 'Controller' to package 'rapid'
  119. rapid.Controller = Controller;
  120. var InputEvent = function(name, port, parameters, time_offset) {
  121. this.name = name;
  122. this.port = port;
  123. this.parameters = parameters;
  124. this.time_offset = time_offset;
  125. };
  126. // add symbol 'InputEvent' to package 'rapid'
  127. rapid.InputEvent = InputEvent;
  128. var Test = function() {
  129. };
  130. Test.prototype.input_events = new Array();
  131. 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())]];
  132. // add symbol 'Test' to package 'rapid'
  133. rapid.Test = Test;
  134. })();