nodeskini 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/README.md +31 -0
  2. package/client/archive/bundle.js +11528 -0
  3. package/client/archive/golem.html +60 -0
  4. package/client/archive/golemClient.js +595 -0
  5. package/client/archive/golembundle.js +11634 -0
  6. package/client/archive/sequencer.html +43 -0
  7. package/client/archive/sequenceurClient.js +815 -0
  8. package/client/archive/stylegolem.css +158 -0
  9. package/client/archive/stylesequenceur.css +204 -0
  10. package/client/clientListe/Sortable-master/.circleci/config.yml +33 -0
  11. package/client/clientListe/Sortable-master/.editorconfig +15 -0
  12. package/client/clientListe/Sortable-master/.github/ISSUE_TEMPLATE/bug-report.md +73 -0
  13. package/client/clientListe/Sortable-master/.github/ISSUE_TEMPLATE/custom-template.md +48 -0
  14. package/client/clientListe/Sortable-master/.github/ISSUE_TEMPLATE/feature-request.md +41 -0
  15. package/client/clientListe/Sortable-master/.jshintrc +25 -0
  16. package/client/clientListe/Sortable-master/.testcaferc.json +7 -0
  17. package/client/clientListe/Sortable-master/CONTRIBUTING.md +26 -0
  18. package/client/clientListe/Sortable-master/LICENSE +21 -0
  19. package/client/clientListe/Sortable-master/README.md +813 -0
  20. package/client/clientListe/Sortable-master/Sortable.js +3709 -0
  21. package/client/clientListe/Sortable-master/Sortable.min.js +2 -0
  22. package/client/clientListe/Sortable-master/Sortable.min.old.js +2 -0
  23. package/client/clientListe/Sortable-master/Sortable.min.old.old.js +2 -0
  24. package/client/clientListe/Sortable-master/babel.config.js +27 -0
  25. package/client/clientListe/Sortable-master/bower.json +30 -0
  26. package/client/clientListe/Sortable-master/entry/entry-complete.js +8 -0
  27. package/client/clientListe/Sortable-master/entry/entry-core.js +19 -0
  28. package/client/clientListe/Sortable-master/entry/entry-defaults.js +19 -0
  29. package/client/clientListe/Sortable-master/index.html +460 -0
  30. package/client/clientListe/Sortable-master/modular/sortable.complete.esm.js +3701 -0
  31. package/client/clientListe/Sortable-master/modular/sortable.core.esm.js +3698 -0
  32. package/client/clientListe/Sortable-master/modular/sortable.esm.js +3699 -0
  33. package/client/clientListe/Sortable-master/package-lock.json +5704 -0
  34. package/client/clientListe/Sortable-master/package.json +56 -0
  35. package/client/clientListe/Sortable-master/plugins/AutoScroll/AutoScroll.js +270 -0
  36. package/client/clientListe/Sortable-master/plugins/AutoScroll/README.md +80 -0
  37. package/client/clientListe/Sortable-master/plugins/AutoScroll/index.js +1 -0
  38. package/client/clientListe/Sortable-master/plugins/MultiDrag/MultiDrag.js +617 -0
  39. package/client/clientListe/Sortable-master/plugins/MultiDrag/README.md +96 -0
  40. package/client/clientListe/Sortable-master/plugins/MultiDrag/index.js +1 -0
  41. package/client/clientListe/Sortable-master/plugins/OnSpill/OnSpill.js +79 -0
  42. package/client/clientListe/Sortable-master/plugins/OnSpill/README.md +60 -0
  43. package/client/clientListe/Sortable-master/plugins/OnSpill/index.js +1 -0
  44. package/client/clientListe/Sortable-master/plugins/README.md +178 -0
  45. package/client/clientListe/Sortable-master/plugins/Swap/README.md +55 -0
  46. package/client/clientListe/Sortable-master/plugins/Swap/Swap.js +90 -0
  47. package/client/clientListe/Sortable-master/plugins/Swap/index.js +1 -0
  48. package/client/clientListe/Sortable-master/scripts/banner.js +8 -0
  49. package/client/clientListe/Sortable-master/scripts/build.js +17 -0
  50. package/client/clientListe/Sortable-master/scripts/esm-build.js +28 -0
  51. package/client/clientListe/Sortable-master/scripts/minify.js +11 -0
  52. package/client/clientListe/Sortable-master/scripts/test-compat.js +30 -0
  53. package/client/clientListe/Sortable-master/scripts/test.js +21 -0
  54. package/client/clientListe/Sortable-master/scripts/umd-build.js +15 -0
  55. package/client/clientListe/Sortable-master/src/Animation.js +175 -0
  56. package/client/clientListe/Sortable-master/src/BrowserInfo.js +12 -0
  57. package/client/clientListe/Sortable-master/src/EventDispatcher.js +57 -0
  58. package/client/clientListe/Sortable-master/src/PluginManager.js +87 -0
  59. package/client/clientListe/Sortable-master/src/Sortable.js +1971 -0
  60. package/client/clientListe/Sortable-master/src/utils.js +556 -0
  61. package/client/clientListe/Sortable-master/st/app.js +224 -0
  62. package/client/clientListe/Sortable-master/st/iframe/frame.html +32 -0
  63. package/client/clientListe/Sortable-master/st/iframe/index.html +49 -0
  64. package/client/clientListe/Sortable-master/st/logo.png +0 -0
  65. package/client/clientListe/Sortable-master/st/og-image.png +0 -0
  66. package/client/clientListe/Sortable-master/st/prettify/prettify.css +1 -0
  67. package/client/clientListe/Sortable-master/st/prettify/prettify.js +46 -0
  68. package/client/clientListe/Sortable-master/st/prettify/run_prettify.js +64 -0
  69. package/client/clientListe/Sortable-master/st/saucelabs.svg +1 -0
  70. package/client/clientListe/Sortable-master/st/theme.css +254 -0
  71. package/client/clientListe/Sortable-master/tests/Sortable.compat.test.js +39 -0
  72. package/client/clientListe/Sortable-master/tests/Sortable.test.js +386 -0
  73. package/client/clientListe/Sortable-master/tests/dual-list.html +34 -0
  74. package/client/clientListe/Sortable-master/tests/empty-list.html +30 -0
  75. package/client/clientListe/Sortable-master/tests/filter.html +27 -0
  76. package/client/clientListe/Sortable-master/tests/handles.html +27 -0
  77. package/client/clientListe/Sortable-master/tests/nested.html +67 -0
  78. package/client/clientListe/Sortable-master/tests/single-list.html +25 -0
  79. package/client/clientListe/Sortable-master/tests/style.css +18 -0
  80. package/client/clientListe/clientListe.html +148 -0
  81. package/client/clientListe/clientListe.js +1508 -0
  82. package/client/clientListe/clientListebundle.js +13164 -0
  83. package/client/clientListe/images/poubelle.png +0 -0
  84. package/client/clientListe/images/start.png +0 -0
  85. package/client/clientListe/images/stop.png +0 -0
  86. package/client/clientListe/images/submit.png +0 -0
  87. package/client/clientListe/sortable-theme-bootstrap.css +90 -0
  88. package/client/configurateur/configReact.js +273 -0
  89. package/client/configurateur/configReactbundle.js +295 -0
  90. package/client/configurateur/configurateur.css +95 -0
  91. package/client/configurateur/configurateur.html +48 -0
  92. package/client/configurateur/lib/jexcel.css +755 -0
  93. package/client/configurateur/lib/jexcel.js +14970 -0
  94. package/client/configurateur/lib/jsuites.css +2801 -0
  95. package/client/configurateur/lib/jsuites.js +11822 -0
  96. package/client/configurateur/lib/react-dom.production.min.js +239 -0
  97. package/client/configurateur/lib/react.production.min.js +32 -0
  98. package/client/configurateur/src/configReact.js +247 -0
  99. package/client/controleur/clientcontroleur.js +536 -0
  100. package/client/controleur/clientcontroleur.test.js +282 -0
  101. package/client/controleur/controleur.html +51 -0
  102. package/client/controleur/controleurbundle.js +565 -0
  103. package/client/controleur/stylecontroleur.css +236 -0
  104. package/client/controleurHH/controleurHH.html +71 -0
  105. package/client/controleurHH/controleurHH.js +252 -0
  106. package/client/controleurHH/styles/index.css +320 -0
  107. package/client/controleurHH/styles/material.css +11552 -0
  108. package/client/parametrage/paramReact.js +473 -0
  109. package/client/parametrage/paramReactbundle.js +500 -0
  110. package/client/parametrage/parametrage.css +111 -0
  111. package/client/parametrage/parametrage.html +163 -0
  112. package/client/parametrage/src/paramReact.js +459 -0
  113. package/client/score/hash.js +83 -0
  114. package/client/score/p5.min.js +3 -0
  115. package/client/score/parto1.js +1171 -0
  116. package/client/score/parto1bundle.js +1181 -0
  117. package/client/score/processing.min.js +431 -0
  118. package/client/score/score.html +15 -0
  119. package/client/score/score.js +34 -0
  120. package/client/simulateurListe/simulateurFork.js +750 -0
  121. package/client/simulateurListe/simulateurFork.mjs +681 -0
  122. package/client/simulateurListe/simulateurForkSansReorg.js +569 -0
  123. package/client/simulateurListe/simulateurListe.js +628 -0
  124. package/myReact/archive/Nodeemitvaluedlocal1.hh.js +52 -0
  125. package/myReact/archive/abort-parNode.js +79 -0
  126. package/myReact/archive/abroNode.js +169 -0
  127. package/myReact/archive/abroNode2.js +80 -0
  128. package/myReact/archive/atom.compile.hh.js +51 -0
  129. package/myReact/archive/await-countNode.js +67 -0
  130. package/myReact/archive/await-nowvalNode.js +44 -0
  131. package/myReact/archive/callHH.js +96 -0
  132. package/myReact/archive/emit-if2.hh.compiled.js +113 -0
  133. package/myReact/archive/every1Node.js +35 -0
  134. package/myReact/archive/if-runNode.js +74 -0
  135. package/myReact/archive/if1Node.js +43 -0
  136. package/myReact/archive/makeawait.js +0 -0
  137. package/myReact/archive/myReact.old.js +684 -0
  138. package/myReact/archive/orchestration.js +281 -0
  139. package/myReact/archive/orchestration1.js +132 -0
  140. package/myReact/archive/orchestration1.xml +465 -0
  141. package/myReact/archive/orchestration2.js +161 -0
  142. package/myReact/archive/orchestrationHH.mano.js +280 -0
  143. package/myReact/archive/orchestrationHHTest.js +428 -0
  144. package/myReact/archive/orchestrationHHTest.xml +234 -0
  145. package/myReact/archive/orchestrationHHTestRun.js +104 -0
  146. package/myReact/archive/orchestrationHHTestRun.xml +34 -0
  147. package/myReact/archive/orchestrationTest0.js +178 -0
  148. package/myReact/archive/orchestrationTest1.js +181 -0
  149. package/myReact/archive/orchestrationTest2.js +281 -0
  150. package/myReact/archive/run3pointsNode.js +59 -0
  151. package/myReact/archive/runNode.js +123 -0
  152. package/myReact/archive/runNode2.js +91 -0
  153. package/myReact/archive/testAwait1.js +141 -0
  154. package/myReact/archive/testAwait1.xml +86 -0
  155. package/myReact/archive/testEvery1.js +122 -0
  156. package/myReact/archive/testEvery1.xml +79 -0
  157. package/myReact/archive/testHH1.js +135 -0
  158. package/myReact/archive/testHH1.xml +86 -0
  159. package/myReact/archive/testHH1revu.js +104 -0
  160. package/myReact/archive/testHH2.js +122 -0
  161. package/myReact/archive/testHH2.xml +79 -0
  162. package/myReact/archive/testHH3.js +130 -0
  163. package/myReact/archive/testHH3.xml +86 -0
  164. package/myReact/archive/testHHabort.js +121 -0
  165. package/myReact/archive/testHHabort.xml +83 -0
  166. package/myReact/archive/testMakeawait.js +202 -0
  167. package/myReact/archive/testRun1.js +168 -0
  168. package/myReact/archive/testRun1.xml +142 -0
  169. package/myReact/archive/titi.js +28 -0
  170. package/myReact/archive/titi.xml +110 -0
  171. package/myReact/archive/toto.js +73 -0
  172. package/myReact/archive/toto.xml +198 -0
  173. package/myReact/archive/trap-await-parallelNode.js +123 -0
  174. package/myReact/inutiles/hiver2022.xml +804 -0
  175. package/myReact/inutiles/hopeNode.xml +459 -0
  176. package/myReact/inutiles/mars2022.xml +871 -0
  177. package/myReact/inutiles/mystique1.xml +318 -0
  178. package/myReact/inutiles/mystiqueOSC.xml +277 -0
  179. package/myReact/inutiles/opus5Node.xml +1271 -0
  180. package/myReact/inutiles/opus5NodeLinux.xml +1241 -0
  181. package/myReact/inutiles/orchestrationHH.xml +541 -0
  182. package/myReact/inutiles/orchestrationHH2.xml +547 -0
  183. package/myReact/inutiles/testHH.xml +95 -0
  184. package/myReact/inutiles/trouveLaPercuTenor.xml +349 -0
  185. package/myReact/myReact.js +744 -0
  186. package/myReact/myReact.min.js +1 -0
  187. package/myReact/orchestrationHH.js +311 -0
  188. package/myReact/orchestrationHH.mjs +436 -0
  189. package/myReact/orchestrationHH.mjs.map +1 -0
  190. package/package.json +46 -0
  191. package/serveur/OSCandMidi.mjs +361 -0
  192. package/serveur/computeScore.mjs +415 -0
  193. package/serveur/controleDAW.mjs +1149 -0
  194. package/serveur/defaultSession.csv +2 -0
  195. package/serveur/defaultSkiniParametres.js +119 -0
  196. package/serveur/gameOSC.mjs +96 -0
  197. package/serveur/groupeClientsSons.mjs +1014 -0
  198. package/serveur/ipConfig.json +24 -0
  199. package/serveur/ipConfig127.json +19 -0
  200. package/serveur/ipConfig75.json +17 -0
  201. package/serveur/ipConfigBH.json +19 -0
  202. package/serveur/ipConfigLocal.json +19 -0
  203. package/serveur/midiConfig.json +26 -0
  204. package/serveur/midiConfigBH.json +26 -0
  205. package/serveur/midiConfigVoid.json +3 -0
  206. package/serveur/midimix.mjs +570 -0
  207. package/serveur/saveParam.mjs +159 -0
  208. package/serveur/skiniParametres.good.js +132 -0
  209. package/serveur/skiniParametres.js +106 -0
  210. package/serveur/utilsHHSkini.hh.js +64 -0
  211. package/serveur/utilsSkini.mjs +137 -0
  212. package/serveur/websocketServer.mjs +2052 -0
  213. package/serveur/workerInterfaceZ.mjs +327 -0
  214. package/serveur/workerSynchro.mjs +49 -0
  215. package/skini.mjs +141 -0
