nabaztag_hack_kit 0.0.2
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.
- data/.gitignore +7 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/README.md +119 -0
- data/Rakefile +21 -0
- data/bin/mtl_comp +41 -0
- data/bin/mtl_merge +22 -0
- data/bin/mtl_simu +40 -0
- data/bytecode/lib/buffer.mtl +109 -0
- data/bytecode/lib/button.mtl +27 -0
- data/bytecode/lib/data_helper.mtl +88 -0
- data/bytecode/lib/ear.mtl +90 -0
- data/bytecode/lib/led.mtl +33 -0
- data/bytecode/lib/rfid.mtl +50 -0
- data/bytecode/main.mtl +129 -0
- data/config.ru +6 -0
- data/ext/bytecode/Commands.md +172 -0
- data/ext/bytecode/Docs.md +488 -0
- data/ext/bytecode/README.md +5 -0
- data/ext/bytecode/lib/arp.mtl +159 -0
- data/ext/bytecode/lib/cfg.mtl +74 -0
- data/ext/bytecode/lib/choreos.mtl +1487 -0
- data/ext/bytecode/lib/dhcp.mtl +152 -0
- data/ext/bytecode/lib/dns.mtl +89 -0
- data/ext/bytecode/lib/http.mtl +84 -0
- data/ext/bytecode/lib/tcp.mtl +340 -0
- data/ext/bytecode/lib/udp.mtl +49 -0
- data/ext/bytecode/lib/util.mtl +74 -0
- data/ext/bytecode/lib/var.mtl +15 -0
- data/ext/bytecode/lib/wifi.mtl +243 -0
- data/ext/bytecode/nominal-ping.mtl +5828 -0
- data/ext/mtl/Makefile +42 -0
- data/ext/mtl/README.md +13 -0
- data/ext/mtl/bc.cpp +1891 -0
- data/ext/mtl/conf.bin.sans_password +0 -0
- data/ext/mtl/config.txt +5 -0
- data/ext/mtl/dumpbc.c +2566 -0
- data/ext/mtl/extconf.rb +1 -0
- data/ext/mtl/linux_simu.c +271 -0
- data/ext/mtl/linux_simuaudio.c +16 -0
- data/ext/mtl/linux_simuaudio.h +18 -0
- data/ext/mtl/linux_simunet.c +620 -0
- data/ext/mtl/linux_simunet.h +7 -0
- data/ext/mtl/log.c +297 -0
- data/ext/mtl/log.h +20 -0
- data/ext/mtl/main_compiler.cpp +104 -0
- data/ext/mtl/main_simu.cpp +221 -0
- data/ext/mtl/mp3/GTKANAL.H +97 -0
- data/ext/mtl/mp3/LAYER3.C +2090 -0
- data/ext/mtl/mp3/TABINIT.C +82 -0
- data/ext/mtl/mp3/common.c +265 -0
- data/ext/mtl/mp3/dct64_i386.c +316 -0
- data/ext/mtl/mp3/decode_i386.c +155 -0
- data/ext/mtl/mp3/huffman.h +332 -0
- data/ext/mtl/mp3/interface.c +258 -0
- data/ext/mtl/mp3/mpg123.h +182 -0
- data/ext/mtl/mp3/mpglib.h +44 -0
- data/ext/mtl/properties.c +293 -0
- data/ext/mtl/properties.h +10 -0
- data/ext/mtl/simu.c +750 -0
- data/ext/mtl/simuaudio.c +662 -0
- data/ext/mtl/simuaudio.h +74 -0
- data/ext/mtl/simunet.c +400 -0
- data/ext/mtl/simunet.h +30 -0
- data/ext/mtl/utils/correct_const.sh +34 -0
- data/ext/mtl/vaudio.c +677 -0
- data/ext/mtl/vaudio.h +46 -0
- data/ext/mtl/vbc.h +160 -0
- data/ext/mtl/vbc_str.h +166 -0
- data/ext/mtl/vcomp/Makefile +29 -0
- data/ext/mtl/vcomp/bootstrap.cpp +89 -0
- data/ext/mtl/vcomp/compiler.cpp +470 -0
- data/ext/mtl/vcomp/compiler.h +200 -0
- data/ext/mtl/vcomp/compiler_file.cpp +929 -0
- data/ext/mtl/vcomp/compiler_prog.cpp +250 -0
- data/ext/mtl/vcomp/compiler_term.cpp +1053 -0
- data/ext/mtl/vcomp/compiler_type.cpp +872 -0
- data/ext/mtl/vcomp/compiler_var.cpp +289 -0
- data/ext/mtl/vcomp/file.cpp +79 -0
- data/ext/mtl/vcomp/file.h +39 -0
- data/ext/mtl/vcomp/filesystem.h +14 -0
- data/ext/mtl/vcomp/interpreter.cpp +85 -0
- data/ext/mtl/vcomp/interpreter.h +121 -0
- data/ext/mtl/vcomp/memory.cpp +241 -0
- data/ext/mtl/vcomp/memory.h +326 -0
- data/ext/mtl/vcomp/param.h +95 -0
- data/ext/mtl/vcomp/parser.cpp +427 -0
- data/ext/mtl/vcomp/parser.h +97 -0
- data/ext/mtl/vcomp/parser_xml.cpp +124 -0
- data/ext/mtl/vcomp/prodbuffer.cpp +125 -0
- data/ext/mtl/vcomp/prodbuffer.h +42 -0
- data/ext/mtl/vcomp/resource.h +17 -0
- data/ext/mtl/vcomp/stdlib_core.cpp +122 -0
- data/ext/mtl/vcomp/terminal.cpp +73 -0
- data/ext/mtl/vcomp/terminal.h +30 -0
- data/ext/mtl/vcomp/util.cpp +48 -0
- data/ext/mtl/vcomp/util.h +31 -0
- data/ext/mtl/vinterp.c +1349 -0
- data/ext/mtl/vinterp.h +11 -0
- data/ext/mtl/vloader.c +127 -0
- data/ext/mtl/vloader.h +31 -0
- data/ext/mtl/vlog.c +589 -0
- data/ext/mtl/vlog.h +69 -0
- data/ext/mtl/vmem.c +424 -0
- data/ext/mtl/vmem.h +107 -0
- data/ext/mtl/vnet.c +255 -0
- data/ext/mtl/vnet.h +19 -0
- data/lib/nabaztag_hack_kit/message/api.rb +39 -0
- data/lib/nabaztag_hack_kit/message/helper.rb +39 -0
- data/lib/nabaztag_hack_kit/message.rb +36 -0
- data/lib/nabaztag_hack_kit/server.rb +50 -0
- data/lib/nabaztag_hack_kit/version.rb +3 -0
- data/lib/nabaztag_hack_kit.rb +4 -0
- data/nabaztag_hack_kit.gemspec +29 -0
- data/public/bytecode.bin +0 -0
- data/test/bytecode/helper.mtl +60 -0
- data/test/bytecode/native.mtl +28 -0
- data/test/bytecode/test.mtl +221 -0
- data/test/spec_helper.rb +5 -0
- data/test/unit/message_spec.rb +56 -0
- metadata +209 -0
@@ -0,0 +1,289 @@
|
|
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
|
+
|
11
|
+
#include "param.h"
|
12
|
+
#include "terminal.h"
|
13
|
+
#include "memory.h"
|
14
|
+
#include "parser.h"
|
15
|
+
#include "prodbuffer.h"
|
16
|
+
#include "compiler.h"
|
17
|
+
#include "interpreter.h"
|
18
|
+
|
19
|
+
|
20
|
+
int Compiler::parseval()
|
21
|
+
{
|
22
|
+
int k;
|
23
|
+
|
24
|
+
if (k=parseval3()) return k;
|
25
|
+
|
26
|
+
if (!parser->next(0)) return 0;
|
27
|
+
if (strcmp(parser->token,"::"))
|
28
|
+
{
|
29
|
+
parser->giveback();
|
30
|
+
return 0;
|
31
|
+
}
|
32
|
+
if (k=parseval()) return k; // r�cursion
|
33
|
+
|
34
|
+
if (k=createnodetype(TYPENAME_LIST)) return k;
|
35
|
+
if (k=createnodetype(TYPENAME_UNDEF)) return k; // noeud �lement
|
36
|
+
TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0)); // attachement du noeud �l�ment au noeud list
|
37
|
+
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,4)))) return k; // unification �lement
|
38
|
+
if (k=unif(VALTOPNT(STACKGET(m,1)),VALTOPNT(STACKGET(m,2)))) return k; // unification list
|
39
|
+
STACKSET(m,4,STACKGET(m,1)); // remplacement du type
|
40
|
+
|
41
|
+
int* p=MALLOCCLEAR(m,LIST_LENGTH); // cr�ation du tuple liste
|
42
|
+
if (!p) return MTLERR_OM;
|
43
|
+
TABSET(m,p,LIST_VAL,STACKGET(m,5));
|
44
|
+
TABSET(m,p,LIST_NEXT,STACKGET(m,3));
|
45
|
+
STACKSET(m,5,PNTTOVAL(p));
|
46
|
+
STACKDROPN(m,4);
|
47
|
+
return 0;
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
int Compiler::parseval3()
|
52
|
+
{
|
53
|
+
int k,op,typ;
|
54
|
+
|
55
|
+
if (k=parseval4()) return k;
|
56
|
+
while(1)
|
57
|
+
{
|
58
|
+
if (!parser->next(0)) return 0;
|
59
|
+
if (!strcmp(parser->token,"+")) { op=OPadd; typ=1;}
|
60
|
+
else if (!strcmp(parser->token,"-")) { op=OPsub; typ=1;}
|
61
|
+
else
|
62
|
+
{
|
63
|
+
parser->giveback();
|
64
|
+
return 0;
|
65
|
+
}
|
66
|
+
if (k=parseval4()) return k;
|
67
|
+
if (op==OPadd) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))+VALTOINT(STACKGET(m,1))));
|
68
|
+
else if (op==OPsub) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))-VALTOINT(STACKGET(m,1))));
|
69
|
+
int* ptyp;
|
70
|
+
if (typ==1) ptyp=VALTOPNT(TABGET(stdtypes,STDTYPE_I));
|
71
|
+
if (k=unif(VALTOPNT(STACKGET(m,0)),ptyp)) return k;
|
72
|
+
if (k=unif(VALTOPNT(STACKGET(m,2)),ptyp)) return k;
|
73
|
+
STACKDROPN(m,2);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
int Compiler::parseval4()
|
78
|
+
{
|
79
|
+
int k,op,typ;
|
80
|
+
|
81
|
+
if (k=parseval5()) return k;
|
82
|
+
while(1)
|
83
|
+
{
|
84
|
+
if (!parser->next(0)) return 0;
|
85
|
+
if (!strcmp(parser->token,"*")) { op=OPmul; typ=1;}
|
86
|
+
else if (!strcmp(parser->token,"/")) { op=OPdiv; typ=1;}
|
87
|
+
else if (!strcmp(parser->token,"%")) { op=OPmod; typ=1;}
|
88
|
+
else
|
89
|
+
{
|
90
|
+
parser->giveback();
|
91
|
+
return 0;
|
92
|
+
}
|
93
|
+
if (k=parseval5()) return k;
|
94
|
+
|
95
|
+
if (op==OPmul) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))*VALTOINT(STACKGET(m,1))));
|
96
|
+
else if (op==OPdiv)
|
97
|
+
{
|
98
|
+
if (VALTOINT(STACKGET(m,1))==0) return MTLERR_DIV;
|
99
|
+
STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))/VALTOINT(STACKGET(m,1))));
|
100
|
+
}
|
101
|
+
else if (op==OPmod) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))%VALTOINT(STACKGET(m,1))));
|
102
|
+
int* ptyp;
|
103
|
+
if (typ==1) ptyp=VALTOPNT(TABGET(stdtypes,STDTYPE_I));
|
104
|
+
if (k=unif(VALTOPNT(STACKGET(m,0)),ptyp)) return k;
|
105
|
+
if (k=unif(VALTOPNT(STACKGET(m,2)),ptyp)) return k;
|
106
|
+
STACKDROPN(m,2);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
int Compiler::parseval5()
|
111
|
+
{
|
112
|
+
int k,op;
|
113
|
+
|
114
|
+
if (k=parseval6()) return k;
|
115
|
+
while(1)
|
116
|
+
{
|
117
|
+
if (!parser->next(0)) return 0;
|
118
|
+
if (!strcmp(parser->token,"&")) op=OPand;
|
119
|
+
else if (!strcmp(parser->token,"|")) op=OPor;
|
120
|
+
else if (!strcmp(parser->token,"^")) op=OPeor;
|
121
|
+
else if (!strcmp(parser->token,"<<")) op=OPshl;
|
122
|
+
else if (!strcmp(parser->token,">>")) op=OPshr;
|
123
|
+
else
|
124
|
+
{
|
125
|
+
parser->giveback();
|
126
|
+
return 0;
|
127
|
+
}
|
128
|
+
if (k=parseval6()) return k;
|
129
|
+
|
130
|
+
if (op==OPand) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))&VALTOINT(STACKGET(m,1))));
|
131
|
+
else if (op==OPor) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))|VALTOINT(STACKGET(m,1))));
|
132
|
+
else if (op==OPeor) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))^VALTOINT(STACKGET(m,1))));
|
133
|
+
else if (op==OPshl) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))<<VALTOINT(STACKGET(m,1))));
|
134
|
+
else if (op==OPshr) STACKSET(m,3,INTTOVAL(VALTOINT(STACKGET(m,3))>>VALTOINT(STACKGET(m,1))));
|
135
|
+
|
136
|
+
int* ptyp=VALTOPNT(TABGET(stdtypes,STDTYPE_I));
|
137
|
+
if (k=unif(VALTOPNT(STACKGET(m,0)),ptyp)) return k;
|
138
|
+
if (k=unif(VALTOPNT(STACKGET(m,2)),ptyp)) return k;
|
139
|
+
STACKDROPN(m,2);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
int Compiler::parseval6()
|
144
|
+
{
|
145
|
+
int k;
|
146
|
+
|
147
|
+
if (!parser->next(0)) return parseval7();
|
148
|
+
|
149
|
+
if (!strcmp(parser->token,"-"))
|
150
|
+
{
|
151
|
+
if (!parser->next(0)) return parseval6();
|
152
|
+
if (isdecimal(parser->token)) // gestion des entiers
|
153
|
+
{
|
154
|
+
int i=-mtl_atoi(parser->token);
|
155
|
+
if (k=STACKPUSH(m,INTTOVAL(i))) return k;
|
156
|
+
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
|
157
|
+
}
|
158
|
+
parser->giveback();
|
159
|
+
if (k=parseval6()) return k;
|
160
|
+
STACKSET(m,1,INTTOVAL(-VALTOINT(STACKGET(m,0))));
|
161
|
+
return unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(TABGET(stdtypes,STDTYPE_I)));
|
162
|
+
}
|
163
|
+
else if (!strcmp(parser->token,"~"))
|
164
|
+
{
|
165
|
+
if (k=parseval6()) return k;
|
166
|
+
STACKSET(m,1,INTTOVAL(~VALTOINT(STACKGET(m,0))));
|
167
|
+
return unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(TABGET(stdtypes,STDTYPE_I)));
|
168
|
+
}
|
169
|
+
parser->giveback();
|
170
|
+
return parseval7();
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
int Compiler::parseval7()
|
175
|
+
{
|
176
|
+
int k;
|
177
|
+
|
178
|
+
if (!parser->next(0))
|
179
|
+
{
|
180
|
+
PRINTF(m)(LOG_COMPILER,"Compiler : term expected (found EOF)\n");
|
181
|
+
return MTLERR_SN;
|
182
|
+
}
|
183
|
+
if (!strcmp(parser->token,"(")) // gestion des parenth�ses
|
184
|
+
{
|
185
|
+
if (k=parseval()) return k;
|
186
|
+
return parser->parsekeyword(")");
|
187
|
+
}
|
188
|
+
else if (!strcmp(parser->token,"[")) // gestion des tuples
|
189
|
+
{
|
190
|
+
int nval=0;
|
191
|
+
if (k=STACKPUSH(m,NIL)) return k; // valeur finale
|
192
|
+
if (k=STACKPUSH(m,NIL)) return k; // type final
|
193
|
+
int sref=STACKREF(m);
|
194
|
+
while(1)
|
195
|
+
{
|
196
|
+
if (!parser->next(0))
|
197
|
+
{
|
198
|
+
PRINTF(m)(LOG_COMPILER,"Compiler : ']' expected (found EOF)\n");
|
199
|
+
return MTLERR_SN;
|
200
|
+
}
|
201
|
+
if (!strcmp(parser->token,"]"))
|
202
|
+
{
|
203
|
+
int* p=MALLOCCLEAR(m,nval); // cr�ation du tuple liste
|
204
|
+
if (!p) return MTLERR_OM;
|
205
|
+
int i;
|
206
|
+
for(i=0;i<nval;i++) TABSET(m,p,i,STACKGET(m,(nval-i)*2-1));
|
207
|
+
STACKSETFROMREF(m,sref,1,PNTTOVAL(p));
|
208
|
+
if (k=createnodetupleval(nval)) return k;
|
209
|
+
STACKSETFROMREF(m,sref,0,STACKPULL(m));
|
210
|
+
STACKRESTOREREF(m,sref);
|
211
|
+
return 0;
|
212
|
+
}
|
213
|
+
parser->giveback();
|
214
|
+
if (k=parseval()) return k;
|
215
|
+
nval++;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
else if (!strcmp(parser->token,"{")) // gestion des tableaux
|
219
|
+
{
|
220
|
+
int nval=0;
|
221
|
+
if (k=STACKPUSH(m,NIL)) return k; // valeur finale
|
222
|
+
if (k=createnodetype(TYPENAME_TAB)) return k; // type final
|
223
|
+
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
224
|
+
TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0));
|
225
|
+
int* p=VALTOPNT(STACKPULL(m));
|
226
|
+
|
227
|
+
while(1)
|
228
|
+
{
|
229
|
+
if (!parser->next(0))
|
230
|
+
{
|
231
|
+
PRINTF(m)(LOG_COMPILER,"Compiler : '}' expected (found EOF)\n");
|
232
|
+
return MTLERR_SN;
|
233
|
+
}
|
234
|
+
if (!strcmp(parser->token,"}"))
|
235
|
+
{
|
236
|
+
|
237
|
+
if (k=DEFTAB(m,nval)) return k;
|
238
|
+
|
239
|
+
STACKSET(m,2,STACKGET(m,0)); // report de la valeur du tableau
|
240
|
+
STACKDROP(m);
|
241
|
+
return 0;
|
242
|
+
}
|
243
|
+
parser->giveback();
|
244
|
+
if (k=parseval()) return k;
|
245
|
+
if (k=unif(VALTOPNT(STACKGET(m,0)),p)) return k;
|
246
|
+
STACKDROP(m);
|
247
|
+
nval++;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
else if (!strcmp(parser->token,"nil")) // gestion du nil
|
251
|
+
{
|
252
|
+
if (k=STACKPUSH(m,NIL)) return k; // valeur
|
253
|
+
return createnodetype(TYPENAME_WEAK);
|
254
|
+
}
|
255
|
+
else if (!strcmp(parser->token,"'")) // gestion des 'char
|
256
|
+
{
|
257
|
+
if (!parser->next(0))
|
258
|
+
{
|
259
|
+
PRINTF(m)(LOG_COMPILER,"Compiler : 'char expected (found EOF)\n");
|
260
|
+
return MTLERR_SN;
|
261
|
+
}
|
262
|
+
if (k=STACKPUSH(m,INTTOVAL(parser->token[0]&255))) return k; // valeur
|
263
|
+
if (k=parser->parsekeyword("'")) return k;
|
264
|
+
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
|
265
|
+
}
|
266
|
+
else if (isdecimal(parser->token)) // gestion des entiers
|
267
|
+
{
|
268
|
+
int i=mtl_atoi(parser->token);
|
269
|
+
if (k=STACKPUSH(m,INTTOVAL(i))) return k; // valeur
|
270
|
+
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
|
271
|
+
}
|
272
|
+
else if ((parser->token[0]=='0')&&(parser->token[1]=='x')
|
273
|
+
&&(ishexadecimal(parser->token+2))) // gestion des entiers
|
274
|
+
{
|
275
|
+
int i=mtl_htoi(parser->token+2);
|
276
|
+
if (k=STACKPUSH(m,INTTOVAL(i))) return k; // valeur
|
277
|
+
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
|
278
|
+
}
|
279
|
+
else if (parser->token[0]=='"') // gestion des chaines
|
280
|
+
{
|
281
|
+
if (k=parser->getstring(m,'"')) return k;
|
282
|
+
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_S));
|
283
|
+
}
|
284
|
+
else
|
285
|
+
{
|
286
|
+
PRINTF(m)(LOG_COMPILER,"Compiler : unexpected term '%s'\n",parser->token);
|
287
|
+
return MTLERR_SN;
|
288
|
+
}
|
289
|
+
}
|
@@ -0,0 +1,79 @@
|
|
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) fclose(file);
|
32
|
+
delete internalbuffer;
|
33
|
+
}
|
34
|
+
|
35
|
+
int File::close()
|
36
|
+
{
|
37
|
+
if (file) fclose(file);
|
38
|
+
file=NULL;
|
39
|
+
return 0;
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
int File::openread(const char* name)
|
44
|
+
{
|
45
|
+
file=fopen(name,"rb");
|
46
|
+
if (file) return 0;
|
47
|
+
return -1;
|
48
|
+
}
|
49
|
+
|
50
|
+
char* File::getcontent(int *size)
|
51
|
+
{
|
52
|
+
if (file==NULL) return NULL;
|
53
|
+
|
54
|
+
fseek(file,0,SEEK_END);
|
55
|
+
*size=ftell(file);
|
56
|
+
fseek(file,0,SEEK_SET);
|
57
|
+
|
58
|
+
char* buffer;
|
59
|
+
buffer=new char[(*size)+1];
|
60
|
+
fread((void*)buffer,1,*size,file);
|
61
|
+
buffer[*size]=0;
|
62
|
+
close();
|
63
|
+
return buffer;
|
64
|
+
}
|
65
|
+
int File::openwrite(const char* name)
|
66
|
+
{
|
67
|
+
file=fopen(name,"wb");
|
68
|
+
if (file) return 0;
|
69
|
+
return -1;
|
70
|
+
}
|
71
|
+
int File::write(const char *outbuf,int size)
|
72
|
+
{
|
73
|
+
if (file==NULL) return 0;
|
74
|
+
|
75
|
+
int k=fwrite((void*)outbuf,1,size,file);
|
76
|
+
if (k<0) return -1;
|
77
|
+
fflush(file);
|
78
|
+
return 0;
|
79
|
+
}
|
@@ -0,0 +1,39 @@
|
|
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
|
+
|
10
|
+
|
11
|
+
#ifndef _FILE_
|
12
|
+
#define _FILE_
|
13
|
+
|
14
|
+
// commenter pour utiliser les fichiers windows
|
15
|
+
#include <stdio.h>
|
16
|
+
|
17
|
+
class FileSystem;
|
18
|
+
|
19
|
+
class File
|
20
|
+
{
|
21
|
+
private :
|
22
|
+
FileSystem *filesystem;
|
23
|
+
FILE *file;
|
24
|
+
char* internalbuffer;
|
25
|
+
int sizeinternalbuffer;
|
26
|
+
public:
|
27
|
+
File(FileSystem *fs);
|
28
|
+
~File();
|
29
|
+
|
30
|
+
int openread(const char* name);
|
31
|
+
char* getcontent(int *size);
|
32
|
+
|
33
|
+
int openwrite(const char* name);
|
34
|
+
int write(const char* outbuf,int size);
|
35
|
+
|
36
|
+
int close();
|
37
|
+
|
38
|
+
};
|
39
|
+
#endif
|
@@ -0,0 +1,85 @@
|
|
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
|
+
|
12
|
+
#include "param.h"
|
13
|
+
#include "terminal.h"
|
14
|
+
#include "prodbuffer.h"
|
15
|
+
#include "memory.h"
|
16
|
+
#include "util.h"
|
17
|
+
#include "interpreter.h"
|
18
|
+
#include "compiler.h"
|
19
|
+
|
20
|
+
#include"../vbc_str.h"
|
21
|
+
|
22
|
+
void displaybc(Memory* m,char* p)
|
23
|
+
{
|
24
|
+
PRINTF(m)(LOG_DEVCORE,"dump %x\n",p);
|
25
|
+
const char* spaces=" ";
|
26
|
+
int ind=0;
|
27
|
+
while(1)
|
28
|
+
{
|
29
|
+
int i=*p;
|
30
|
+
if ((i<0)||(i>=MaxOpcode)) PRINTF(m)(LOG_DEVCORE,"%4d ??\n",ind);
|
31
|
+
else if ((i==OPint))
|
32
|
+
{
|
33
|
+
p++;
|
34
|
+
int v=(p[0]&255)+((p[1]&255)<<8)+((p[2]&255)<<16)+((p[3]&255)<<24);
|
35
|
+
PRINTF(m)(LOG_DEVCORE,"%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
|
36
|
+
ind+=4;
|
37
|
+
p+=3;
|
38
|
+
}
|
39
|
+
else if ((i==OPgoto)||(i==OPelse))
|
40
|
+
{
|
41
|
+
p++;
|
42
|
+
int v=(p[0]&255)+((p[1]&255)<<8);
|
43
|
+
PRINTF(m)(LOG_DEVCORE,"%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
|
44
|
+
ind+=2;
|
45
|
+
p+=1;
|
46
|
+
} else if ((i==OPgetlocalb)||(i==OPgetglobalb)||(i==OPfetchb)||(i==OPdeftabb)||(i==OPsetlocalb)||
|
47
|
+
(i==OPmktabb)||(i==OPsetstructb)||(i==OPcallrb)||(i==OPintb))
|
48
|
+
{
|
49
|
+
p++;
|
50
|
+
int v=p[0]&255;
|
51
|
+
PRINTF(m)(LOG_DEVCORE,"%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
|
52
|
+
ind++;
|
53
|
+
}
|
54
|
+
else if (i==OPret)
|
55
|
+
{
|
56
|
+
PRINTF(m)(LOG_DEVCORE,"%4d %s%s\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]));
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
else PRINTF(m)(LOG_DEVCORE,"%4d %s%s\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]));
|
60
|
+
ind++;
|
61
|
+
p++;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
Interpreter::Interpreter(Memory* memory)
|
67
|
+
{
|
68
|
+
m=memory;
|
69
|
+
output=new Prodbuffer();
|
70
|
+
};
|
71
|
+
|
72
|
+
Interpreter::~Interpreter()
|
73
|
+
{
|
74
|
+
delete output;
|
75
|
+
};
|
76
|
+
|
77
|
+
int Interpreter::start()
|
78
|
+
{
|
79
|
+
return 0;
|
80
|
+
}
|
81
|
+
|
82
|
+
void Interpreter::stop()
|
83
|
+
{
|
84
|
+
}
|
85
|
+
|
@@ -0,0 +1,121 @@
|
|
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
|
+
#ifndef _INTERPRETER_
|
10
|
+
#define _INTERPRETER_
|
11
|
+
|
12
|
+
|
13
|
+
class Memory;
|
14
|
+
class Prodbuffer;
|
15
|
+
|
16
|
+
|
17
|
+
class Interpreter
|
18
|
+
{
|
19
|
+
private:
|
20
|
+
Memory* m;
|
21
|
+
int callstack;
|
22
|
+
char *pc; // pointeur vers le prochain bytecode
|
23
|
+
char *bc; // pointeur vers le d�but du bytecode
|
24
|
+
int locals; // pointeur vers les variable locales dans la pile
|
25
|
+
int* globals; // pointeur vers les variable globales
|
26
|
+
|
27
|
+
public:
|
28
|
+
Prodbuffer* output;
|
29
|
+
|
30
|
+
Interpreter(Memory* memory);
|
31
|
+
~Interpreter();
|
32
|
+
int start();
|
33
|
+
void stop();
|
34
|
+
|
35
|
+
int go();
|
36
|
+
|
37
|
+
int TFCtest(char* p);
|
38
|
+
|
39
|
+
int BCexec();
|
40
|
+
int BCret();
|
41
|
+
int BCdrop();
|
42
|
+
int BCdup();
|
43
|
+
int BCnil();
|
44
|
+
int BCgetlocal();
|
45
|
+
int BCsetlocal();
|
46
|
+
int BCgetglobal();
|
47
|
+
int BCgetglobalb();
|
48
|
+
int BCint();
|
49
|
+
int BCgoto();
|
50
|
+
int BCelse();
|
51
|
+
int BCfetch();
|
52
|
+
int BCstore();
|
53
|
+
int BCdeftab();
|
54
|
+
int BCnop();
|
55
|
+
int BCadd();
|
56
|
+
int BCsub();
|
57
|
+
int BCmul();
|
58
|
+
int BCdiv();
|
59
|
+
int BCneg();
|
60
|
+
int BCand();
|
61
|
+
int BCor();
|
62
|
+
int BCeor();
|
63
|
+
int BCnot();
|
64
|
+
int BCshl();
|
65
|
+
int BCshr();
|
66
|
+
int BCeq();
|
67
|
+
int BCne();
|
68
|
+
int BClt();
|
69
|
+
int BCgt();
|
70
|
+
int BCle();
|
71
|
+
int BCge();
|
72
|
+
int BCnon();
|
73
|
+
int BCsearch();
|
74
|
+
int BCfloat();
|
75
|
+
int BCcall();
|
76
|
+
int BCaddf();
|
77
|
+
int BCsubf();
|
78
|
+
int BCmulf();
|
79
|
+
int BCdivf();
|
80
|
+
int BCnegf();
|
81
|
+
int BCltf();
|
82
|
+
int BCgtf();
|
83
|
+
int BClef();
|
84
|
+
int BCgef();
|
85
|
+
int BCsetlocal2();
|
86
|
+
int BCsetglobal2();
|
87
|
+
int BCexecnative();
|
88
|
+
int BCgetlocalb();
|
89
|
+
int BCfetchb();
|
90
|
+
int BCdeftabb();
|
91
|
+
int BCsetlocalb();
|
92
|
+
int BCfirst();
|
93
|
+
int BCmod();
|
94
|
+
int BCmktab();
|
95
|
+
int BCmktabb();
|
96
|
+
int BCsetstruct();
|
97
|
+
int BCsetstructb();
|
98
|
+
int BCcallr();
|
99
|
+
int BCcallrb();
|
100
|
+
int BCgetglobalval();
|
101
|
+
int BCgetglobalvalb();
|
102
|
+
int BCupdate();
|
103
|
+
int BCupdateb();
|
104
|
+
int BCintb();
|
105
|
+
|
106
|
+
};
|
107
|
+
|
108
|
+
typedef int (Interpreter::*BCfunction)();
|
109
|
+
typedef int (*EXTfunction)(void*);
|
110
|
+
|
111
|
+
#include"../vbc.h"
|
112
|
+
|
113
|
+
#define CALLSTACK_LENGTH 6 // taille de la callstack sans les variables locales
|
114
|
+
#define CALLSTACK_BC 0 // pointeur bytecode
|
115
|
+
#define CALLSTACK_PC 1 // index bytecode
|
116
|
+
#define CALLSTACK_REF 2 // table r�f�rences globales
|
117
|
+
#define CALLSTACK_PREV 3 // callstack pr�c�dente
|
118
|
+
#define CALLSTACK_NBARGS 4 // nombre d'arguments et variables globales
|
119
|
+
#define CALLSTACK_FUN 5 // pointeur vers la r�f�rence de la fonction en cours
|
120
|
+
|
121
|
+
#endif
|