nabaztag_hack_kit 0.1.0.beta3 → 0.1.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -2
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +2 -2
  5. data/CHANGELOG.md +17 -2
  6. data/LICENSE +21 -0
  7. data/README.md +115 -44
  8. data/Rakefile +2 -6
  9. data/bytecode/{Commands.md → _docs/commands.md} +0 -0
  10. data/bytecode/{Docs.md → _docs/grammar.md} +0 -0
  11. data/bytecode/_docs/grammar.pdf +0 -0
  12. data/bytecode/{src → _original}/README.md +0 -0
  13. data/bytecode/{src → _original}/lib/arp.mtl +0 -0
  14. data/bytecode/{src → _original}/lib/cfg.mtl +0 -0
  15. data/bytecode/{src → _original}/lib/choreos.mtl +0 -0
  16. data/bytecode/{src → _original}/lib/dhcp.mtl +0 -0
  17. data/bytecode/{src → _original}/lib/dns.mtl +0 -0
  18. data/bytecode/{src → _original}/lib/http.mtl +0 -0
  19. data/bytecode/{src → _original}/lib/tcp.mtl +0 -0
  20. data/bytecode/{src → _original}/lib/udp.mtl +0 -0
  21. data/bytecode/{src → _original}/lib/util.mtl +0 -0
  22. data/bytecode/{src → _original}/lib/var.mtl +0 -0
  23. data/bytecode/{src → _original}/lib/wav.mtl +0 -0
  24. data/bytecode/{src → _original}/lib/wifi.mtl +0 -0
  25. data/bytecode/{src → _original}/nominal-ping.mtl +0 -0
  26. data/bytecode/main.mtl +11 -11
  27. data/bytecode/test/test.mtl +8 -8
  28. data/examples/basic/Gemfile +1 -3
  29. data/examples/basic/config.ru +14 -4
  30. data/examples/record/Gemfile +0 -5
  31. data/examples/record/{config.ru.example → config.ru} +2 -2
  32. data/examples/record/server.rb +0 -2
  33. data/ext/Makefile +10 -0
  34. data/ext/bin/mtl_comp +29 -0
  35. data/{bytecode → ext}/bin/mtl_merge +0 -0
  36. data/ext/bin/mtl_simu +29 -0
  37. data/{bytecode/src/mtl → ext}/extconf.rb +0 -0
  38. data/ext/mtl_linux/.gitignore +7 -0
  39. data/ext/mtl_linux/LICENSE +21 -0
  40. data/ext/mtl_linux/Makefile +116 -0
  41. data/ext/mtl_linux/MetalC.project +196 -0
  42. data/ext/mtl_linux/conf.bin +0 -0
  43. data/{bytecode/src/mtl → ext/mtl_linux}/conf.bin.sans_password +0 -0
  44. data/{bytecode/src/mtl → ext/mtl_linux}/config.txt +0 -0
  45. data/ext/mtl_linux/inc/log.h +21 -0
  46. data/{bytecode/src/mtl → ext/mtl_linux/inc}/properties.h +0 -0
  47. data/{bytecode/src/mtl/linux_simuaudio.h → ext/mtl_linux/inc/simu/linux/simuaudio.h} +0 -0
  48. data/{bytecode/src/mtl/linux_simunet.h → ext/mtl_linux/inc/simu/linux/simunet.h} +0 -0
  49. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simuaudio.h +18 -18
  50. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simunet.h +0 -0
  51. data/ext/mtl_linux/inc/vcomp/compiler.h +200 -0
  52. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/file.h +11 -11
  53. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/filesystem.h +0 -0
  54. data/ext/mtl_linux/inc/vcomp/interpreter.h +121 -0
  55. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/memory.h +120 -92
  56. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/param.h +0 -0
  57. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/parser.h +27 -27
  58. data/ext/mtl_linux/inc/vcomp/prodbuffer.h +42 -0
  59. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/resource.h +1 -1
  60. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/terminal.h +8 -8
  61. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/util.h +7 -7
  62. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vaudio.h +0 -0
  63. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vbc.h +1 -1
  64. data/ext/mtl_linux/inc/vm/vbc_str.h +167 -0
  65. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vinterp.h +0 -0
  66. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vloader.h +0 -0
  67. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vlog.h +0 -0
  68. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vmem.h +0 -0
  69. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vnet.h +0 -0
  70. data/ext/mtl_linux/nominal.mtl +3959 -0
  71. data/ext/mtl_linux/src/comp/main.cpp +123 -0
  72. data/ext/mtl_linux/src/simu/dumpbc.c +2566 -0
  73. data/ext/mtl_linux/src/simu/linux/main.cpp +288 -0
  74. data/ext/mtl_linux/src/simu/linux/simu.c +309 -0
  75. data/ext/mtl_linux/src/simu/linux/simuaudio.c +44 -0
  76. data/ext/mtl_linux/src/simu/linux/simunet.c +707 -0
  77. data/ext/mtl_linux/src/simu/log.c +340 -0
  78. data/ext/mtl_linux/src/simu/properties.c +368 -0
  79. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/GTKANAL.H +0 -0
  80. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/LAYER3.C +0 -0
  81. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/TABINIT.C +0 -0
  82. data/ext/mtl_linux/src/simu/win/mp3/common.c +302 -0
  83. data/ext/mtl_linux/src/simu/win/mp3/dct64_i386.c +316 -0
  84. data/ext/mtl_linux/src/simu/win/mp3/decode_i386.c +160 -0
  85. data/ext/mtl_linux/src/simu/win/mp3/huffman.h +332 -0
  86. data/ext/mtl_linux/src/simu/win/mp3/interface.c +276 -0
  87. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/mpg123.h +34 -30
  88. data/ext/mtl_linux/src/simu/win/mp3/mpglib.h +47 -0
  89. data/ext/mtl_linux/src/simu/win/simu.c +819 -0
  90. data/ext/mtl_linux/src/simu/win/simuaudio.c +787 -0
  91. data/ext/mtl_linux/src/simu/win/simunet.c +489 -0
  92. data/ext/mtl_linux/src/vcomp/bootstrap.cpp +95 -0
  93. data/ext/mtl_linux/src/vcomp/compiler.cpp +587 -0
  94. data/ext/mtl_linux/src/vcomp/compiler_file.cpp +1253 -0
  95. data/ext/mtl_linux/src/vcomp/compiler_prog.cpp +437 -0
  96. data/ext/mtl_linux/src/vcomp/compiler_term.cpp +1500 -0
  97. data/ext/mtl_linux/src/vcomp/compiler_type.cpp +1238 -0
  98. data/ext/mtl_linux/src/vcomp/compiler_var.cpp +502 -0
  99. data/ext/mtl_linux/src/vcomp/file.cpp +100 -0
  100. data/ext/mtl_linux/src/vcomp/interpreter.cpp +93 -0
  101. data/ext/mtl_linux/src/vcomp/memory.cpp +313 -0
  102. data/ext/mtl_linux/src/vcomp/parser.cpp +584 -0
  103. data/ext/mtl_linux/src/vcomp/parser_xml.cpp +137 -0
  104. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/prodbuffer.cpp +57 -36
  105. data/ext/mtl_linux/src/vcomp/stdlib_core.cpp +130 -0
  106. data/ext/mtl_linux/src/vcomp/terminal.cpp +80 -0
  107. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/util.cpp +18 -11
  108. data/ext/mtl_linux/src/vm/vaudio.c +830 -0
  109. data/ext/mtl_linux/src/vm/vinterp.c +1780 -0
  110. data/ext/mtl_linux/src/vm/vloader.c +139 -0
  111. data/ext/mtl_linux/src/vm/vlog.c +782 -0
  112. data/ext/mtl_linux/src/vm/vmem.c +461 -0
  113. data/ext/mtl_linux/src/vm/vnet.c +298 -0
  114. data/{bytecode/src/mtl → ext/mtl_linux}/utils/correct_const.sh +0 -0
  115. data/lib/nabaztag_hack_kit/server.rb +4 -7
  116. data/lib/nabaztag_hack_kit/version.rb +1 -1
  117. data/lib/nabaztag_hack_kit.rb +2 -2
  118. data/nabaztag_hack_kit.gemspec +10 -11
  119. data/spec/integration/server_spec.rb +3 -3
  120. data/spec/spec_helper.rb +2 -0
  121. data/spec/unit/message_spec.rb +12 -18
  122. data/spec/unit/server_spec.rb +13 -10
  123. metadata +145 -137
  124. data/bytecode/bin/mtl_comp +0 -50
  125. data/bytecode/bin/mtl_simu +0 -49
  126. data/bytecode/src/mtl/Makefile +0 -42
  127. data/bytecode/src/mtl/README.md +0 -13
  128. data/bytecode/src/mtl/bc.cpp +0 -1891
  129. data/bytecode/src/mtl/dumpbc.c +0 -2566
  130. data/bytecode/src/mtl/linux_simu.c +0 -271
  131. data/bytecode/src/mtl/linux_simuaudio.c +0 -16
  132. data/bytecode/src/mtl/linux_simunet.c +0 -620
  133. data/bytecode/src/mtl/log.c +0 -297
  134. data/bytecode/src/mtl/log.h +0 -20
  135. data/bytecode/src/mtl/main_compiler.cpp +0 -104
  136. data/bytecode/src/mtl/main_simu.cpp +0 -221
  137. data/bytecode/src/mtl/mp3/common.c +0 -265
  138. data/bytecode/src/mtl/mp3/dct64_i386.c +0 -316
  139. data/bytecode/src/mtl/mp3/decode_i386.c +0 -155
  140. data/bytecode/src/mtl/mp3/huffman.h +0 -332
  141. data/bytecode/src/mtl/mp3/interface.c +0 -258
  142. data/bytecode/src/mtl/mp3/mpglib.h +0 -44
  143. data/bytecode/src/mtl/properties.c +0 -293
  144. data/bytecode/src/mtl/simu.c +0 -750
  145. data/bytecode/src/mtl/simuaudio.c +0 -662
  146. data/bytecode/src/mtl/simunet.c +0 -400
  147. data/bytecode/src/mtl/vaudio.c +0 -677
  148. data/bytecode/src/mtl/vbc_str.h +0 -166
  149. data/bytecode/src/mtl/vcomp/Makefile +0 -29
  150. data/bytecode/src/mtl/vcomp/bootstrap.cpp +0 -89
  151. data/bytecode/src/mtl/vcomp/compiler.cpp +0 -470
  152. data/bytecode/src/mtl/vcomp/compiler.h +0 -200
  153. data/bytecode/src/mtl/vcomp/compiler_file.cpp +0 -929
  154. data/bytecode/src/mtl/vcomp/compiler_prog.cpp +0 -250
  155. data/bytecode/src/mtl/vcomp/compiler_term.cpp +0 -1053
  156. data/bytecode/src/mtl/vcomp/compiler_type.cpp +0 -872
  157. data/bytecode/src/mtl/vcomp/compiler_var.cpp +0 -289
  158. data/bytecode/src/mtl/vcomp/file.cpp +0 -79
  159. data/bytecode/src/mtl/vcomp/interpreter.cpp +0 -85
  160. data/bytecode/src/mtl/vcomp/interpreter.h +0 -121
  161. data/bytecode/src/mtl/vcomp/memory.cpp +0 -241
  162. data/bytecode/src/mtl/vcomp/parser.cpp +0 -427
  163. data/bytecode/src/mtl/vcomp/parser_xml.cpp +0 -124
  164. data/bytecode/src/mtl/vcomp/prodbuffer.h +0 -42
  165. data/bytecode/src/mtl/vcomp/stdlib_core.cpp +0 -122
  166. data/bytecode/src/mtl/vcomp/terminal.cpp +0 -73
  167. data/bytecode/src/mtl/vinterp.c +0 -1349
  168. data/bytecode/src/mtl/vloader.c +0 -127
  169. data/bytecode/src/mtl/vlog.c +0 -589
  170. data/bytecode/src/mtl/vmem.c +0 -424
  171. data/bytecode/src/mtl/vnet.c +0 -255
  172. data/examples/basic/Procfile +0 -2
  173. data/examples/basic/server.rb +0 -14