@@ -0,0 +1,744 @@
1
+ "use strict"
2
+
3
+ /*------------------------------------------------------------------------------
4
+ 3052021-1
5
+
6
+ myReact.js
7
+
8
+ Début : 14/4/2021
9
+
10
+ Il s'agit de simuler (mimer) quelques fonctions de bases de la programmation
11
+ réactive utiles pour Skini.
12
+ Il ne s'agit pas d'un compilateur Estérel ni HipHop (loin de là).
13
+
14
+ On utilise la notion de signal et la notion de réaction.
15
+
16
+ Un programme ou une branche de programme sont des tableaux d'objets 'instructions'
17
+ qui sont exécutées en séquence.
18
+ Une 'instruction' peut inclure
19
+ d'autres branches d'instructions comme par, seq ou abort.
20
+
21
+ L'exécution du programme consiste à dérouler les branches.
22
+ Le principe de base est qu'une instruction qui a été exécutée
23
+ ne l'est plus par la suite si on ne la réactive pas.
24
+
25
+ Les commandes réactives sont:
26
+ -----------------------------
27
+ await_do: d'un signal et de son décompte
28
+ await: d'un signal et de son décompte
29
+ atom: execution d'une fonction
30
+ emit: pour l'émission d'un signal dans le programme
31
+ seq: pour une branche à jouer en séquence
32
+ par: pour une branche dont les sous branches se jouent en parallèle, !! l'ordre dans 'par' joue.
33
+ every: pour une branche qui est joué à chaque occurence d'un signal
34
+ abort: pour tuer une branche à l'occurence d'un signal
35
+ loop: boucle
36
+ run: en fait comme seq
37
+
38
+ En intégration de la réaction dans un programme JavaScript:
39
+ -----------------------------
40
+ addEventListener: sur emit
41
+ activateSignal: avant l'appel d'une réaction
42
+
43
+ A faire:
44
+ --------
45
+ sustain
46
+ suspend
47
+
48
+ Ce qu'il n'y a pas:
49
+ -------------------
50
+ -> trap: La difficulté de trap est la mise en place de l'exit du trap. A réfléchir.
51
+ Nous n'avons pas la finesse d'Estérel sur la gestion des signaux. trap et abort seraient
52
+ sans doute équivalents ici.
53
+
54
+ -> nowval, preval : les signaux sont des paramètres des instructions.
55
+ Il n'existe pas de façon globale. La notion de signal globale existe (objet signal)
56
+ pour créer un lien d'un signal vers une action pour les eventListeners.
57
+ On a donc une même action pour plusieurs signaux de même nom qui sont associés
58
+ à des instructions. On pourrait traiter des valeurs au niveau global,
59
+ il faut être prudent sur l'impact et la confusion que ça peut créer avec
60
+ les signaux associés aux instructions. nowval de quoi ? de l'objet signal global ou
61
+ du signal présent dans l'instruction ?
62
+ S'il s'agit uniquement de valeurs pour des tests les objets "signal" devrait être suffisants.
63
+
64
+ -> Opérations logique sur les signaux, faisable si nowal, mais est-ce utile pour Skini ?
65
+
66
+ de deteriminisme, de détection de cycle de causalité.
67
+
68
+ --------------------------------------------------------------------------------*/
69
+ // signals est utilisé pour les addEventListeners,
70
+ // les véritables signaux sont locaux aux instructions
71
+ var signals = [];
72
+ var instrIndex = 0;
73
+
74
+ var debug = false;
75
+ var debug1 = true;
76
+ var program;
77
+
78
+ /*============================================================
79
+ *
80
+ * Les objets signaux pour les listeneres et les emits
81
+ * ainsi que leurs traitements
82
+ *
83
+ =============================================================*/
84
+
85
+ // La décalaration des signaux ne sert que
86
+ // pour les actions de playEventListener
87
+ // utlisées par emit.
88
+ function createSignal( sig, val ){
89
+ var oneSignal = {
90
+ name: sig,
91
+ activated: false,
92
+ value: val,
93
+ action: undefined,
94
+ }
95
+ signals.push(oneSignal);
96
+ }
97
+ exports.createSignal =createSignal;
98
+
99
+ function addEventListener(sig , action) {
100
+ for(var i=0; i < signals.length; i++){
101
+ if (signals[i].name === sig ){
102
+ signals[i].action = action;
103
+ return true;
104
+ }
105
+ }
106
+ console.log("ERR: addEventListener: signal inconnu:", sig);
107
+ return -1;
108
+ }
109
+ exports.addEventListener = addEventListener;
110
+
111
+ function playEventListener(sig, val) {
112
+ for(var i=0; i < signals.length; i++){
113
+ if(signals[i].name === sig){
114
+ if (signals[i].action !== undefined){
115
+ signals[i].action(val);
116
+ return true;
117
+ }else{
118
+ return true;
119
+ }
120
+ }
121
+ }
122
+ console.log("ERR: playEventListener: signal inconnu:", sig, val);
123
+ return -1;
124
+ }
125
+ exports.playEventListener = playEventListener;
126
+
127
+ // Pour mis à jour de la valeur dans le tableau signals
128
+ // Pas utile pour le moment avec le playEventListener ci-dessus qui
129
+ // prend la valeur en paramètre. Mais pourra être utile pour des test sur des
130
+ // valeur de signaux.
131
+ function setSignalValue(val){
132
+ for(var i=0; i < signals.length; i++){
133
+ if(signals[i].name === sig){
134
+ signals[i].value = val;
135
+ return true;
136
+ }
137
+ }
138
+ console.log("ERR: setSignalValue: signal inconnu:", sig);
139
+ return -1;
140
+ }
141
+ exports.setSignalValue = setSignalValue;
142
+
143
+ function getSignalValue(val){
144
+ for(var i=0; i < signals.length; i++){
145
+ if(signals[i].name === sig){
146
+ return signals[i].value;
147
+ }
148
+ }
149
+ console.log("ERR: getSignalValue: signal inconnu:", sig);
150
+ return -1;
151
+ }
152
+ exports.getSignalValue = getSignalValue;
153
+
154
+ function isSignalActivated(sig){
155
+ for(var i=0; i < signals.length; i++){
156
+ if(signals[i].name === sig){
157
+ return signals[i].activated;
158
+ }
159
+ }
160
+ console.log("ERR: isSignalActivated: signal inconnu:", sig);
161
+ return -1;
162
+ }
163
+
164
+ function setSignalActivated(sig, val){
165
+ for(var i=0; i < signals.length; i++){
166
+ if(signals[i].name === sig){
167
+ signals[i].activated = val;
168
+ return true;
169
+ }
170
+ }
171
+ console.log("ERR: setSignalValue: signal inconnu:", sig);
172
+ return -1;
173
+ }
174
+
175
+ /*============================================================
176
+ *
177
+ * Les objets signaux dans les commandes et leurs traitements
178
+ *
179
+ =============================================================*/
180
+
181
+ function isSignalActivatedInInstruction(instr, signal){
182
+ if(instr.signal === signal){
183
+ if(instr.signalActivated) return true;
184
+ }
185
+ return false;
186
+ }
187
+
188
+ // Quand on active un signal c'est pour tout le programme
189
+ // idée de broadcast
190
+ function activateSignal(sig){
191
+ if(debug) console.log("activateSignal", sig);
192
+ setSignalAll(program, sig, true);
193
+ return true;
194
+ }
195
+ exports.activateSignal = activateSignal;
196
+
197
+ function setSignal(instr, sig, activated){
198
+ if(instr === undefined) return;
199
+
200
+ for(var i=0; i < instr.length; i++){
201
+ if(instr[i].signal === sig){
202
+ instr[i].signalActivated = activated;
203
+ //return;
204
+ }
205
+ if(debug) console.log("-- setSignal", instr[i].name,
206
+ instr[i].signal, instr[i].signalActivated);
207
+
208
+ setSignal(instr[i].nextInstr, sig, activated);
209
+ }
210
+ }
211
+
212
+ function setSignalAll(prog, sig, activated){
213
+ if(debug) console.log("- setSignalAll");
214
+ setSignal(prog.instructions, sig, activated);
215
+ }
216
+ exports.setSignalAll = setSignalAll;
217
+
218
+ function resetSignal(instr){
219
+ if(debug) console.log("-- resetSignal: ", instr);
220
+
221
+ if(instr === undefined) return;
222
+
223
+ for(var i=0; i < instr.length; i++){
224
+ instr[i].signalActivated = false;
225
+
226
+ if(debug) console.log("-- resetSignal", instr[i].name,
227
+ instr[i].signal, instr[i].signalActivated);
228
+
229
+ resetSignal(instr[i].nextInstr);
230
+ }
231
+ }
232
+ exports.resetSignal = resetSignal;
233
+
234
+ function resetSignalAll(prog){
235
+ if(debug) console.log("- resetSignalAll :", prog);
236
+ resetSignal(prog);
237
+ }
238
+ exports.resetSignalAll = resetSignalAll;
239
+
240
+ /*============================================================
241
+ *
242
+ * Gestion des instructions du programme
243
+ * Un programme est un arbre d'objets instructions
244
+ *
245
+ =============================================================*/
246
+
247
+ function createInstruction(name, signal, nowval, count, action, nextInstr){
248
+ var instruction = {
249
+ name: name,
250
+ signal: signal,
251
+ signalActivated: false,
252
+ nowval: nowval,
253
+ count: 0,
254
+ countMax: count,
255
+ action: action,
256
+ burnt: false,
257
+ broadcast: false,
258
+ nextInstr: nextInstr,
259
+ index: instrIndex,
260
+ branchStarted: false
261
+ };
262
+
263
+ if(debug) console.log("createInstruction", instruction.name, instruction.signal,
264
+ instruction.nowval, instruction.index);
265
+
266
+ instrIndex++;
267
+ return instruction;
268
+ }
269
+ exports.createInstruction = createInstruction;
270
+
271
+ // Retourne true si l'instruction se joue à l'instant
272
+ // ou a déjà été jouée (elle est brulée).
273
+ // false si pas terminée donc bloquée (en attente de signaux)
274
+ function execInstruction(command, branch){
275
+ if(debug) console.log("execInstruction: Instruction :", command.name, command.signal);
276
+
277
+ if(!command.burnt){ // Elle n'a pas encore été jouée
278
+ switch(command.name){
279
+
280
+ // Si dans un par, emit AVANT abort, prise en compte immédiate
281
+ // Si dans un par, emit APRES abort, prise en compte à la prochaine réaction
282
+ case "abort":
283
+ if(debug) console.log("abort: signal", command.signal,
284
+ ", abort burnt:", command.burnt,
285
+ ", abort index:", command.index);
286
+
287
+ if(isSignalActivatedInInstruction(command, command.signal)){
288
+ command.count++;
289
+ if(command.count >= command.countMax){
290
+ command.count = 0;
291
+ command.burnt = true;
292
+ if(debug) console.log("abort brulé car signal actif:", command);
293
+ return true;
294
+ }else{
295
+ // On joue la branche comme une séquence
296
+ for(var i=0; i < command.nextInstr.length ; i++){
297
+ if(!runBranch(command.nextInstr[i], command.nextInstr)){
298
+ command.burnt = false;
299
+ return false;
300
+ }
301
+ // Si on est à la dernière branche, c'est fini.
302
+ if(i === command.nextInstr.length - 1) {
303
+ command.count = 0;
304
+ command.burnt = true;
305
+ return true;
306
+ }
307
+ }
308
+ }
309
+ }else{
310
+ // On joue la branche comme une séquence
311
+ for(var i=0; i < command.nextInstr.length ; i++){
312
+ if(!runBranch(command.nextInstr[i], branch)){
313
+ command.burnt = false;
314
+ return false;
315
+ }
316
+ // Si on est à la dernière branche, c'est fini.
317
+ if(i === command.nextInstr.length - 1) {
318
+ command.count = 0;
319
+ command.burnt = true;
320
+ return true;
321
+ }
322
+ }
323
+ }
324
+ break;
325
+
326
+ case "atom":
327
+ if(debug) console.log("atom");
328
+ command.action();
329
+ command.burnt = true;
330
+ return true;
331
+
332
+ case "await":
333
+ // Si le signal est actif
334
+ if(isSignalActivatedInInstruction(command, command.signal)){
335
+ command.count++;
336
+ if(command.count >= command.countMax){
337
+ command.count = 0;
338
+ // On désactive le signal pour cet await
339
+ command.signalActivated = false;
340
+ // On le désactive aussi pour la branch de cet await
341
+ // pour éviter la prise en compte du signal
342
+ // absorbé par cette await
343
+ if(debug) console.log("await dans la branche:", branch);
344
+ setSignal(branch, command.signal,
345
+ command.nowval, false);
346
+ // Brule la commande
347
+ command.burnt = true;
348
+ return true;
349
+ }
350
+ }else{
351
+ command.burnt = false;
352
+ return false;
353
+ }
354
+ break;
355
+
356
+ case "await_do":
357
+ if(debug) console.log("await_do: ", command.signal, signals);
358
+
359
+ // Si le signal est actif
360
+ if(isSignalActivatedInInstruction(command, command.signal)){
361
+ command.count++;
362
+ if(command.count >= command.countMax){
363
+ command.action();
364
+ command.count = 0;
365
+ // On désactive le signal pour cet await
366
+ command.signalActivated = false;
367
+ // On le désactive aussi pour la branch de cet await
368
+ // pour éviter la prise en compte du signal
369
+ // absorbé par cette await
370
+ setSignal(branch, command.signal,
371
+ command.nowval, false);
372
+ // Brule la commande
373
+ command.burnt = true;
374
+ return true;
375
+ }
376
+ }else{
377
+ command.burnt = false;
378
+ return false;
379
+ }
380
+
381
+ case "emit":
382
+ if(debug) console.log("-- emit --", command.signal, command.nowval, command.index);
383
+ // Une sorte de broadcast du signal
384
+ // qui consiste à mettre à jour tous les signaux
385
+ // command.signal qui se trouvent dans les instructions
386
+ activateSignal(command.signal, command.nowval);
387
+
388
+ // Inspiré de HipHop. Assicié une action à une emission dans le programme.
389
+ playEventListener(command.signal, command.nowval);
390
+
391
+ if(debug) console.log("-- emit activé : ", command.signal, command.burnt);
392
+ command.burnt = true;
393
+
394
+ // Broadcast ?
395
+ //reRunProg(); // marche pas avec every qui remet les intr à unbrunt
396
+
397
+ return true;
398
+
399
+ // A revoir n'est pas conforme à la sémantique HH
400
+ // Quand le signal est actif on déclenche le corps de l'every
401
+ // en remettant les instructions en unburnt. On joue alors le corps du every.
402
+ // A la prochaine réaction si le signal n'est pas actif on ne fait rien du tout.
403
+ // Ce qui n'est pas correct. Il faudrait continuer à jouer le corps de l'every.
404
+
405
+ case "every":
406
+ // Le corps du every a déjà été commencé
407
+ if(command.branchStarted){
408
+ // Continue le corps de l'every
409
+ for(var i=0; i < command.nextInstr.length ; i++){
410
+ if(debug) console.log("every: branchStarted nextInstr[i].name", i, command.nextInstr[i].name, command.nextInstr.length);
411
+ if(!runBranch(command.nextInstr[i], command.nextInstr)){
412
+ return false;
413
+ }
414
+ // Si on est à la dernière branche, le corps du every est fini.
415
+ // mais pas every.
416
+ if(i === command.nextInstr.length -1){
417
+ command.burnt = false; // every n'est jamais terminé
418
+ // Mais on est au bout de la branche
419
+ command.branchStarted = false;
420
+ return false;
421
+ }
422
+ }
423
+ // On n'est pas au bout de la branche et le corps a été commencé.
424
+ command.burnt = false;
425
+ return false;
426
+ }
427
+
428
+ if(isSignalActivatedInInstruction(command, command.signal)){
429
+ command.count++;
430
+ if(command.count >= command.countMax){
431
+ command.count = 0;
432
+ if(debug) console.log("every: command.branch", i, command.nextInstr[0]);
433
+
434
+ // On a pris le signal en compte, il faudra
435
+ // ne pas tout recommencer la prochaine fois s'il n'est plus là...
436
+ command.signalActivated = false;
437
+
438
+ // reset des instructions
439
+ // pour repartir du début de la branche puisqu'on repoart du début de l'every.
440
+ // On pourrait aussi ne pas recommencer du début
441
+ // de la branche en commentant cette ligne.
442
+ unburnBranch(command.nextInstr);
443
+
444
+ // Le corps du every est donc commencée
445
+ command.branchStarted = true;
446
+
447
+ // Joue le corps de l'every
448
+ for(var i=0; i < command.nextInstr.length ; i++){
449
+ if(debug) console.log("every: seq command.branch", i, command.nextInstr[i].name);
450
+ if(!runBranch(command.nextInstr[i], command.nextInstr)){
451
+ return false;
452
+ }
453
+ // Si on est à la dernière branche, le corps du every est fini.
454
+ // mais pas every.
455
+ if(i === command.nextInstr.length - 1){
456
+ command.burnt = false; // every n'est jamais terminé
457
+ // Mais on est au bout de la branche
458
+ command.branchStarted = false;
459
+ return false;
460
+ }
461
+ }
462
+ }else{ // On n'a pas atteint le décompte.
463
+ command.burnt = false;
464
+ return false;
465
+ }
466
+ }else{ // Signal non activé
467
+ command.burnt = false;
468
+ return false;
469
+ }
470
+
471
+ case "loop":
472
+ if(debug) console.log("loop command.branch", command.nextInstr);
473
+
474
+ for(var i=0; i < command.nextInstr.length ; i++){
475
+ if(debug) console.log("seq command.branch", i,
476
+ command.nextInstr[i]);
477
+ if(!runBranch(command.nextInstr[i], command.nextInstr)){
478
+ return false;
479
+ }
480
+ // Si on est à la dernière branche on reset
481
+ // les instructions de la branche et on recommence
482
+ if(i === command.nextInstr.length - 1){
483
+ // reset des instructions
484
+ unburnBranch(command.nextInstr);
485
+ command.burnt = false;
486
+ return false;
487
+ }
488
+ }
489
+ break;
490
+
491
+ case "par":
492
+ var countBranch = 0;
493
+ // Les branches sont les éléments d'un tableau
494
+ for(var i=0; i < command.nextInstr.length ; i++){
495
+ if(runBranch(command.nextInstr[i], command.nextInstr)){
496
+ if(debug) console.log("Par:", i);
497
+ countBranch++;
498
+ }
499
+ }
500
+ // Si le décompte des branches terminées
501
+ // correspond à l'ensembles des instructions
502
+ // c'est qu'on a terminé le parallèle
503
+ if(countBranch === command.nextInstr.length){
504
+ command.burnt = true;
505
+ return true;
506
+ }else{
507
+ return false;
508
+ }
509
+ break;
510
+
511
+ case "restart":
512
+ if(debug1) console.log("restart:");
513
+ command.burnt = true;
514
+ reRunProg();
515
+ return true;
516
+
517
+ case "run":
518
+ case "seq":
519
+ if(debug) console.log("seq command.branch", command.nextInstr);
520
+
521
+ for(var i=0; i < command.nextInstr.length ; i++){
522
+ if(debug) console.log("seq command.branch", i, command.nextInstr[i]);
523
+ if(!runBranch(command.nextInstr[i], command.nextInstr)){
524
+ return false;
525
+ }
526
+ // Si on est à la dernière branche, c'est fini.
527
+ if(i === command.nextInstr.length -1){
528
+ command.burnt = true;
529
+ return true;
530
+ }
531
+ }
532
+ break;
533
+
534
+ case "printSignals":
535
+ // devenu inutile sou cette forme
536
+ if(debug) console.log("printSignals");
537
+ command.action();
538
+ command.burnt = true;
539
+ return true;
540
+
541
+ default: console.log("Instruction inconnue");
542
+ }
543
+ }else{ // La commande a déjà été jouée
544
+ if(debug) console.log("execInstruction: Instruction :", command.name, "déjà jouée");
545
+ return true;
546
+ }
547
+ }
548
+
549
+ /*============================================================
550
+ *
551
+ * Déclenchement d'une réaction.
552
+ * S'arrête si un signal est attendu dans le déroulement.
553
+ * La notion de programme constitué de module est une façon
554
+ * d'éviter une instruction seq en début de programme
555
+ * Est-ce bien utile ?
556
+ *
557
+ =============================================================*/
558
+ function runProg(){
559
+ if(debug) console.log("\nrunProg", prog.length);
560
+ runBranch(program.instructions, undefined);
561
+ }
562
+ exports.runProg = runProg;
563
+
564
+ function reRunProg(){
565
+ if(debug) console.log("\nreRunProg", program);
566
+ if(program !== undefined){
567
+ runBranch(program.instructions, undefined);
568
+ }
569
+ }
570
+
571
+ // Création du point de départ du programme
572
+ function createModule(instr){
573
+ var module = {
574
+ name: "Program",
575
+ signal: undefined,
576
+ signalActivated: false,
577
+ burnt: false,
578
+ instructions: instr
579
+ }
580
+ program = module;
581
+ return module;
582
+ }
583
+ exports.createModule = createModule;
584
+
585
+ /*============================================================
586
+ *
587
+ * Pour l'execution du programme
588
+ *
589
+ =============================================================*/
590
+
591
+ // Exécute la liste d'instructions qui constitue une branche
592
+ // Reçoit comme paramètre un tableau d'objets instructions.
593
+ // S'arrête et retourne true si la branche a été executée
594
+ // false si on tombe sur une instruction en attente.
595
+ function runBranch(instructions, branch){
596
+ if(debug) console.log("\nrunBranch: length: ", instructions.length);
597
+
598
+ // --> Cas d'une instruction seule
599
+ if(instructions.length === undefined){
600
+ if(debug) console.log("runBranch: instruction seule:", instructions.name);
601
+ // Si l'instruction est bloquée
602
+ if(!execInstruction( instructions, branch )){
603
+ return false;
604
+ }
605
+ // Si l'instruction est ou a été jouée
606
+ return true;
607
+ }
608
+
609
+ // --> Cas d'un tableau d'instructions
610
+ for(var i=0; i < instructions.length; i++){
611
+ if(debug) console.log("-- runBranch: tableau d'instructions:", i,
612
+ instructions[i].name, instructions[i].index);
613
+ // On tombe sur une instruction bloquée
614
+ if(!execInstruction( instructions[i], instructions )){
615
+ return false;
616
+ }
617
+ // On joue la suivante
618
+ }
619
+ // On a joué la branche complétement
620
+ return true;
621
+ }
622
+
623
+ // Restauration des instructions dans une branche
624
+ function unburnBranch(instructions){
625
+ // On est sur une instruction "finale" et plus sur une branche
626
+ if(instructions === undefined){
627
+ return true;
628
+ }
629
+
630
+ if(instructions.length === undefined){
631
+ if(debug) console.log("unburnBranch 1:", instructions);
632
+ instructions.burnt = false;
633
+ return true;
634
+ }
635
+
636
+ // On est sur une suite d'instructions
637
+ for(var i=0; i < instructions.length; i++){
638
+ if(debug) console.log("\n--- unburnBranch", i, instructions[i].name);
639
+ if(instructions[i].burnt !== undefined){
640
+ if(debug) console.log("unburnBranch 2:", instructions[i].name);
641
+ instructions[i].burnt = false;
642
+ unburnBranch(instructions[i].nextInstr);
643
+ }else{
644
+ unburnBranch(instructions[i].nextInstr);
645
+ }
646
+ }
647
+ return true;
648
+ }
649
+
650
+ /*============================================================
651
+ *
652
+ * Pour une vision du programme à exécuter
653
+ * Balayage de l'arbre du programme
654
+ *
655
+ =============================================================*/
656
+
657
+ function printInstructions(instr, option){
658
+ if(instr === undefined) return;
659
+
660
+ for(var i=0; i < instr.length; i++){
661
+ if(option === true){
662
+ console.log(instr[i]);
663
+ console.log("------------------------------");
664
+ }else{
665
+ console.log("-> ", instr[i].name, ": index:", instr[i].index, ", signal :", instr[i].signal, ", signalActivated :", instr[i].signalActivated);
666
+ }
667
+ printInstructions(instr[i].nextInstr, option);
668
+ }
669
+ }
670
+
671
+ function printProgram(prog, option){
672
+ console.log("------ PROGRAM ---------------");
673
+ printInstructions(prog.instructions, option);
674
+ console.log("------------------------------");
675
+ }
676
+ exports.printProgram = printProgram;
677
+
678
+ /*============================================================
679
+ *
680
+ * Couche de simplification des créations
681
+ * d'instructions pour export et utilisation dans Blockly
682
+ *
683
+ =============================================================*/
684
+
685
+ function _emit(signal, value){
686
+ return createInstruction("emit", signal, value, undefined, undefined, undefined);
687
+ }
688
+ exports._emit = _emit;
689
+
690
+ function _await(signal, count){
691
+ return createInstruction("await",signal, undefined, count, undefined, undefined);
692
+ }
693
+ exports._await = _await;
694
+
695
+ function _await_do(signal, count, action){
696
+ return createInstruction("await_do",signal, undefined, count, action, undefined);
697
+ }
698
+ exports._await_do = _await_do;
699
+
700
+ function _abort(signal, count, instructions){
701
+ return createInstruction("abort",signal, undefined, count, undefined, instructions);
702
+ }
703
+ exports._abort = _abort;
704
+
705
+ function _every(signal, count, instructions){
706
+ return createInstruction("every",signal, undefined, count, undefined, instructions);
707
+ }
708
+ exports._every = _every;
709
+
710
+ function _seq(instructions){
711
+ return createInstruction("seq", undefined, undefined, undefined, undefined, instructions);
712
+ }
713
+ exports._seq = _seq;
714
+
715
+ function _par(instructions){
716
+ return createInstruction("par", undefined, undefined, undefined, undefined, instructions);
717
+ }
718
+ exports._par = _par;
719
+
720
+ function _loop(instructions){
721
+ return createInstruction("loop", undefined, undefined, undefined, undefined, instructions);
722
+ }
723
+ exports._loop = _loop;
724
+
725
+ function _run(module){
726
+ //var instructions = _seq(module);
727
+ return createInstruction("run", undefined, undefined, undefined, undefined, module);
728
+ }
729
+ exports._run = _run;
730
+
731
+ function _atom(action){
732
+ return createInstruction("atom",undefined, undefined, undefined, action, undefined);
733
+ }
734
+ exports._atom = _atom;
735
+
736
+ function _printSignals(){
737
+ return createInstruction("printSignals",undefined, undefined, undefined, () => {console.log(signals);}, undefined);
738
+ }
739
+ exports._printSignals = _printSignals;
740
+
741
+ function _restart(){
742
+ return createInstruction("restart",undefined, undefined, undefined, undefined, undefined);
743
+ }
744
+ exports._restart = _restart;