nabaztag_hack_kit 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +4 -0
  5. data/README.md +119 -0
  6. data/Rakefile +21 -0
  7. data/bin/mtl_comp +41 -0
  8. data/bin/mtl_merge +22 -0
  9. data/bin/mtl_simu +40 -0
  10. data/bytecode/lib/buffer.mtl +109 -0
  11. data/bytecode/lib/button.mtl +27 -0
  12. data/bytecode/lib/data_helper.mtl +88 -0
  13. data/bytecode/lib/ear.mtl +90 -0
  14. data/bytecode/lib/led.mtl +33 -0
  15. data/bytecode/lib/rfid.mtl +50 -0
  16. data/bytecode/main.mtl +129 -0
  17. data/config.ru +6 -0
  18. data/ext/bytecode/Commands.md +172 -0
  19. data/ext/bytecode/Docs.md +488 -0
  20. data/ext/bytecode/README.md +5 -0
  21. data/ext/bytecode/lib/arp.mtl +159 -0
  22. data/ext/bytecode/lib/cfg.mtl +74 -0
  23. data/ext/bytecode/lib/choreos.mtl +1487 -0
  24. data/ext/bytecode/lib/dhcp.mtl +152 -0
  25. data/ext/bytecode/lib/dns.mtl +89 -0
  26. data/ext/bytecode/lib/http.mtl +84 -0
  27. data/ext/bytecode/lib/tcp.mtl +340 -0
  28. data/ext/bytecode/lib/udp.mtl +49 -0
  29. data/ext/bytecode/lib/util.mtl +74 -0
  30. data/ext/bytecode/lib/var.mtl +15 -0
  31. data/ext/bytecode/lib/wifi.mtl +243 -0
  32. data/ext/bytecode/nominal-ping.mtl +5828 -0
  33. data/ext/mtl/Makefile +42 -0
  34. data/ext/mtl/README.md +13 -0
  35. data/ext/mtl/bc.cpp +1891 -0
  36. data/ext/mtl/conf.bin.sans_password +0 -0
  37. data/ext/mtl/config.txt +5 -0
  38. data/ext/mtl/dumpbc.c +2566 -0
  39. data/ext/mtl/extconf.rb +1 -0
  40. data/ext/mtl/linux_simu.c +271 -0
  41. data/ext/mtl/linux_simuaudio.c +16 -0
  42. data/ext/mtl/linux_simuaudio.h +18 -0
  43. data/ext/mtl/linux_simunet.c +620 -0
  44. data/ext/mtl/linux_simunet.h +7 -0
  45. data/ext/mtl/log.c +297 -0
  46. data/ext/mtl/log.h +20 -0
  47. data/ext/mtl/main_compiler.cpp +104 -0
  48. data/ext/mtl/main_simu.cpp +221 -0
  49. data/ext/mtl/mp3/GTKANAL.H +97 -0
  50. data/ext/mtl/mp3/LAYER3.C +2090 -0
  51. data/ext/mtl/mp3/TABINIT.C +82 -0
  52. data/ext/mtl/mp3/common.c +265 -0
  53. data/ext/mtl/mp3/dct64_i386.c +316 -0
  54. data/ext/mtl/mp3/decode_i386.c +155 -0
  55. data/ext/mtl/mp3/huffman.h +332 -0
  56. data/ext/mtl/mp3/interface.c +258 -0
  57. data/ext/mtl/mp3/mpg123.h +182 -0
  58. data/ext/mtl/mp3/mpglib.h +44 -0
  59. data/ext/mtl/properties.c +293 -0
  60. data/ext/mtl/properties.h +10 -0
  61. data/ext/mtl/simu.c +750 -0
  62. data/ext/mtl/simuaudio.c +662 -0
  63. data/ext/mtl/simuaudio.h +74 -0
  64. data/ext/mtl/simunet.c +400 -0
  65. data/ext/mtl/simunet.h +30 -0
  66. data/ext/mtl/utils/correct_const.sh +34 -0
  67. data/ext/mtl/vaudio.c +677 -0
  68. data/ext/mtl/vaudio.h +46 -0
  69. data/ext/mtl/vbc.h +160 -0
  70. data/ext/mtl/vbc_str.h +166 -0
  71. data/ext/mtl/vcomp/Makefile +29 -0
  72. data/ext/mtl/vcomp/bootstrap.cpp +89 -0
  73. data/ext/mtl/vcomp/compiler.cpp +470 -0
  74. data/ext/mtl/vcomp/compiler.h +200 -0
  75. data/ext/mtl/vcomp/compiler_file.cpp +929 -0
  76. data/ext/mtl/vcomp/compiler_prog.cpp +250 -0
  77. data/ext/mtl/vcomp/compiler_term.cpp +1053 -0
  78. data/ext/mtl/vcomp/compiler_type.cpp +872 -0
  79. data/ext/mtl/vcomp/compiler_var.cpp +289 -0
  80. data/ext/mtl/vcomp/file.cpp +79 -0
  81. data/ext/mtl/vcomp/file.h +39 -0
  82. data/ext/mtl/vcomp/filesystem.h +14 -0
  83. data/ext/mtl/vcomp/interpreter.cpp +85 -0
  84. data/ext/mtl/vcomp/interpreter.h +121 -0
  85. data/ext/mtl/vcomp/memory.cpp +241 -0
  86. data/ext/mtl/vcomp/memory.h +326 -0
  87. data/ext/mtl/vcomp/param.h +95 -0
  88. data/ext/mtl/vcomp/parser.cpp +427 -0
  89. data/ext/mtl/vcomp/parser.h +97 -0
  90. data/ext/mtl/vcomp/parser_xml.cpp +124 -0
  91. data/ext/mtl/vcomp/prodbuffer.cpp +125 -0
  92. data/ext/mtl/vcomp/prodbuffer.h +42 -0
  93. data/ext/mtl/vcomp/resource.h +17 -0
  94. data/ext/mtl/vcomp/stdlib_core.cpp +122 -0
  95. data/ext/mtl/vcomp/terminal.cpp +73 -0
  96. data/ext/mtl/vcomp/terminal.h +30 -0
  97. data/ext/mtl/vcomp/util.cpp +48 -0
  98. data/ext/mtl/vcomp/util.h +31 -0
  99. data/ext/mtl/vinterp.c +1349 -0
  100. data/ext/mtl/vinterp.h +11 -0
  101. data/ext/mtl/vloader.c +127 -0
  102. data/ext/mtl/vloader.h +31 -0
  103. data/ext/mtl/vlog.c +589 -0
  104. data/ext/mtl/vlog.h +69 -0
  105. data/ext/mtl/vmem.c +424 -0
  106. data/ext/mtl/vmem.h +107 -0
  107. data/ext/mtl/vnet.c +255 -0
  108. data/ext/mtl/vnet.h +19 -0
  109. data/lib/nabaztag_hack_kit/message/api.rb +39 -0
  110. data/lib/nabaztag_hack_kit/message/helper.rb +39 -0
  111. data/lib/nabaztag_hack_kit/message.rb +36 -0
  112. data/lib/nabaztag_hack_kit/server.rb +50 -0
  113. data/lib/nabaztag_hack_kit/version.rb +3 -0
  114. data/lib/nabaztag_hack_kit.rb +4 -0
  115. data/nabaztag_hack_kit.gemspec +29 -0
  116. data/public/bytecode.bin +0 -0
  117. data/test/bytecode/helper.mtl +60 -0
  118. data/test/bytecode/native.mtl +28 -0
  119. data/test/bytecode/test.mtl +221 -0
  120. data/test/spec_helper.rb +5 -0
  121. data/test/unit/message_spec.rb +56 -0
  122. metadata +209 -0
