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,313 @@
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 "memory.h"
16
+ #include "util.h"
17
+ #include "interpreter.h"
18
+
19
+ #define GCincPeriod 20
20
+
21
+
22
+ // Gestion de la pile
23
+ Stack::Stack()
24
+ {
25
+ base=NULL;
26
+ }
27
+ Stack::~Stack()
28
+ {
29
+ if (base)
30
+ {
31
+ delete base;
32
+ }
33
+ }
34
+
35
+ void Stack::dump(FILE *f)
36
+ {
37
+ const char* buf="stck";
38
+ fwrite((void*)buf,1,4,f);
39
+ fwrite((void*)&size,1,4,f);
40
+ fwrite((void*)&pp,1,4,f);
41
+ fwrite((void*)&base,1,4,f);
42
+ fwrite((void*)base,1,4*size,f);
43
+ }
44
+
45
+ void Stack::initialize(int s)
46
+ {
47
+ size=s;
48
+ base=new intptr_t[size];
49
+ pp=base;
50
+ }
51
+
52
+ int Stack::bigger(Memory* m)
53
+ {
54
+ int currentpp=pp-base;
55
+
56
+ size*=2;
57
+
58
+ intptr_t* newbase=new intptr_t[size];
59
+ if (!newbase)
60
+ {
61
+ PRINTF(m)(LOG_RUNTIME,"Stack : out of Stack Memory\n");
62
+ AbortMetal(m,1);
63
+ return MTLERR_OM; // impossible d'augmenter la taille de la pile
64
+ }
65
+ int i;
66
+ for(i=0; i<=currentpp; i++)
67
+ {
68
+ newbase[i]=base[i];
69
+ }
70
+ delete base;
71
+ base=newbase;
72
+ pp=&base[currentpp];
73
+ return 0;
74
+ }
75
+
76
+
77
+
78
+
79
+ // ajout d'une racine
80
+ intptr_t Memory::addroot(intptr_t *p)
81
+ {
82
+ intptr_t k;
83
+
84
+ if (k=push(PNTTOVAL(p)))
85
+ {
86
+ return k;
87
+ }
88
+ intptr_t* r=malloc(LIST_LENGTH,TYPE_TAB);
89
+ TABSET(this,r,LIST_VAL,PNTTOVAL(p));
90
+ TABSET(this,r,LIST_NEXT,root);
91
+ root=PNTTOVAL(r);
92
+ STACKDROP(this);
93
+ return 0;
94
+ }
95
+
96
+ // suppression d'une racine
97
+ void Memory::removeroot(intptr_t *p)
98
+ {
99
+ intptr_t* last=NULL; // pointeur vers le précédent maillon de la liste
100
+ intptr_t vq=root;
101
+ while(vq!=NIL)
102
+ {
103
+ intptr_t* q=VALTOPNT(vq);
104
+ if (TABGET(q,LIST_VAL)==PNTTOVAL(p))
105
+ {
106
+ if (last)
107
+ {
108
+ TABSET(this,last,LIST_NEXT,TABGET(q,LIST_NEXT));
109
+ }
110
+ else
111
+ {
112
+ root=TABGET(q,LIST_NEXT);
113
+ }
114
+ return;
115
+ }
116
+ last=q;
117
+ vq=TABGET(q,LIST_NEXT);
118
+ }
119
+ }
120
+
121
+ Memory::Memory(int size,Terminal *t,FileSystem *fs)
122
+ {
123
+ term=t;
124
+ filesystem=fs;
125
+ size0=size; // on retient la taille initiale, elle sert d'ordre de grandeur
126
+ gcincperiod=GCincPeriod;
127
+ abort=0;
128
+
129
+ util=new Util(this);
130
+ winutil=NULL;
131
+ // listing();
132
+ }
133
+
134
+ Memory::~Memory()
135
+ {
136
+ // if (winutil) delete winutil;
137
+ delete util;
138
+ }
139
+
140
+ void Memory::stop()
141
+ {
142
+ abort=1;
143
+ util->stop();
144
+ root=NIL;
145
+ stack.pp=0;
146
+ }
147
+
148
+ int Memory::start()
149
+ {
150
+ root=NIL;
151
+
152
+ stack.initialize(STACK_FIRST_SIZE);
153
+
154
+ PRINTF(this)(LOG_RUNTIME,"Metal Virtual Machine\n");
155
+ PRINTF(this)(LOG_RUNTIME,"V0.2 - Sylvain Huet - 2005\n");
156
+ PRINTF(this)(LOG_RUNTIME,"--------------------------\n");
157
+ return util->start();
158
+ }
159
+
160
+ void Memory::dump()
161
+ {
162
+ }
163
+
164
+
165
+ intptr_t* Memory::malloc(int size,int type)
166
+ {
167
+ intptr_t *p=NULL;
168
+
169
+ int blocsize=size+HEADER_LENGTH;
170
+ p=new intptr_t[blocsize];
171
+ if (!p)
172
+ {
173
+ return p;
174
+ }
175
+
176
+ HEADERSETSIZETYPE(p,blocsize,type);
177
+
178
+ return p;
179
+ }
180
+
181
+
182
+
183
+ intptr_t* Memory::mallocClear(int size)
184
+ {
185
+ intptr_t* p=malloc(size,TYPE_TAB);
186
+ if (!p)
187
+ {
188
+ return p;
189
+ }
190
+ int i;
191
+ for(i=0; i<size; i++)
192
+ {
193
+ TABSET(this,p,i,NIL);
194
+ }
195
+ return p;
196
+ }
197
+
198
+ // allocation de type TYPE_EXT (la fonction fun(pnt) sera appelée lors de l'oubli du bloc)
199
+ intptr_t* Memory::mallocExternal(void* pnt,FORGET fun)
200
+ {
201
+ intptr_t* p=malloc(2,TYPE_EXT);
202
+ if (!p)
203
+ {
204
+ return p;
205
+ }
206
+ TABSET(this,p,0,*((intptr_t*)pnt));
207
+ TABSET(this,p,1,*((intptr_t*)fun));
208
+ return p;
209
+ }
210
+
211
+ // allocation de type TYPE_EXT (la fonction fun(pnt) sera appelée lors de l'oubli du bloc)
212
+ intptr_t Memory::pushExternal(void* pnt,FORGET fun)
213
+ {
214
+ intptr_t* p=mallocExternal(pnt,fun);
215
+ if (!p)
216
+ {
217
+ return MTLERR_OM;
218
+ }
219
+ return push(PNTTOVAL(p));
220
+ }
221
+
222
+ intptr_t* Memory::storenosrc(int size)
223
+ {
224
+ // calcul de la taille d'un bloc pouvant contenir une certain nombre de caractères
225
+ // il faut 1 mot pour la taille et un octet nul final
226
+ int l=2+(size>>2);
227
+
228
+ intptr_t* p=malloc(l,TYPE_BINARY);
229
+ if (!p)
230
+ {
231
+ return p;
232
+ }
233
+ STRSETLEN(p,size);
234
+ STRSTART(p)[size]=0;
235
+ return p;
236
+ }
237
+
238
+ intptr_t* Memory::storebinary(const char *src,int size)
239
+ {
240
+ // calcul de la taille d'un bloc pouvant contenir une certain nombre de caractères
241
+ // il faut 1 mot pour la taille et un octet nul final
242
+ int l=2+(size>>2);
243
+
244
+ intptr_t* p=malloc(l,TYPE_BINARY);
245
+ if (!p)
246
+ {
247
+ return p;
248
+ }
249
+ STRSETLEN(p,size);
250
+ memcpy(STRSTART(p),src,size);
251
+ STRSTART(p)[size]=0;
252
+ return p;
253
+ }
254
+
255
+ intptr_t* Memory::storestring(const char *src)
256
+ {
257
+ return storebinary(src,strlen(src));
258
+ }
259
+
260
+ int Memory::deftab(int size)
261
+ {
262
+ intptr_t* p=malloc(size,TYPE_TAB);
263
+ if (!p)
264
+ {
265
+ return MTLERR_OM;
266
+ }
267
+ int i;
268
+ for(i=size-1; i>=0; i--)
269
+ {
270
+ TABSET(this,p,i,STACKPULL(this));
271
+ }
272
+ return push(PNTTOVAL(p));
273
+ }
274
+
275
+ const char* Memory::errorname(int err)
276
+ {
277
+ if (err==MTLERR_OM)
278
+ {
279
+ return "Out of memory";
280
+ }
281
+ else if (err==MTLERR_OP)
282
+ {
283
+ return "Unknown Operand";
284
+ }
285
+ else if (err==MTLERR_DIV)
286
+ {
287
+ return "Division by zero";
288
+ }
289
+ else if (err==MTLERR_RET)
290
+ {
291
+ return "Bad implementation on 'return'";
292
+ }
293
+ else if (err==MTLERR_NOFUN)
294
+ {
295
+ return "No function defined";
296
+ }
297
+ else if (err==MTLERR_SN)
298
+ {
299
+ return "Syntax error";
300
+ }
301
+ else if (err==MTLERR_TYPE)
302
+ {
303
+ return "Typechecking error";
304
+ }
305
+ else if (err==MTLERR_ABORT)
306
+ {
307
+ return "Application aborted";
308
+ }
309
+ else
310
+ {
311
+ return "Unknown error";
312
+ }
313
+ }