@@ -0,0 +1,502 @@
1
+ //-------------------
2
+ // MV
3
+ // version WIN32 et POCKETPC
4
+ // Sylvain Huet
5
+ // Derniere mise a jour : 07/01/2003
6
+ //
7
+
8
+ #include <stdio.h>
9
+ #include <string.h>
10
+ #include <stdint.h>
11
+
12
+ #include "param.h"
13
+ #include "terminal.h"
14
+ #include "memory.h"
15
+ #include "parser.h"
16
+ #include "prodbuffer.h"
17
+ #include "compiler.h"
18
+ #include "interpreter.h"
19
+
20
+
21
+ int Compiler::parseval()
22
+ {
23
+ int k;
24
+
25
+ if (k=parseval3())
26
+ {
27
+ return k;
28
+ }
29
+
30
+ if (!parser->next(0))
31
+ {
32
+ return 0;
33
+ }
34
+ if (strcmp(parser->token,"::"))
35
+ {
36
+ parser->giveback();
37
+ return 0;
38
+ }
39
+ if (k=parseval())
40
+ {
41
+ return k; // r�cursion
42
+ }
43
+
44
+ if (k=createnodetype(TYPENAME_LIST))
45
+ {
46
+ return k;
47
+ }
48
+ if (k=createnodetype(TYPENAME_UNDEF))
49
+ {
50
+ return k; // noeud �lement
51
+ }
52
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0)); // attachement du noeud �l�ment au noeud list
53
+ if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,4))))
54
+ {
55
+ return k; // unification �lement
56
+ }
57
+ if (k=unif(VALTOPNT(STACKGET(m,1)),VALTOPNT(STACKGET(m,2))))
58
+ {
59
+ return k; // unification list
60
+ }
61
+ STACKSET(m,4,STACKGET(m,1)); // remplacement du type
62
+
63
+ intptr_t* p=MALLOCCLEAR(m,LIST_LENGTH); // cr�ation du tuple liste
64
+ if (!p)
65
+ {
66
+ return MTLERR_OM;
67
+ }
68
+ TABSET(m,p,LIST_VAL,STACKGET(m,5));
69
+ TABSET(m,p,LIST_NEXT,STACKGET(m,3));
70
+ STACKSET(m,5,PNTTOVAL(p));
71
+ STACKDROPN(m,4);
72
+ return 0;
73
+ }
74
+
75
+
76
+ int Compiler::parseval3()
77
+ {
78
+ int k,op,typ;
79
+
80
+ if (k=parseval4())
81
+ {
82
+ return k;
83
+ }
84
+ while(1)
85
+ {
86
+ if (!parser->next(0))
87
+ {
88
+ return 0;
89
+ }
90
+ if (!strcmp(parser->token,"+"))
91
+ {
92
+ op=OPadd;
93
+ typ=1;
94
+ }
95
+ else if (!strcmp(parser->token,"-"))
96
+ {
97
+ op=OPsub;
98
+ typ=1;
99
+ }
100
+ else
101
+ {
102
+ parser->giveback();
103
+ return 0;
104
+ }
105
+ if (k=parseval4())
106
+ {
107
+ return k;
108
+ }
109
+ if (op==OPadd)
110
+ {
111
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))+VALTOINT(STACKGET(m,1))));
112
+ }
113
+ else if (op==OPsub)
114
+ {
115
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))-VALTOINT(STACKGET(m,1))));
116
+ }
117
+ intptr_t* ptyp;
118
+ if (typ==1)
119
+ {
120
+ ptyp=VALTOPNT(TABGET(stdtypes,STDTYPE_I));
121
+ }
122
+ if (k=unif(VALTOPNT(STACKGET(m,0)),ptyp))
123
+ {
124
+ return k;
125
+ }
126
+ if (k=unif(VALTOPNT(STACKGET(m,2)),ptyp))
127
+ {
128
+ return k;
129
+ }
130
+ STACKDROPN(m,2);
131
+ }
132
+ }
133
+
134
+ int Compiler::parseval4()
135
+ {
136
+ int k,op,typ;
137
+
138
+ if (k=parseval5())
139
+ {
140
+ return k;
141
+ }
142
+ while(1)
143
+ {
144
+ if (!parser->next(0))
145
+ {
146
+ return 0;
147
+ }
148
+ if (!strcmp(parser->token,"*"))
149
+ {
150
+ op=OPmul;
151
+ typ=1;
152
+ }
153
+ else if (!strcmp(parser->token,"/"))
154
+ {
155
+ op=OPdiv;
156
+ typ=1;
157
+ }
158
+ else if (!strcmp(parser->token,"%"))
159
+ {
160
+ op=OPmod;
161
+ typ=1;
162
+ }
163
+ else
164
+ {
165
+ parser->giveback();
166
+ return 0;
167
+ }
168
+ if (k=parseval5())
169
+ {
170
+ return k;
171
+ }
172
+
173
+ if (op==OPmul)
174
+ {
175
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))*VALTOINT(STACKGET(m,1))));
176
+ }
177
+ else if (op==OPdiv)
178
+ {
179
+ if (VALTOINT(STACKGET(m,1))==0)
180
+ {
181
+ return MTLERR_DIV;
182
+ }
183
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))/VALTOINT(STACKGET(m,1))));
184
+ }
185
+ else if (op==OPmod)
186
+ {
187
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))%VALTOINT(STACKGET(m,1))));
188
+ }
189
+ intptr_t* ptyp;
190
+ if (typ==1)
191
+ {
192
+ ptyp=VALTOPNT(TABGET(stdtypes,STDTYPE_I));
193
+ }
194
+ if (k=unif(VALTOPNT(STACKGET(m,0)),ptyp))
195
+ {
196
+ return k;
197
+ }
198
+ if (k=unif(VALTOPNT(STACKGET(m,2)),ptyp))
199
+ {
200
+ return k;
201
+ }
202
+ STACKDROPN(m,2);
203
+ }
204
+ }
205
+
206
+ int Compiler::parseval5()
207
+ {
208
+ int k,op;
209
+
210
+ if (k=parseval6())
211
+ {
212
+ return k;
213
+ }
214
+ while(1)
215
+ {
216
+ if (!parser->next(0))
217
+ {
218
+ return 0;
219
+ }
220
+ if (!strcmp(parser->token,"&"))
221
+ {
222
+ op=OPand;
223
+ }
224
+ else if (!strcmp(parser->token,"|"))
225
+ {
226
+ op=OPor;
227
+ }
228
+ else if (!strcmp(parser->token,"^"))
229
+ {
230
+ op=OPeor;
231
+ }
232
+ else if (!strcmp(parser->token,"<<"))
233
+ {
234
+ op=OPshl;
235
+ }
236
+ else if (!strcmp(parser->token,">>"))
237
+ {
238
+ op=OPshr;
239
+ }
240
+ else
241
+ {
242
+ parser->giveback();
243
+ return 0;
244
+ }
245
+ if (k=parseval6())
246
+ {
247
+ return k;
248
+ }
249
+
250
+ if (op==OPand)
251
+ {
252
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))&VALTOINT(STACKGET(m,1))));
253
+ }
254
+ else if (op==OPor)
255
+ {
256
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))|VALTOINT(STACKGET(m,1))));
257
+ }
258
+ else if (op==OPeor)
259
+ {
260
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))^VALTOINT(STACKGET(m,1))));
261
+ }
262
+ else if (op==OPshl)
263
+ {
264
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))<<VALTOINT(STACKGET(m,1))));
265
+ }
266
+ else if (op==OPshr)
267
+ {
268
+ STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))>>VALTOINT(STACKGET(m,1))));
269
+ }
270
+
271
+ intptr_t* ptyp=VALTOPNT(TABGET(stdtypes,STDTYPE_I));
272
+ if (k=unif(VALTOPNT(STACKGET(m,0)),ptyp))
273
+ {
274
+ return k;
275
+ }
276
+ if (k=unif(VALTOPNT(STACKGET(m,2)),ptyp))
277
+ {
278
+ return k;
279
+ }
280
+ STACKDROPN(m,2);
281
+ }
282
+ }
283
+
284
+ int Compiler::parseval6()
285
+ {
286
+ int k;
287
+
288
+ if (!parser->next(0))
289
+ {
290
+ return parseval7();
291
+ }
292
+
293
+ if (!strcmp(parser->token,"-"))
294
+ {
295
+ if (!parser->next(0))
296
+ {
297
+ return parseval6();
298
+ }
299
+ if (isdecimal(parser->token)) // gestion des entiers
300
+ {
301
+ int i=-mtl_atoi(parser->token);
302
+ if (k=STACKPUSH(m,INTTOVAL(i)))
303
+ {
304
+ return k;
305
+ }
306
+ return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
307
+ }
308
+ parser->giveback();
309
+ if (k=parseval6())
310
+ {
311
+ return k;
312
+ }
313
+ STACKSET(m,1,INTTOVAL(-VALTOINT(STACKGET(m,0))));
314
+ return unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(TABGET(stdtypes,STDTYPE_I)));
315
+ }
316
+ else if (!strcmp(parser->token,"~"))
317
+ {
318
+ if (k=parseval6())
319
+ {
320
+ return k;
321
+ }
322
+ STACKSET(m,1,INTTOVAL(~VALTOINT(STACKGET(m,0))));
323
+ return unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(TABGET(stdtypes,STDTYPE_I)));
324
+ }
325
+ parser->giveback();
326
+ return parseval7();
327
+ }
328
+
329
+
330
+ int Compiler::parseval7()
331
+ {
332
+ int k;
333
+
334
+ if (!parser->next(0))
335
+ {
336
+ PRINTF(m)(LOG_COMPILER,"Compiler : term expected (found EOF)\n");
337
+ return MTLERR_SN;
338
+ }
339
+ if (!strcmp(parser->token,"(")) // gestion des parenth�ses
340
+ {
341
+ if (k=parseval())
342
+ {
343
+ return k;
344
+ }
345
+ return parser->parsekeyword(")");
346
+ }
347
+ else if (!strcmp(parser->token,"[")) // gestion des tuples
348
+ {
349
+ int nval=0;
350
+ if (k=STACKPUSH(m,NIL))
351
+ {
352
+ return k; // valeur finale
353
+ }
354
+ if (k=STACKPUSH(m,NIL))
355
+ {
356
+ return k; // type final
357
+ }
358
+ int sref=STACKREF(m);
359
+ while(1)
360
+ {
361
+ if (!parser->next(0))
362
+ {
363
+ PRINTF(m)(LOG_COMPILER,"Compiler : ']' expected (found EOF)\n");
364
+ return MTLERR_SN;
365
+ }
366
+ if (!strcmp(parser->token,"]"))
367
+ {
368
+ intptr_t* p=MALLOCCLEAR(m,nval); // cr�ation du tuple liste
369
+ if (!p)
370
+ {
371
+ return MTLERR_OM;
372
+ }
373
+ int i;
374
+ for(i=0; i<nval; i++)
375
+ {
376
+ TABSET(m,p,i,STACKGET(m,(nval-i)*2-1));
377
+ }
378
+ STACKSETFROMREF(m,sref,1,PNTTOVAL(p));
379
+ if (k=createnodetupleval(nval))
380
+ {
381
+ return k;
382
+ }
383
+ STACKSETFROMREF(m,sref,0,STACKPULL(m));
384
+ STACKRESTOREREF(m,sref);
385
+ return 0;
386
+ }
387
+ parser->giveback();
388
+ if (k=parseval())
389
+ {
390
+ return k;
391
+ }
392
+ nval++;
393
+ }
394
+ }
395
+ else if (!strcmp(parser->token,"{")) // gestion des tableaux
396
+ {
397
+ int nval=0;
398
+ if (k=STACKPUSH(m,NIL))
399
+ {
400
+ return k; // valeur finale
401
+ }
402
+ if (k=createnodetype(TYPENAME_TAB))
403
+ {
404
+ return k; // type final
405
+ }
406
+ if (k=createnodetype(TYPENAME_UNDEF))
407
+ {
408
+ return k;
409
+ }
410
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0));
411
+ intptr_t* p=VALTOPNT(STACKPULL(m));
412
+
413
+ while(1)
414
+ {
415
+ if (!parser->next(0))
416
+ {
417
+ PRINTF(m)(LOG_COMPILER,"Compiler : '}' expected (found EOF)\n");
418
+ return MTLERR_SN;
419
+ }
420
+ if (!strcmp(parser->token,"}"))
421
+ {
422
+
423
+ if (k=DEFTAB(m,nval))
424
+ {
425
+ return k;
426
+ }
427
+
428
+ STACKSET(m,2,STACKGET(m,0)); // report de la valeur du tableau
429
+ STACKDROP(m);
430
+ return 0;
431
+ }
432
+ parser->giveback();
433
+ if (k=parseval())
434
+ {
435
+ return k;
436
+ }
437
+ if (k=unif(VALTOPNT(STACKGET(m,0)),p))
438
+ {
439
+ return k;
440
+ }
441
+ STACKDROP(m);
442
+ nval++;
443
+ }
444
+ }
445
+ else if (!strcmp(parser->token,"nil")) // gestion du nil
446
+ {
447
+ if (k=STACKPUSH(m,NIL))
448
+ {
449
+ return k; // valeur
450
+ }
451
+ return createnodetype(TYPENAME_WEAK);
452
+ }
453
+ else if (!strcmp(parser->token,"'")) // gestion des 'char
454
+ {
455
+ if (!parser->next(0))
456
+ {
457
+ PRINTF(m)(LOG_COMPILER,"Compiler : 'char expected (found EOF)\n");
458
+ return MTLERR_SN;
459
+ }
460
+ if (k=STACKPUSH(m,INTTOVAL(parser->token[0]&255)))
461
+ {
462
+ return k; // valeur
463
+ }
464
+ if (k=parser->parsekeyword("'"))
465
+ {
466
+ return k;
467
+ }
468
+ return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
469
+ }
470
+ else if (isdecimal(parser->token)) // gestion des entiers
471
+ {
472
+ int i=mtl_atoi(parser->token);
473
+ if (k=STACKPUSH(m,INTTOVAL(i)))
474
+ {
475
+ return k; // valeur
476
+ }
477
+ return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
478
+ }
479
+ else if ((parser->token[0]=='0')&&(parser->token[1]=='x')
480
+ &&(ishexadecimal(parser->token+2))) // gestion des entiers
481
+ {
482
+ int i=mtl_htoi(parser->token+2);
483
+ if (k=STACKPUSH(m,INTTOVAL(i)))
484
+ {
485
+ return k; // valeur
486
+ }
487
+ return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
488
+ }
489
+ else if (parser->token[0]=='"') // gestion des chaines
490
+ {
491
+ if (k=parser->getstring(m,'"'))
492
+ {
493
+ return k;
494
+ }
495
+ return STACKPUSH(m,TABGET(stdtypes,STDTYPE_S));
496
+ }
497
+ else
498
+ {
499
+ PRINTF(m)(LOG_COMPILER,"Compiler : unexpected term '%s'\n",parser->token);
500
+ return MTLERR_SN;
501
+ }
502
+ }
@@ -0,0 +1,100 @@
1
+ //-------------------
2
+ // Moteur 3d
3
+ // version WIN32 et POCKETPC
4
+ // Sylvain Huet
5
+ // Premiere version : 03/09/2002
6
+ // Derniere mise a jour : 05/10/2002
7
+ //
8
+
9
+ #include <stdio.h>
10
+ #include <stdarg.h>
11
+ #include <string.h>
12
+
13
+ #include "param.h"
14
+ #include "filesystem.h"
15
+ #include "file.h"
16
+
17
+ ///////////////
18
+ // File - gestion simple de fichiers
19
+
20
+
21
+ File::File(FileSystem *fs)
22
+ {
23
+ filesystem=fs;
24
+ file=NULL;
25
+ sizeinternalbuffer=64;
26
+ internalbuffer=new char[sizeinternalbuffer];
27
+ }
28
+
29
+ File::~File()
30
+ {
31
+ if (file)
32
+ {
33
+ fclose(file);
34
+ }
35
+ delete internalbuffer;
36
+ }
37
+
38
+ int File::close()
39
+ {
40
+ if (file)
41
+ {
42
+ fclose(file);
43
+ }
44
+ file=NULL;
45
+ return 0;
46
+ }
47
+
48
+
49
+ int File::openread(const char* name)
50
+ {
51
+ file=fopen(name,"rb");
52
+ if (file)
53
+ {
54
+ return 0;
55
+ }
56
+ return -1;
57
+ }
58
+
59
+ char* File::getcontent(int *size)
60
+ {
61
+ if (file==NULL)
62
+ {
63
+ return NULL;
64
+ }
65
+
66
+ fseek(file,0,SEEK_END);
67
+ *size=ftell(file);
68
+ fseek(file,0,SEEK_SET);
69
+
70
+ char* buffer;
71
+ buffer=new char[(*size)+1];
72
+ fread((void*)buffer,1,*size,file);
73
+ buffer[*size]=0;
74
+ close();
75
+ return buffer;
76
+ }
77
+ int File::openwrite(const char* name)
78
+ {
79
+ file=fopen(name,"wb");
80
+ if (file)
81
+ {
82
+ return 0;
83
+ }
84
+ return -1;
85
+ }
86
+ int File::write(const char *outbuf,int size)
87
+ {
88
+ if (file==NULL)
89
+ {
90
+ return 0;
91
+ }
92
+
93
+ int k=fwrite((void*)outbuf,1,size,file);
94
+ if (k<0)
95
+ {
96
+ return -1;
97
+ }
98
+ fflush(file);
99
+ return 0;
100
+ }
@@ -0,0 +1,93 @@
1
+ //-------------------
2
+ // MV
3
+ // version WIN32 et POCKETPC
4
+ // Sylvain Huet
5
+ // Premiere version : 07/01/2003
6
+ // Derniere mise a jour : 07/01/2003
7
+ //
8
+
9
+ #include <stdio.h>
10
+ #include <string.h>
11
+ #include <stdint.h>
12
+
13
+ #include "param.h"
14
+ #include "terminal.h"
15
+ #include "prodbuffer.h"
16
+ #include "memory.h"
17
+ #include "util.h"
18
+ #include "interpreter.h"
19
+ #include "compiler.h"
20
+
21
+ #include"vm/vbc_str.h"
22
+
23
+ void displaybc(Memory* m,char* p)
24
+ {
25
+ PRINTF(m)(LOG_DEVCORE,"dump %x\n",p);
26
+ const char* spaces=" ";
27
+ int ind=0;
28
+ while(1)
29
+ {
30
+ int i=*p;
31
+ if ((i<0)||(i>=MaxOpcode))
32
+ {
33
+ PRINTF(m)(LOG_DEVCORE,"%4d ??\n",ind);
34
+ }
35
+ else if ((i==OPint))
36
+ {
37
+ p++;
38
+ int v=(p[0]&255)+((p[1]&255)<<8)+((p[2]&255)<<16)+((p[3]&255)<<24);
39
+ PRINTF(m)(LOG_DEVCORE,"%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
40
+ ind+=4;
41
+ p+=3;
42
+ }
43
+ else if ((i==OPgoto)||(i==OPelse))
44
+ {
45
+ p++;
46
+ int v=(p[0]&255)+((p[1]&255)<<8);
47
+ PRINTF(m)(LOG_DEVCORE,"%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
48
+ ind+=2;
49
+ p+=1;
50
+ }
51
+ else if ((i==OPgetlocalb)||(i==OPgetglobalb)||(i==OPfetchb)||(i==OPdeftabb)||(i==OPsetlocalb)||
52
+ (i==OPmktabb)||(i==OPsetstructb)||(i==OPcallrb)||(i==OPintb))
53
+ {
54
+ p++;
55
+ int v=p[0]&255;
56
+ PRINTF(m)(LOG_DEVCORE,"%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
57
+ ind++;
58
+ }
59
+ else if (i==OPret)
60
+ {
61
+ PRINTF(m)(LOG_DEVCORE,"%4d %s%s\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]));
62
+ return;
63
+ }
64
+ else
65
+ {
66
+ PRINTF(m)(LOG_DEVCORE,"%4d %s%s\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]));
67
+ }
68
+ ind++;
69
+ p++;
70
+ }
71
+ }
72
+
73
+
74
+ Interpreter::Interpreter(Memory* memory)
75
+ {
76
+ m=memory;
77
+ output=new Prodbuffer();
78
+ };
79
+
80
+ Interpreter::~Interpreter()
81
+ {
82
+ delete output;
83
+ };
84
+
85
+ int Interpreter::start()
86
+ {
87
+ return 0;
88
+ }
89
+
90
+ void Interpreter::stop()
91
+ {
92
+ }
93
+