@@ -0,0 +1,929 @@
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::recglobal(int val,Prodbuffer *b)
21
+ {
22
+ if (val==NIL)
23
+ {
24
+ b->addint(-1);
25
+ // printf("nil\n");
26
+ }
27
+ else if (ISVALPNT(val))
28
+ {
29
+ int *p=VALTOPNT(val);
30
+ if (HEADER_TYPE(p)==TYPE_TAB)
31
+ {
32
+ b->addint((TABLEN(p)<<2)+3);
33
+ // printf("tuple %d @ %x : %x\n",TABLEN(p),val,*p);
34
+ for(int i=0;i<TABLEN(p);i++) recglobal(TABGET(p,i),b);
35
+ }
36
+ else
37
+ {
38
+ b->addint((STRLEN(p)<<2)+1);
39
+ b->addstr(STRSTART(p),STRLEN(p));
40
+ // printf("'%s'\n",STRSTART(p));
41
+ }
42
+ }
43
+ else
44
+ {
45
+ b->addint(val);
46
+ // printf("%d\n",VALTOINT(val));
47
+ }
48
+ return 0;
49
+ }
50
+
51
+
52
+ /**
53
+ G�n�re le bytecode correspondant � la d�claration de toutes les
54
+ variables globales
55
+ */
56
+ int Compiler::recglobals(int vlab,Prodbuffer *b)
57
+ {
58
+ if (vlab==NIL) return -1;
59
+
60
+ int n=1+recglobals(TABGET(VALTOPNT(vlab),LABELLIST_NEXT),b);
61
+ int val=TABGET(VALTOPNT(vlab),LABELLIST_REF);
62
+
63
+ // printf("%d:%s ",n,STRSTART(VALTOPNT(TABGET(VALTOPNT(vlab),LABELLIST_NAME))));
64
+ // avant de l'enregistrer, on verifie si tout est correct
65
+ int* p;
66
+ p = searchref_nosetused(PNTTOVAL(newpackage),STRSTART(VALTOPNT(TABGET(VALTOPNT(vlab),LABELLIST_NAME))));
67
+ if (NULL != p)
68
+ {
69
+ if (VALTOINT(TABGET(p,REF_USED)) == 0)
70
+ {
71
+ PRINTF(m)(LOG_WARNING,"%s is declared but never used\n",
72
+ STRSTART(VALTOPNT(TABGET(VALTOPNT(vlab),LABELLIST_NAME))));
73
+ }
74
+ else if (VALTOINT(TABGET(p,REF_CODE)) == CODE_VAR)
75
+ {
76
+ if (VALTOINT(TABGET(p,REF_SET)) == 0)
77
+ {
78
+ if (VALTOINT(TABGET(p,REF_USED)) > VALTOINT(TABGET(p,REF_USED_IN_IFDEF)))
79
+ PRINTF(m)(LOG_WARNING,"%s never gets a value\n",
80
+ STRSTART(VALTOPNT(TABGET(VALTOPNT(vlab),LABELLIST_NAME))));
81
+ }
82
+ else if (VALTOINT(TABGET(p,REF_SET)) == 1)
83
+ PRINTF(m)(LOG_WARNING,"%s is only set once, at declaration. It should be a const.\n",
84
+ STRSTART(VALTOPNT(TABGET(VALTOPNT(vlab),LABELLIST_NAME))));
85
+ }
86
+ }
87
+
88
+ recglobal(val,b);
89
+ return n;
90
+ }
91
+
92
+ int Compiler::recbc(int vref,Prodbuffer *b,Prodbuffer *btab,int offset)
93
+ {
94
+ if (vref==NIL) return -1;
95
+ int f=recbc(TABGET(VALTOPNT(vref),REF_NEXTALL),b,btab,offset);
96
+ if (f<-1) return f;
97
+ if (VALTOINT(TABGET(VALTOPNT(vref),REF_CODE))<0) return f;
98
+ int nf=VALTOINT(TABGET(VALTOPNT(vref),REF_PACKAGE));
99
+ if (nf<=f) return f;
100
+ if (TABGET(VALTOPNT(vref),REF_VAL)==NIL)
101
+ {
102
+ printf("%s is EMPTY !!!\n",STRSTART(VALTOPNT(TABGET(VALTOPNT(vref),REF_NAME))));
103
+ return -2;
104
+ }
105
+ int *fun=VALTOPNT(TABGET(VALTOPNT(vref),REF_VAL));
106
+ int nloc=VALTOINT(TABGET(fun,FUN_NBLOCALS))-VALTOINT(TABGET(fun,FUN_NBARGS));
107
+ int nargs=VALTOINT(TABGET(fun,FUN_NBARGS));
108
+ int ipc=b->getsize()-offset;
109
+ btab->addint(ipc);
110
+ b->addchar(nargs);
111
+ b->addshort(nloc);
112
+ b->addstr(STRSTART(VALTOPNT(TABGET(fun,FUN_BC))),STRLEN(VALTOPNT(TABGET(fun,FUN_BC))));
113
+ printf("%d@%d:%s nargs=%d nlocals=%d / %d bytes\n",nf,ipc,STRSTART(VALTOPNT(TABGET(VALTOPNT(vref),REF_NAME))),nargs,nloc,STRLEN(VALTOPNT(TABGET(fun,FUN_BC))));
114
+ return nf;
115
+ }
116
+
117
+
118
+ // compilation
119
+ // [filename/src packages] -> [packages]
120
+ int Compiler::gocompile(int type)
121
+ {
122
+ int k;
123
+
124
+ if (STACKGET(m,0)==NIL)
125
+ {
126
+ STACKDROP(m);
127
+ return 0;
128
+ }
129
+ const char* name=STRSTART(VALTOPNT(STACKGET(m,0)));
130
+ if (type==COMPILE_FROMFILE)
131
+ {
132
+ parser=new Parser(m->term,m->filesystem,name);
133
+ PRINTF(m)(LOG_COMPILER,"Compiler : compiling file '%s'\n",name);
134
+ }
135
+ else
136
+ {
137
+ parser=new Parser(m->term,name);
138
+ name="...";
139
+ PRINTF(m)(LOG_COMPILER,"Compiler : compiling string buffer\n");
140
+ }
141
+
142
+ if (k=createpackage(name,4)) return k; // [package nom_fichier env]
143
+ TABSET(m,VALTOPNT(STACKGET(m,0)),PACK_NEXT,STACKGET(m,2));
144
+ STACKSET(m,2,STACKGET(m,0)); // [newenv nom_fichier newenv]
145
+ STACKDROPN(m,2); // [newenv]
146
+ newpackage=VALTOPNT(STACKGET(m,0));
147
+ // parsing
148
+
149
+ //### ici on doit pouvoir ajouter la liste des globales et la liste des fonctions
150
+ //### c'est ici �galement qu'on va r�initialiser la structure bc
151
+ if (k=STACKPUSH(m,NIL)) return k; // GLOBALS
152
+ globals=STACKREF(m);
153
+ ifuns=0;
154
+
155
+ k=parsefile(0);
156
+
157
+ //### c'est fait, on a le bytecode, la liste des fonctions, et la liste des globales
158
+ if (!k)
159
+ {
160
+ Prodbuffer* btab=new Prodbuffer();
161
+
162
+ int n=nblabels(globals);
163
+ brelease->addint(0);
164
+ recglobals(STACKGETFROMREF(m,globals,0),brelease);
165
+ brelease->setint(0,brelease->getsize());
166
+
167
+ int sizebc=brelease->getsize();
168
+ brelease->addint(0); // on pr�pare le champ pour la taille du bytecode
169
+ int* p=VALTOPNT(TABGET(newpackage,PACK_HACH));
170
+ int vref=TABGET(p,TABLEN(p)-1);
171
+ int nfun=recbc(vref,brelease,btab,sizebc+4);
172
+ if (nfun<0) return nfun;
173
+
174
+ brelease->setint(sizebc,brelease->getsize()-sizebc-4);
175
+ brelease->addshort(nfun+1);
176
+ brelease->addstr(btab->getstart(),btab->getsize());
177
+ delete btab;
178
+ }
179
+ if (k) parser->echoposition();
180
+ PRINTF(m)(LOG_COMPILER,"\n");
181
+ // dumppackage(STACKGET(m,0));
182
+ delete parser;
183
+ return k;
184
+ }
185
+
186
+
187
+ int Compiler::parsefile(int ifdef)
188
+ {
189
+ int k;
190
+
191
+ while(parser->next(0))
192
+ {
193
+ if (!strcmp(parser->token,"fun"))
194
+ {
195
+ if ((!parser->next(0))||(!islabel(parser->token)))
196
+ {
197
+ if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of function expected (found '%s')\n",parser->token);
198
+ else PRINTF(m)(LOG_COMPILER,"Compiler : name of function expected (found EOF)\n");
199
+ return MTLERR_SN;
200
+ }
201
+ if (k=STRPUSH(m,parser->token)) return k;
202
+ int* s=VALTOPNT(STACKGET(m,0));
203
+ if (k=parsefun())
204
+ {
205
+ PRINTF(m)(LOG_COMPILER,"Compiler : error compiling function '%s'\n",STRSTART(s));
206
+ return k;
207
+ }
208
+ }
209
+ else if (!strcmp(parser->token,"type"))
210
+ {
211
+ if ((!parser->next(0))||(!islabel(parser->token)))
212
+ {
213
+ if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of type expected (found '%s')\n",parser->token);
214
+ else PRINTF(m)(LOG_COMPILER,"Compiler : name of type expected (found EOF)\n");
215
+ return MTLERR_SN;
216
+ }
217
+ if (k=STRPUSH(m,parser->token)) return k;
218
+ int* s=VALTOPNT(STACKGET(m,0));
219
+
220
+ if (k=parsetype())
221
+ {
222
+ PRINTF(m)(LOG_COMPILER,"Compiler : error compiling type '%s'\n",STRSTART(s));
223
+ return k;
224
+ }
225
+ }
226
+ else if (!strcmp(parser->token,"var"))
227
+ {
228
+ if ((!parser->next(0))||(!islabel(parser->token)))
229
+ {
230
+ if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of reference expected (found '%s')\n",parser->token);
231
+ else PRINTF(m)(LOG_COMPILER,"Compiler : name of reference expected (found EOF)\n");
232
+ return MTLERR_SN;
233
+ }
234
+ if (k=STRPUSH(m,parser->token)) return k;
235
+ int* s=VALTOPNT(STACKGET(m,0));
236
+
237
+ if (k=parsevar())
238
+ {
239
+ PRINTF(m)(LOG_COMPILER,"Compiler : error compiling var '%s'\n",STRSTART(s));
240
+ return k;
241
+ }
242
+ }
243
+ else if (!strcmp(parser->token,"const"))
244
+ {
245
+ if ((!parser->next(0))||(!islabel(parser->token)))
246
+ {
247
+ if (parser->token)
248
+ PRINTF(m)(LOG_COMPILER,"Compiler : name of reference expected (found '%s')\n",parser->token);
249
+ else
250
+ PRINTF(m)(LOG_COMPILER,"Compiler : name of reference expected (found EOF)");
251
+ return MTLERR_SN;
252
+ }
253
+ if (k=STRPUSH(m,parser->token)) return k;
254
+ int *s=VALTOPNT(STACKGET(m,0));
255
+ if (k=parseconst())
256
+ {
257
+ PRINTF(m)(LOG_COMPILER,"Compiler : error compiling const '%s'\n",STRSTART(s));
258
+ return k;
259
+ }
260
+ }
261
+ else if (!strcmp(parser->token,"proto"))
262
+ {
263
+ if ((!parser->next(0))||(!islabel(parser->token)))
264
+ {
265
+ if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of function expected (found '%s')\n",parser->token);
266
+ else PRINTF(m)(LOG_COMPILER,"Compiler : name of function expected (found EOF)\n");
267
+ return MTLERR_SN;
268
+ }
269
+ if (k=STRPUSH(m,parser->token)) return k;
270
+ int* s=VALTOPNT(STACKGET(m,0));
271
+
272
+ if (k=parseproto())
273
+ {
274
+ PRINTF(m)(LOG_COMPILER,"Compiler : error compiling proto '%s'\n",STRSTART(s));
275
+ return k;
276
+ }
277
+ }
278
+ else if (!strcmp(parser->token,"ifdef"))
279
+ {
280
+ if (k=parseifdef(0)) return k;
281
+ }
282
+ else if (!strcmp(parser->token,"ifndef"))
283
+ {
284
+ if (k=parseifdef(1)) return k;
285
+ }
286
+ else if ((ifdef)&&(!strcmp(parser->token,"}")))
287
+ {
288
+ parser->giveback();
289
+ return 0;
290
+ }
291
+ else
292
+ {
293
+ PRINTF(m)(LOG_COMPILER,"Compiler : unknown token %s\n",parser->token);
294
+ return MTLERR_SN;
295
+ }
296
+ }
297
+ return 0;
298
+ }
299
+
300
+ int Compiler::skipifdef()
301
+ {
302
+ int n=0;
303
+ while(parser->next(0))
304
+ {
305
+ if (!strcmp(parser->token,"{")) n++;
306
+ else if (!strcmp(parser->token,"}"))
307
+ {
308
+ n--;
309
+ if (n<0) return 0;
310
+ }
311
+ }
312
+ PRINTF(m)(LOG_COMPILER,"Compiler : '}' expected (found EOF)\n");
313
+ return MTLERR_SN;
314
+ }
315
+
316
+ int Compiler::parseifdef(int ifndef)
317
+ {
318
+ int k;
319
+ if (!parser->next(0))
320
+ {
321
+ PRINTF(m)(LOG_COMPILER,"Compiler : label expected (found EOF)\n");
322
+ return MTLERR_SN;
323
+ }
324
+ if (!islabel(parser->token))
325
+ {
326
+ PRINTF(m)(LOG_COMPILER,"Compiler : label expected (found '%s')\n",parser->token);
327
+ return MTLERR_SN;
328
+ }
329
+ int first=1;
330
+
331
+ int *ref, *type;
332
+ if ((!(ref = searchref(PNTTOVAL(newpackage),parser->token)))&&(!(type = searchtype(PNTTOVAL(newpackage),parser->token))))
333
+ first=0;
334
+
335
+ // si c'est une variable on note qu'elle est utlilis� dans un ifdef
336
+ // �a nous permet de savoir, plus tard, si elle est seulement
337
+ // utilis�e dans un/des ifdef - dans ce cas elle n'a pas besoin de
338
+ // valeur - ou aussi autre part - dans ce cas elle a besoin d'�tre
339
+ // sett�e au moins une fois.
340
+ if (ref)
341
+ {
342
+ int curval = VALTOINT(TABGET(ref,REF_USED_IN_IFDEF));
343
+ TABSET(m,ref,REF_USED_IN_IFDEF,INTTOVAL(curval+1));
344
+ }
345
+
346
+ if (ifndef) first=!first;
347
+ if (k=parser->parsekeyword("{")) return k;
348
+ if (first)
349
+ {
350
+ parsefile(1);
351
+ if (k=parser->parsekeyword("}")) return k;
352
+ }
353
+ else if (k=skipifdef()) return k;
354
+ if (!parser->next(0)) return 0;
355
+ if (strcmp(parser->token,"else"))
356
+ {
357
+ parser->giveback();
358
+ return 0;
359
+ }
360
+ else
361
+ {
362
+ if (k=parser->parsekeyword("{")) return k;
363
+ if (!first)
364
+ {
365
+ parsefile(1);
366
+ if (k=parser->parsekeyword("}")) return k;
367
+ }
368
+ else if (k=skipifdef()) return k;
369
+ }
370
+ return 0;
371
+ }
372
+
373
+ void displaybc(Memory* m,char* src);
374
+
375
+
376
+ // compilation d'une fonction
377
+ // [name] -> 0
378
+ int Compiler::parsefun()
379
+ {
380
+ int k;
381
+ int* type_result;
382
+ // PRINTF(m)(LOG_DEVCORE,"fonction %s\n",STRSTART(VALTOPNT(STACKGET(m,0))));
383
+
384
+ char* name=STRSTART(VALTOPNT(STACKGET(m,0)));
385
+ // cr�ation des variables de travail
386
+ if (k=STACKPUSH(m,NIL)) return k; // LOCALS
387
+ locals=STACKREF(m);
388
+
389
+ if (k=createnodetype(TYPENAME_FUN)) return k;
390
+
391
+ // recherche des arguments
392
+ int narg=0;
393
+ do
394
+ {
395
+ if (!parser->next(0))
396
+ {
397
+ PRINTF(m)(LOG_COMPILER,"Compiler : argument or '=' expected (found EOF)\n");
398
+ return MTLERR_SN;
399
+ }
400
+ if (islabel(parser->token))
401
+ {
402
+ if (k=createnodetype(TYPENAME_UNDEF)) return k;
403
+ if (k=addlabel(locals,parser->token,INTTOVAL(narg++),STACKGET(m,0))) return k;
404
+ }
405
+ else if (strcmp(parser->token,"="))
406
+ {
407
+ PRINTF(m)(LOG_COMPILER,"Compiler : argument or '=' expected (found '%s')\n",parser->token);
408
+ return MTLERR_SN;
409
+ }
410
+ } while(strcmp(parser->token,"="));
411
+ // construction du type initial de la fonction
412
+ if (k=createnodetuple(narg)) return k;
413
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0)); // attachement du noeud tuple au noeud fun
414
+ STACKDROP(m);
415
+
416
+ if (k=createnodetype(TYPENAME_UNDEF)) return k; // noeud r�sultat
417
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH+1,STACKGET(m,0)); // attachement du noeud resultat au noeud fun
418
+ type_result=VALTOPNT(STACKPULL(m)); // on garde en m�moire le type du r�sultat
419
+ // ici : [type local global name]
420
+
421
+ // on cr�e le bloc fonction
422
+ newref=MALLOCCLEAR(m,REF_LENGTH);
423
+ if (!newref) return MTLERR_OM;
424
+ TABSET(m,newref,REF_TYPE,STACKPULL(m));
425
+ TABSET(m,newref,REF_NAME,STACKGET(m,1));
426
+ TABSET(m,newref,REF_CODE,INTTOVAL(narg));
427
+
428
+ // vient d'�tre d�clar�e, pas encore utilis�e
429
+ TABSET(m,newref,REF_USED,INTTOVAL(0));
430
+
431
+ k=findproto(PNTTOVAL(newpackage),newref);
432
+
433
+ TABSET(m,newref,REF_PACKAGE,(k!=NIL)?k:INTTOVAL(ifuns++));
434
+
435
+ if (k=STACKPUSH(m,PNTTOVAL(newref))) return MTLERR_OM; // [newref local global name]
436
+ addreftopackage(newref,newpackage);
437
+ STACKDROP(m);
438
+ // [local global name]
439
+
440
+ // on poursuit la compilation vers le corps de la fonction
441
+ nblocals=narg;
442
+
443
+ bc->reinit(); // initialisation de la production de bytecode
444
+
445
+ // [locals globals]
446
+
447
+ // parsing
448
+ if (k=parseprogram()) return k;
449
+
450
+ // [type locals globals]
451
+ // la pile contient le type du r�sultat de la fonction
452
+ if (k=parser->parsekeyword(";;")) return k;
453
+
454
+ // unifier le type r�sultat
455
+ if (k=unif(type_result,VALTOPNT(STACKGET(m,0)))) return k;
456
+ STACKDROP(m);
457
+ // [locals globals name]
458
+ // cr�er le bloc programme
459
+ int* fun=MALLOCCLEAR(m,FUN_LENGTH);
460
+ if (!fun) return MTLERR_OM;
461
+ TABSET(m,newref,REF_VAL,PNTTOVAL(fun));
462
+
463
+ TABSET(m,fun,FUN_NBARGS,INTTOVAL(narg));
464
+ TABSET(m,fun,FUN_NBLOCALS,INTTOVAL(nblocals));
465
+
466
+ // stocker le bytecode
467
+ bc->addchar(OPret);
468
+
469
+ if (k=STRPUSHBINARY(m,bc->getstart(),bc->getsize())) return k;
470
+ TABSET(m,fun,FUN_BC,STACKPULL(m));
471
+
472
+ if (!strcmp(name,"awcConnect"))
473
+ displaybc(m,STRSTART(VALTOPNT(TABGET(fun,FUN_BC))));
474
+
475
+ // construire le tuple des r�f�rences globales
476
+ // int* globalstuple=tuplefromlabels(globals);
477
+ // if (!globalstuple) return MTLERR_OM;
478
+ // TABSET(m,fun,FUN_REF,PNTTOVAL(globalstuple));
479
+ TABSET(m,fun,FUN_REFERENCE,PNTTOVAL(newref));
480
+
481
+ STACKDROPN(m,2);
482
+
483
+ // []
484
+
485
+ // chercher d'�ventuels prototypes
486
+ if (k=fillproto(PNTTOVAL(newpackage),newref)) return k;
487
+
488
+ outputbuf->reinit();
489
+ outputbuf->printf("Compiler : %s : ",STRSTART(VALTOPNT(TABGET(newref,REF_NAME))));
490
+ echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE)));
491
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
492
+
493
+ return 0;
494
+ }
495
+
496
+ // compilation d'une variable
497
+ // [name] -> 0
498
+ int Compiler::parsevar()
499
+ {
500
+ int k;
501
+ int hasvalue = 0;
502
+
503
+ if (!parser->next(0))
504
+ {
505
+ PRINTF(m)(LOG_COMPILER,"Compiler : ';;' expected (found EOF)\n");
506
+ return MTLERR_SN;
507
+ }
508
+ if (!strcmp(parser->token,"="))
509
+ {
510
+ if (k=parseval()) return k;
511
+ hasvalue = 1;
512
+ }
513
+ else
514
+ {
515
+ parser->giveback();
516
+ if (k=STACKPUSH(m,NIL)) return k;
517
+ if (k=createnodetype(TYPENAME_WEAK)) return k;
518
+ }
519
+ // [val type name]
520
+ if (k=parser->parsekeyword(";;")) return k;
521
+
522
+ int val=INTTOVAL(nblabels(globals));
523
+ if (k=addlabel(globals,STRSTART(VALTOPNT(STACKGET(m,2))),val,STACKGET(m,1))) return k; // enregistrement d'une nouvelle globale
524
+
525
+ // on cr�e le bloc fonction
526
+ newref=MALLOCCLEAR(m,REF_LENGTH);
527
+ if (!newref) return MTLERR_OM;
528
+ TABSET(m,newref,REF_TYPE,STACKPULL(m));
529
+ TABSET(m,newref,REF_VAL,STACKPULL(m));
530
+ TABSET(m,newref,REF_NAME,STACKPULL(m));
531
+ TABSET(m,newref,REF_CODE,INTTOVAL(CODE_VAR));
532
+
533
+ // la variable vient d'�tre cr��, elle n'est donc ni utilis�e ni modifi�e encore
534
+ TABSET(m,newref,REF_USED,INTTOVAL(0));
535
+ TABSET(m,newref,REF_SET,INTTOVAL(hasvalue));
536
+ TABSET(m,newref,REF_USED_IN_IFDEF,INTTOVAL(0));
537
+
538
+ TABSET(m,newref,REF_PACKAGE,val);
539
+
540
+ if (k=STACKPUSH(m,PNTTOVAL(newref))) return MTLERR_OM; // [newref]
541
+ addreftopackage(newref,newpackage);
542
+ STACKDROP(m);
543
+
544
+ outputbuf->reinit();
545
+ outputbuf->printf("Compiler : var %s : ",STRSTART(VALTOPNT(TABGET(newref,REF_NAME))));
546
+ echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE)));
547
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
548
+ return 0;
549
+ }
550
+
551
+
552
+ // compilation d'une constante (const var = val;;)
553
+ // [name] -> 0
554
+ int Compiler::parseconst()
555
+ {
556
+ int k;
557
+
558
+ if (k=parser->parsekeyword("=")) return k;
559
+ if (k=parseval()) return k;
560
+ if (k=parser->parsekeyword(";;")) return k;
561
+
562
+ int val=INTTOVAL(nblabels(globals));
563
+ if (k=addlabel(globals,STRSTART(VALTOPNT(STACKGET(m,2))),val,STACKGET(m,1))) return k; // enregistrement d'une nouvelle globale
564
+
565
+ // on cr�e le bloc fonction
566
+ newref=MALLOCCLEAR(m,REF_LENGTH);
567
+ if (!newref) return MTLERR_OM;
568
+ TABSET(m,newref,REF_TYPE,STACKPULL(m));
569
+ TABSET(m,newref,REF_VAL,STACKPULL(m));
570
+ TABSET(m,newref,REF_NAME,STACKPULL(m));
571
+ TABSET(m,newref,REF_CODE,INTTOVAL(CODE_CONST));
572
+
573
+ // la constante vient d'�tre cr��e, elle n'est donc pas utilis�e, mais elle a une valeur
574
+ TABSET(m,newref,REF_USED,INTTOVAL(0));
575
+ TABSET(m,newref,REF_SET,INTTOVAL(1));
576
+ TABSET(m,newref,REF_USED_IN_IFDEF,INTTOVAL(0));
577
+
578
+ TABSET(m,newref,REF_PACKAGE,val);
579
+
580
+ if (k=STACKPUSH(m,PNTTOVAL(newref))) return MTLERR_OM; // [newref]
581
+ addreftopackage(newref,newpackage);
582
+ STACKDROP(m);
583
+
584
+ outputbuf->reinit();
585
+ outputbuf->printf("Compiler : const %s : ",STRSTART(VALTOPNT(TABGET(newref,REF_NAME))));
586
+ echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE)));
587
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
588
+ return 0;
589
+ }
590
+
591
+
592
+ // compilation d'un prototype
593
+ // [name] -> 0
594
+ int Compiler::parseproto()
595
+ {
596
+ int k;
597
+
598
+ if (!parser->next(0))
599
+ {
600
+ PRINTF(m)(LOG_COMPILER,"Compiler : integer or '=' expected (found EOF)\n");
601
+ return MTLERR_SN;
602
+ }
603
+ int nbarg=-1;
604
+ if (!strcmp(parser->token,"="))
605
+ {
606
+ if (k=creategraph(parser,PNTTOVAL(newpackage),0)) return k;
607
+ int vp=STACKGET(m,0);
608
+ if (vp!=NIL)
609
+ {
610
+ int* p=VALTOPNT(vp);
611
+ if (TABGET(p,TYPEHEADER_CODE)==INTTOVAL(TYPENAME_FUN))
612
+ {
613
+ vp=TABGET(p,TYPEHEADER_LENGTH);
614
+ if (vp!=NIL)
615
+ {
616
+ int* p=VALTOPNT(vp);
617
+ if (TABGET(p,TYPEHEADER_CODE)==INTTOVAL(TYPENAME_TUPLE))
618
+ {
619
+ nbarg=TABLEN(p)-TYPEHEADER_LENGTH;
620
+ }
621
+ }
622
+ }
623
+ }
624
+ if (nbarg<0)
625
+ {
626
+ PRINTF(m)(LOG_COMPILER,"Compiler : function type expected\n");
627
+ return MTLERR_SN;
628
+ }
629
+ }
630
+ else if (isdecimal(parser->token))
631
+ {
632
+ nbarg=mtl_atoi(parser->token);
633
+
634
+ if (k=createnodetype(TYPENAME_FUN)) return k;
635
+
636
+ int i;for(i=0;i<nbarg;i++) if (k=createnodetype(TYPENAME_WEAK)) return k;
637
+ if (k=createnodetuple(nbarg)) return k;
638
+
639
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0)); // attachement du noeud tuple au noeud fun
640
+ STACKDROP(m);
641
+
642
+ if (k=createnodetype(TYPENAME_WEAK)) return k; // noeud r�sultat
643
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH+1,STACKGET(m,0)); // attachement du noeud resultat au noeud fun
644
+ STACKDROP(m);
645
+ }
646
+ if (nbarg<0)
647
+ {
648
+ PRINTF(m)(LOG_COMPILER,"Compiler : integer or '=' expected (found '%s')\n",parser->token);
649
+ return MTLERR_SN;
650
+ }
651
+ if (k=parser->parsekeyword(";;")) return k;
652
+ // on cr�e le bloc fonction
653
+ newref=MALLOCCLEAR(m,REF_LENGTH);
654
+ if (!newref) return MTLERR_OM;
655
+ TABSET(m,newref,REF_TYPE,STACKPULL(m));
656
+ TABSET(m,newref,REF_NAME,STACKPULL(m));
657
+ TABSET(m,newref,REF_CODE,INTTOVAL(nbarg));
658
+ TABSET(m,newref,REF_PACKAGE,INTTOVAL(ifuns++));
659
+ if (k=STACKPUSH(m,PNTTOVAL(newref))) return MTLERR_OM; // [newref]
660
+ addreftopackage(newref,newpackage);
661
+ STACKDROP(m);
662
+
663
+ outputbuf->reinit();
664
+ outputbuf->printf("Compiler : proto %s : ",STRSTART(VALTOPNT(TABGET(newref,REF_NAME))));
665
+ echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE)));
666
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
667
+ return 0;
668
+ }
669
+ // compilation d'un type
670
+ // [name] -> 0
671
+ int Compiler::parsetype()
672
+ {
673
+ int k;
674
+ // PRINTF(m)(LOG_DEVCORE,"type %s\n",STRSTART(VALTOPNT(STACKGET(m,0))));
675
+
676
+ char* name=STRSTART(VALTOPNT(STACKGET(m,0)));
677
+ // cr�ation des variables de travail
678
+ if (k=STACKPUSH(m,NIL)) return k; // LOCALS
679
+ locals=STACKREF(m);
680
+
681
+ newref=searchemptytype(PNTTOVAL(newpackage),name);
682
+ int mergetype=1;
683
+ if (newref)
684
+ {
685
+ if (k=createnodetypecore(TABGET(VALTOPNT(TABGET(newref,REF_TYPE)),TYPEHEADER_LENGTH+1))) return k;
686
+ }
687
+ else
688
+ {
689
+ mergetype=0;
690
+ if (k=createnodetypecore(STACKGET(m,1))) return k;
691
+ newref=MALLOCCLEAR(m,REF_LENGTH);
692
+ if (!newref) return MTLERR_OM;
693
+ TABSET(m,newref,REF_CODE,INTTOVAL(CODE_EMPTYTYPE));
694
+ TABSET(m,newref,REF_TYPE,STACKGET(m,0));
695
+ if (k=STACKPUSH(m,PNTTOVAL(newref))) return MTLERR_OM; // [newtyp local name]
696
+ addreftopackage(newref,newpackage);
697
+ STACKDROP(m);
698
+ }
699
+
700
+ int narg=0;
701
+ if (parser->next(0))
702
+ {
703
+ if (strcmp(parser->token,"(")) parser->giveback();
704
+ else
705
+ {
706
+ do
707
+ {
708
+ if (!parser->next(0))
709
+ {
710
+ PRINTF(m)(LOG_COMPILER,"Compiler : parameter or ')' expected (found EOF)\n");
711
+ return MTLERR_SN;
712
+ }
713
+ if (islabel(parser->token))
714
+ {
715
+ if (k=createnodetype(TYPENAME_UNDEF)) return k;
716
+ if (k=addlabel(locals,parser->token,STACKGET(m,0),INTTOVAL(narg++))) return k;
717
+ }
718
+ else if (strcmp(parser->token,")"))
719
+ {
720
+ PRINTF(m)(LOG_COMPILER,"Compiler : parameter or ')' expected (found '%s')\n",parser->token);
721
+ return MTLERR_SN;
722
+ }
723
+ } while(strcmp(parser->token,")"));
724
+ if (k=DEFTAB(m,narg)) return k;
725
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0));
726
+ STACKDROP(m);
727
+ }
728
+ }
729
+ if (!mergetype) STACKDROP(m);
730
+ else if (k=unif(VALTOPNT(STACKPULL(m)),VALTOPNT(TABGET(newref,REF_TYPE)))) return k;
731
+
732
+ if (!parser->next(0))
733
+ {
734
+ PRINTF(m)(LOG_COMPILER,"Compiler : '=' or ';;' expected (found EOF)\n");
735
+ return MTLERR_SN;
736
+ }
737
+ if (!strcmp(parser->token,"="))
738
+ {
739
+ if (!parser->next(0))
740
+ {
741
+ PRINTF(m)(LOG_COMPILER,"Compiler : uncomplete type definition (found EOF)\n");
742
+ return MTLERR_SN;
743
+ }
744
+ if (!strcmp(parser->token,"[")) return parsestruct();
745
+ parser->giveback();
746
+ return parsesum();
747
+ }
748
+ else if (!strcmp(parser->token,";;"))
749
+ {
750
+ STACKDROPN(m,2);
751
+ outputbuf->reinit();
752
+ outputbuf->printf("Compiler : uncompleted type : ");
753
+ echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE)));
754
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
755
+ return 0;
756
+ }
757
+ PRINTF(m)(LOG_COMPILER,"Compiler : '=' or ';;' expected (found '%s')\n",parser->token);
758
+ return MTLERR_SN;
759
+ }
760
+
761
+
762
+ // compilation d'une structure (le premier '[' a �t� lu)
763
+ // [locals nom]
764
+ int Compiler::parsestruct()
765
+ {
766
+ int k;
767
+
768
+ // on cr�e le bloc type
769
+ TABSET(m,newref,REF_VAL,INTTOVAL(0));
770
+ TABSET(m,newref,REF_CODE,INTTOVAL(CODE_STRUCT));
771
+ // [local name]
772
+
773
+ int loop=1;
774
+ do
775
+ {
776
+ if (!parser->next(0))
777
+ {
778
+ PRINTF(m)(LOG_COMPILER,"Compiler : field name or ']' expected (found EOF)\n");
779
+ return MTLERR_SN;
780
+ }
781
+ if (islabel(parser->token))
782
+ {
783
+ if (k=STRPUSH(m,parser->token)) return k;
784
+
785
+ // on cr�e le bloc champ
786
+ int* newfield=MALLOCCLEAR(m,REF_LENGTH);
787
+ if (!newfield) return MTLERR_OM;
788
+ TABSET(m,newfield,REF_NAME,STACKPULL(m));
789
+ TABSET(m,newfield,REF_CODE,INTTOVAL(CODE_FIELD));
790
+ if (k=STACKPUSH(m,PNTTOVAL(newfield))) return MTLERR_OM; // [newfield local name]
791
+ addreftopackage(newfield,newpackage);
792
+ STACKDROP(m);
793
+ // [local name]
794
+ if (k=STACKPUSH(m,TABGET(newref,REF_VAL))) return k;
795
+ if (k=STACKPUSH(m,PNTTOVAL(newref))) return k;
796
+ if (k=DEFTAB(m,FIELD_LENGTH)) return k;
797
+ TABSET(m,newfield,REF_VAL,STACKPULL(m));
798
+
799
+ TABSET(m,newref,REF_VAL,INTTOVAL(1+VALTOINT(TABGET(newref,REF_VAL)))); // incr�mentation
800
+
801
+ if (k=createnodetype(TYPENAME_FUN)) return k;
802
+ if (k=STACKPUSH(m,TABGET(newref,REF_TYPE))) return k;
803
+ if (k=createnodetuple(1)) return k;
804
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0)); // attachement du noeud tuple au noeud fun
805
+ STACKDROP(m);
806
+
807
+ if ((!parser->next(0))||(strcmp(parser->token,":")))
808
+ {
809
+ parser->giveback();
810
+ k=createnodetype(TYPENAME_WEAK);
811
+ }
812
+ else k=creategraph(parser,PNTTOVAL(newpackage),1,locals);
813
+ if (k) return k;
814
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH+1,STACKGET(m,0)); // attachement du noeud resultat au noeud fun
815
+ STACKDROP(m);
816
+ TABSET(m,newfield,REF_TYPE,STACKPULL(m));
817
+
818
+ outputbuf->reinit();
819
+ outputbuf->printf("Compiler : %s : ",STRSTART(VALTOPNT(TABGET(newfield,REF_NAME))));
820
+ echograph(outputbuf,VALTOPNT(TABGET(newfield,REF_TYPE)));
821
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
822
+ }
823
+ else if (!strcmp(parser->token,"]")) loop=0;
824
+ else
825
+ {
826
+ PRINTF(m)(LOG_COMPILER,"Compiler : field name or ']' expected (found '%s')\n",parser->token);
827
+ return MTLERR_SN;
828
+ }
829
+ } while(loop);
830
+ if (k=parser->parsekeyword(";;")) return k;
831
+
832
+ STACKDROPN(m,2);
833
+
834
+ outputbuf->reinit();
835
+ outputbuf->printf("Compiler : ");
836
+ echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE)));
837
+ outputbuf->printf(" : struct (%d)\n",VALTOINT(TABGET(newref,REF_VAL)));
838
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
839
+
840
+ return 0;
841
+ }
842
+
843
+ // compilation d'une somme
844
+ // [locals nom]
845
+ int Compiler::parsesum()
846
+ {
847
+ int k;
848
+
849
+ // on cr�e le bloc type
850
+ TABSET(m,newref,REF_VAL,INTTOVAL(0));
851
+ TABSET(m,newref,REF_CODE,INTTOVAL(CODE_SUM));
852
+ // [local name]
853
+
854
+ int loop=1;
855
+ do
856
+ {
857
+ if (!parser->next(0))
858
+ {
859
+ PRINTF(m)(LOG_COMPILER,"Compiler : constructor expected (found EOF)\n");
860
+ return MTLERR_SN;
861
+ }
862
+ if (islabel(parser->token))
863
+ {
864
+ if (k=STRPUSH(m,parser->token)) return k;
865
+
866
+ // on cr�e le bloc champ
867
+ int* newcons=MALLOCCLEAR(m,REF_LENGTH);
868
+ if (!newcons) return MTLERR_OM;
869
+ TABSET(m,newcons,REF_NAME,STACKPULL(m));
870
+ if (k=STACKPUSH(m,PNTTOVAL(newcons))) return MTLERR_OM; // [newcons local name]
871
+ addreftopackage(newcons,newpackage);
872
+ STACKDROP(m);
873
+ // [local name]
874
+ TABSET(m,newcons,REF_VAL,TABGET(newref,REF_VAL));
875
+ TABSET(m,newref,REF_VAL,INTTOVAL(1+VALTOINT(TABGET(newref,REF_VAL)))); // incr�mentation
876
+
877
+ if (k=createnodetype(TYPENAME_FUN)) return k;
878
+
879
+ if ((parser->next(0))&&((!strcmp(parser->token,"|"))||(!strcmp(parser->token,";;"))))
880
+ {
881
+ parser->giveback();
882
+ if (k=createnodetuple(0)) return k;
883
+ TABSET(m,newcons,REF_CODE,INTTOVAL(CODE_CONS0));
884
+ }
885
+ else
886
+ {
887
+ parser->giveback();
888
+ if (k=creategraph(parser,PNTTOVAL(newpackage),1,locals)) return k;
889
+ if (k=createnodetuple(1)) return k;
890
+ TABSET(m,newcons,REF_CODE,INTTOVAL(CODE_CONS));
891
+ }
892
+ TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0)); // attachement du noeud tuple au noeud fun
893
+ STACKDROP(m);
894
+ TABSET(m,VALTOPNT(STACKGET(m,0)),TYPEHEADER_LENGTH+1,TABGET(newref,REF_TYPE)); // attachement du type resultat au noeud fun
895
+ TABSET(m,newcons,REF_TYPE,STACKPULL(m));
896
+
897
+ outputbuf->reinit();
898
+ outputbuf->printf("Compiler : %s : ",STRSTART(VALTOPNT(TABGET(newcons,REF_NAME))));
899
+ echograph(outputbuf,VALTOPNT(TABGET(newcons,REF_TYPE)));
900
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
901
+ }
902
+ else
903
+ {
904
+ PRINTF(m)(LOG_COMPILER,"Compiler : constructor expected (found '%s')\n",parser->token);
905
+ return MTLERR_SN;
906
+ }
907
+
908
+ if (!parser->next(0))
909
+ {
910
+ PRINTF(m)(LOG_COMPILER,"Compiler : '|' or ';;' expected (found EOF)\n");
911
+ return MTLERR_SN;
912
+ }
913
+ if (!strcmp(parser->token,";;")) loop=0;
914
+ else if (strcmp(parser->token,"|"))
915
+ {
916
+ PRINTF(m)(LOG_COMPILER,"Compiler : '|' or ';;' expected (found '%s')\n",parser->token);
917
+ return MTLERR_SN;
918
+ }
919
+ } while(loop);
920
+ STACKDROPN(m,2);
921
+
922
+ outputbuf->reinit();
923
+ outputbuf->printf("Compiler : ");
924
+ echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE)));
925
+ outputbuf->printf(" : constructor\n");
926
+ PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart());
927
+
928
+ return 0;
929
+ }