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.
- checksums.yaml +7 -0
- data/.gitignore +7 -2
- data/.gitmodules +3 -0
- data/.travis.yml +2 -2
- data/CHANGELOG.md +17 -2
- data/LICENSE +21 -0
- data/README.md +115 -44
- data/Rakefile +2 -6
- data/bytecode/{Commands.md → _docs/commands.md} +0 -0
- data/bytecode/{Docs.md → _docs/grammar.md} +0 -0
- data/bytecode/_docs/grammar.pdf +0 -0
- data/bytecode/{src → _original}/README.md +0 -0
- data/bytecode/{src → _original}/lib/arp.mtl +0 -0
- data/bytecode/{src → _original}/lib/cfg.mtl +0 -0
- data/bytecode/{src → _original}/lib/choreos.mtl +0 -0
- data/bytecode/{src → _original}/lib/dhcp.mtl +0 -0
- data/bytecode/{src → _original}/lib/dns.mtl +0 -0
- data/bytecode/{src → _original}/lib/http.mtl +0 -0
- data/bytecode/{src → _original}/lib/tcp.mtl +0 -0
- data/bytecode/{src → _original}/lib/udp.mtl +0 -0
- data/bytecode/{src → _original}/lib/util.mtl +0 -0
- data/bytecode/{src → _original}/lib/var.mtl +0 -0
- data/bytecode/{src → _original}/lib/wav.mtl +0 -0
- data/bytecode/{src → _original}/lib/wifi.mtl +0 -0
- data/bytecode/{src → _original}/nominal-ping.mtl +0 -0
- data/bytecode/main.mtl +11 -11
- data/bytecode/test/test.mtl +8 -8
- data/examples/basic/Gemfile +1 -3
- data/examples/basic/config.ru +14 -4
- data/examples/record/Gemfile +0 -5
- data/examples/record/{config.ru.example → config.ru} +2 -2
- data/examples/record/server.rb +0 -2
- data/ext/Makefile +10 -0
- data/ext/bin/mtl_comp +29 -0
- data/{bytecode → ext}/bin/mtl_merge +0 -0
- data/ext/bin/mtl_simu +29 -0
- data/{bytecode/src/mtl → ext}/extconf.rb +0 -0
- data/ext/mtl_linux/.gitignore +7 -0
- data/ext/mtl_linux/LICENSE +21 -0
- data/ext/mtl_linux/Makefile +116 -0
- data/ext/mtl_linux/MetalC.project +196 -0
- data/ext/mtl_linux/conf.bin +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux}/conf.bin.sans_password +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux}/config.txt +0 -0
- data/ext/mtl_linux/inc/log.h +21 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/properties.h +0 -0
- data/{bytecode/src/mtl/linux_simuaudio.h → ext/mtl_linux/inc/simu/linux/simuaudio.h} +0 -0
- data/{bytecode/src/mtl/linux_simunet.h → ext/mtl_linux/inc/simu/linux/simunet.h} +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simuaudio.h +18 -18
- data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simunet.h +0 -0
- data/ext/mtl_linux/inc/vcomp/compiler.h +200 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/file.h +11 -11
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/filesystem.h +0 -0
- data/ext/mtl_linux/inc/vcomp/interpreter.h +121 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/memory.h +120 -92
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/param.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/parser.h +27 -27
- data/ext/mtl_linux/inc/vcomp/prodbuffer.h +42 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/resource.h +1 -1
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/terminal.h +8 -8
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/util.h +7 -7
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vaudio.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vbc.h +1 -1
- data/ext/mtl_linux/inc/vm/vbc_str.h +167 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vinterp.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vloader.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vlog.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vmem.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vnet.h +0 -0
- data/ext/mtl_linux/nominal.mtl +3959 -0
- data/ext/mtl_linux/src/comp/main.cpp +123 -0
- data/ext/mtl_linux/src/simu/dumpbc.c +2566 -0
- data/ext/mtl_linux/src/simu/linux/main.cpp +288 -0
- data/ext/mtl_linux/src/simu/linux/simu.c +309 -0
- data/ext/mtl_linux/src/simu/linux/simuaudio.c +44 -0
- data/ext/mtl_linux/src/simu/linux/simunet.c +707 -0
- data/ext/mtl_linux/src/simu/log.c +340 -0
- data/ext/mtl_linux/src/simu/properties.c +368 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/GTKANAL.H +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/LAYER3.C +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/TABINIT.C +0 -0
- data/ext/mtl_linux/src/simu/win/mp3/common.c +302 -0
- data/ext/mtl_linux/src/simu/win/mp3/dct64_i386.c +316 -0
- data/ext/mtl_linux/src/simu/win/mp3/decode_i386.c +160 -0
- data/ext/mtl_linux/src/simu/win/mp3/huffman.h +332 -0
- data/ext/mtl_linux/src/simu/win/mp3/interface.c +276 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/mpg123.h +34 -30
- data/ext/mtl_linux/src/simu/win/mp3/mpglib.h +47 -0
- data/ext/mtl_linux/src/simu/win/simu.c +819 -0
- data/ext/mtl_linux/src/simu/win/simuaudio.c +787 -0
- data/ext/mtl_linux/src/simu/win/simunet.c +489 -0
- data/ext/mtl_linux/src/vcomp/bootstrap.cpp +95 -0
- data/ext/mtl_linux/src/vcomp/compiler.cpp +587 -0
- data/ext/mtl_linux/src/vcomp/compiler_file.cpp +1253 -0
- data/ext/mtl_linux/src/vcomp/compiler_prog.cpp +437 -0
- data/ext/mtl_linux/src/vcomp/compiler_term.cpp +1500 -0
- data/ext/mtl_linux/src/vcomp/compiler_type.cpp +1238 -0
- data/ext/mtl_linux/src/vcomp/compiler_var.cpp +502 -0
- data/ext/mtl_linux/src/vcomp/file.cpp +100 -0
- data/ext/mtl_linux/src/vcomp/interpreter.cpp +93 -0
- data/ext/mtl_linux/src/vcomp/memory.cpp +313 -0
- data/ext/mtl_linux/src/vcomp/parser.cpp +584 -0
- data/ext/mtl_linux/src/vcomp/parser_xml.cpp +137 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/prodbuffer.cpp +57 -36
- data/ext/mtl_linux/src/vcomp/stdlib_core.cpp +130 -0
- data/ext/mtl_linux/src/vcomp/terminal.cpp +80 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/util.cpp +18 -11
- data/ext/mtl_linux/src/vm/vaudio.c +830 -0
- data/ext/mtl_linux/src/vm/vinterp.c +1780 -0
- data/ext/mtl_linux/src/vm/vloader.c +139 -0
- data/ext/mtl_linux/src/vm/vlog.c +782 -0
- data/ext/mtl_linux/src/vm/vmem.c +461 -0
- data/ext/mtl_linux/src/vm/vnet.c +298 -0
- data/{bytecode/src/mtl → ext/mtl_linux}/utils/correct_const.sh +0 -0
- data/lib/nabaztag_hack_kit/server.rb +4 -7
- data/lib/nabaztag_hack_kit/version.rb +1 -1
- data/lib/nabaztag_hack_kit.rb +2 -2
- data/nabaztag_hack_kit.gemspec +10 -11
- data/spec/integration/server_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/message_spec.rb +12 -18
- data/spec/unit/server_spec.rb +13 -10
- metadata +145 -137
- data/bytecode/bin/mtl_comp +0 -50
- data/bytecode/bin/mtl_simu +0 -49
- data/bytecode/src/mtl/Makefile +0 -42
- data/bytecode/src/mtl/README.md +0 -13
- data/bytecode/src/mtl/bc.cpp +0 -1891
- data/bytecode/src/mtl/dumpbc.c +0 -2566
- data/bytecode/src/mtl/linux_simu.c +0 -271
- data/bytecode/src/mtl/linux_simuaudio.c +0 -16
- data/bytecode/src/mtl/linux_simunet.c +0 -620
- data/bytecode/src/mtl/log.c +0 -297
- data/bytecode/src/mtl/log.h +0 -20
- data/bytecode/src/mtl/main_compiler.cpp +0 -104
- data/bytecode/src/mtl/main_simu.cpp +0 -221
- data/bytecode/src/mtl/mp3/common.c +0 -265
- data/bytecode/src/mtl/mp3/dct64_i386.c +0 -316
- data/bytecode/src/mtl/mp3/decode_i386.c +0 -155
- data/bytecode/src/mtl/mp3/huffman.h +0 -332
- data/bytecode/src/mtl/mp3/interface.c +0 -258
- data/bytecode/src/mtl/mp3/mpglib.h +0 -44
- data/bytecode/src/mtl/properties.c +0 -293
- data/bytecode/src/mtl/simu.c +0 -750
- data/bytecode/src/mtl/simuaudio.c +0 -662
- data/bytecode/src/mtl/simunet.c +0 -400
- data/bytecode/src/mtl/vaudio.c +0 -677
- data/bytecode/src/mtl/vbc_str.h +0 -166
- data/bytecode/src/mtl/vcomp/Makefile +0 -29
- data/bytecode/src/mtl/vcomp/bootstrap.cpp +0 -89
- data/bytecode/src/mtl/vcomp/compiler.cpp +0 -470
- data/bytecode/src/mtl/vcomp/compiler.h +0 -200
- data/bytecode/src/mtl/vcomp/compiler_file.cpp +0 -929
- data/bytecode/src/mtl/vcomp/compiler_prog.cpp +0 -250
- data/bytecode/src/mtl/vcomp/compiler_term.cpp +0 -1053
- data/bytecode/src/mtl/vcomp/compiler_type.cpp +0 -872
- data/bytecode/src/mtl/vcomp/compiler_var.cpp +0 -289
- data/bytecode/src/mtl/vcomp/file.cpp +0 -79
- data/bytecode/src/mtl/vcomp/interpreter.cpp +0 -85
- data/bytecode/src/mtl/vcomp/interpreter.h +0 -121
- data/bytecode/src/mtl/vcomp/memory.cpp +0 -241
- data/bytecode/src/mtl/vcomp/parser.cpp +0 -427
- data/bytecode/src/mtl/vcomp/parser_xml.cpp +0 -124
- data/bytecode/src/mtl/vcomp/prodbuffer.h +0 -42
- data/bytecode/src/mtl/vcomp/stdlib_core.cpp +0 -122
- data/bytecode/src/mtl/vcomp/terminal.cpp +0 -73
- data/bytecode/src/mtl/vinterp.c +0 -1349
- data/bytecode/src/mtl/vloader.c +0 -127
- data/bytecode/src/mtl/vlog.c +0 -589
- data/bytecode/src/mtl/vmem.c +0 -424
- data/bytecode/src/mtl/vnet.c +0 -255
- data/examples/basic/Procfile +0 -2
- data/examples/basic/server.rb +0 -14
@@ -1,1053 +0,0 @@
|
|
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
|
-
// switch 8 / 32 bits
|
20
|
-
void Compiler::bc_byte_or_int(int val,int opbyte,int opint)
|
21
|
-
{
|
22
|
-
if ((val>=0)&&(val<=255))
|
23
|
-
{
|
24
|
-
bc->addchar(opbyte);
|
25
|
-
bc->addchar(val);
|
26
|
-
}
|
27
|
-
else
|
28
|
-
{
|
29
|
-
bc->addchar(OPint);
|
30
|
-
bc->addint(val);
|
31
|
-
bc->addchar(opint);
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
void Compiler::bcint_byte_or_int(int val)
|
36
|
-
{
|
37
|
-
if ((val>=0)&&(val<=255))
|
38
|
-
{
|
39
|
-
bc->addchar(OPintb);
|
40
|
-
bc->addchar(val);
|
41
|
-
}
|
42
|
-
else
|
43
|
-
{
|
44
|
-
bc->addchar(OPint);
|
45
|
-
bc->addint(val);
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
int Compiler::parseterm()
|
51
|
-
{
|
52
|
-
int k;
|
53
|
-
|
54
|
-
if (!parser->next(0))
|
55
|
-
{
|
56
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : term expected (found EOF)\n");
|
57
|
-
return MTLERR_SN;
|
58
|
-
}
|
59
|
-
if (!strcmp(parser->token,"(")) // gestion des parenth�ses
|
60
|
-
{
|
61
|
-
if (k=parseprogram()) return k;
|
62
|
-
return parser->parsekeyword(")");
|
63
|
-
}
|
64
|
-
else if (!strcmp(parser->token,"[")) // gestion des tuples
|
65
|
-
{
|
66
|
-
if (parser->next(0))
|
67
|
-
{
|
68
|
-
if (islabel(parser->token))
|
69
|
-
{
|
70
|
-
int *p;
|
71
|
-
if ((p=searchref(PNTTOVAL(newpackage),parser->token)) // recherche dans les autres globales
|
72
|
-
&&(VALTOINT(TABGET(p,REF_CODE))==CODE_FIELD))
|
73
|
-
return parsefields(p);
|
74
|
-
}
|
75
|
-
parser->giveback();
|
76
|
-
}
|
77
|
-
int nval=0;
|
78
|
-
while(1)
|
79
|
-
{
|
80
|
-
if (!parser->next(0))
|
81
|
-
{
|
82
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : ']' expected (found EOF)\n");
|
83
|
-
return MTLERR_SN;
|
84
|
-
}
|
85
|
-
if (!strcmp(parser->token,"]"))
|
86
|
-
{
|
87
|
-
bc_byte_or_int(nval,OPdeftabb,OPdeftab);
|
88
|
-
return createnodetuple(nval);
|
89
|
-
}
|
90
|
-
parser->giveback();
|
91
|
-
if (k=parseexpression()) return k;
|
92
|
-
nval++;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
else if (!strcmp(parser->token,"{")) // gestion des tableaux
|
96
|
-
{
|
97
|
-
int nval=0;
|
98
|
-
if (k=createnodetype(TYPENAME_TAB)) return k;
|
99
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
100
|
-
TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0));
|
101
|
-
int* p=VALTOPNT(STACKPULL(m));
|
102
|
-
|
103
|
-
while(1)
|
104
|
-
{
|
105
|
-
if (!parser->next(0))
|
106
|
-
{
|
107
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : '}' expected (found EOF)\n");
|
108
|
-
return MTLERR_SN;
|
109
|
-
}
|
110
|
-
if (!strcmp(parser->token,"}"))
|
111
|
-
{
|
112
|
-
bc_byte_or_int(nval,OPdeftabb,OPdeftab);
|
113
|
-
return 0;
|
114
|
-
}
|
115
|
-
parser->giveback();
|
116
|
-
if (k=parseexpression()) return k;
|
117
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),p)) return k;
|
118
|
-
STACKDROP(m);
|
119
|
-
nval++;
|
120
|
-
}
|
121
|
-
}
|
122
|
-
else if (!strcmp(parser->token,"if")) // gestion du if
|
123
|
-
return parseif();
|
124
|
-
else if (!strcmp(parser->token,"let")) // gestion du let
|
125
|
-
return parselet();
|
126
|
-
else if (!strcmp(parser->token,"set")) // gestion du set
|
127
|
-
return parseset();
|
128
|
-
else if (!strcmp(parser->token,"while")) // gestion du while
|
129
|
-
return parsewhile();
|
130
|
-
else if (!strcmp(parser->token,"for")) // gestion du for
|
131
|
-
return parsefor();
|
132
|
-
else if (!strcmp(parser->token,"match")) // gestion du match
|
133
|
-
return parsematch();
|
134
|
-
else if (!strcmp(parser->token,"call")) // gestion du while
|
135
|
-
return parsecall();
|
136
|
-
else if (!strcmp(parser->token,"update")) // gestion du update
|
137
|
-
return parseupdate();
|
138
|
-
else if (!strcmp(parser->token,"nil")) // gestion du nil
|
139
|
-
{
|
140
|
-
bc->addchar(OPnil);
|
141
|
-
return createnodetype(TYPENAME_UNDEF);
|
142
|
-
}
|
143
|
-
else if (!strcmp(parser->token,"'")) // gestion des 'char
|
144
|
-
{
|
145
|
-
if (!parser->next(0))
|
146
|
-
{
|
147
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : 'char expected (found EOF)\n");
|
148
|
-
return MTLERR_SN;
|
149
|
-
}
|
150
|
-
bcint_byte_or_int(parser->token[0]&255);
|
151
|
-
if (k=parser->parsekeyword("'")) return k;
|
152
|
-
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
|
153
|
-
}
|
154
|
-
else if (islabel(parser->token)) // gestion des appels de fonctions ou r�f�rences
|
155
|
-
return parseref();
|
156
|
-
else if (isdecimal(parser->token)) // gestion des entiers
|
157
|
-
{
|
158
|
-
int i=mtl_atoi(parser->token);
|
159
|
-
bcint_byte_or_int(i);
|
160
|
-
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
|
161
|
-
}
|
162
|
-
else if ((parser->token[0]=='0')&&(parser->token[1]=='x')
|
163
|
-
&&(ishexadecimal(parser->token+2))) // gestion des entiers
|
164
|
-
{
|
165
|
-
int i=mtl_htoi(parser->token+2);
|
166
|
-
bcint_byte_or_int(i);
|
167
|
-
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_I));
|
168
|
-
}
|
169
|
-
else if (parser->token[0]=='"') // gestion des chaines
|
170
|
-
{
|
171
|
-
if (k=parser->getstring(m,'"')) return k;
|
172
|
-
int val=INTTOVAL(nblabels(globals));
|
173
|
-
if (k=addlabel(globals,"",val,STACKGET(m,0))) return k; // enregistrement d'une nouvelle globale
|
174
|
-
STACKDROP(m);
|
175
|
-
bc_byte_or_int(VALTOINT(val),OPgetglobalb,OPgetglobal);
|
176
|
-
return STACKPUSH(m,TABGET(stdtypes,STDTYPE_S));
|
177
|
-
}
|
178
|
-
else if (!strcmp(parser->token,"#")) // gestion des pointeurs sur fonction statique ou dynamique
|
179
|
-
return parsepntfun();
|
180
|
-
else
|
181
|
-
{
|
182
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : unexpected term '%s'\n",parser->token);
|
183
|
-
return MTLERR_SN;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
// parsing de la cr�ation d'une structure
|
188
|
-
// p contient la r�f�rence du premier champ
|
189
|
-
int Compiler::parsefields(int* p)
|
190
|
-
{
|
191
|
-
int k;
|
192
|
-
int* type=VALTOPNT(TABGET(VALTOPNT(TABGET(p,REF_VAL)),FIELD_TYPE));
|
193
|
-
int n=VALTOINT(TABGET(type,REF_VAL));
|
194
|
-
bc_byte_or_int(n,OPmktabb,OPmktab); // cr�ation de la structure
|
195
|
-
if (k=copytype(VALTOPNT(TABGET(type,REF_TYPE)))) return k; // cr�ation du type
|
196
|
-
|
197
|
-
int loop=1;
|
198
|
-
while(loop)
|
199
|
-
{
|
200
|
-
if (k=copytype(VALTOPNT(TABGET(p,REF_TYPE)))) return k; // cr�ation du type du champ
|
201
|
-
if (k=unif(VALTOPNT(STACKGET(m,1)),
|
202
|
-
VALTOPNT(TABGET(argsfromfun(VALTOPNT(STACKGET(m,0))),TYPEHEADER_LENGTH)) )) return k;
|
203
|
-
STACKSET(m,0,TABGET(VALTOPNT(STACKGET(m,0)),TYPEHEADER_LENGTH+1));
|
204
|
-
|
205
|
-
if (k=parser->parsekeyword(":")) return k;
|
206
|
-
if (k=parseexpression()) return k;
|
207
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,1)))) return k;
|
208
|
-
STACKDROPN(m,2);
|
209
|
-
bc_byte_or_int( VALTOINT(TABGET(VALTOPNT(TABGET(p,REF_VAL)),FIELD_NUM)), OPsetstructb,OPsetstruct);
|
210
|
-
|
211
|
-
|
212
|
-
if (!parser->next(0))
|
213
|
-
{
|
214
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : ']' expected (found EOF)\n");
|
215
|
-
return MTLERR_SN;
|
216
|
-
}
|
217
|
-
if (!strcmp(parser->token,"]"))
|
218
|
-
{
|
219
|
-
return 0;
|
220
|
-
}
|
221
|
-
loop=0;
|
222
|
-
if (islabel(parser->token))
|
223
|
-
{
|
224
|
-
if ((p=searchref(PNTTOVAL(newpackage),parser->token)) // recherche dans les autres globales
|
225
|
-
&&(VALTOINT(TABGET(p,REF_CODE))==CODE_FIELD))
|
226
|
-
loop=1;
|
227
|
-
}
|
228
|
-
}
|
229
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : ']' expected (found '%s')\n",parser->token);
|
230
|
-
return MTLERR_SN;
|
231
|
-
}
|
232
|
-
|
233
|
-
|
234
|
-
// parsing d'une r�f�rence quelconque (d�j� pr�sente dans parser->token)
|
235
|
-
int Compiler::parseref()
|
236
|
-
{
|
237
|
-
int k;
|
238
|
-
|
239
|
-
int val;
|
240
|
-
int ref;
|
241
|
-
if (!searchlabel_byname(locals,parser->token,&val,&ref)) // recherche dans les variables locales
|
242
|
-
{
|
243
|
-
bc_byte_or_int(VALTOINT(val),OPgetlocalb,OPgetlocal);
|
244
|
-
if (k=STACKPUSH(m,ref)) return k;
|
245
|
-
return parsegetpoint();
|
246
|
-
}
|
247
|
-
val=-1;
|
248
|
-
|
249
|
-
int *p;
|
250
|
-
if (p=searchref(PNTTOVAL(newpackage),parser->token)) // recherche dans les autres globales
|
251
|
-
{
|
252
|
-
ref=PNTTOVAL(p);
|
253
|
-
int code=VALTOINT(TABGET(p,REF_CODE));
|
254
|
-
if (code==CODE_CONS0)
|
255
|
-
{
|
256
|
-
bcint_byte_or_int(VALTOINT(TABGET(p,REF_VAL)));
|
257
|
-
bc->addchar(OPdeftabb);
|
258
|
-
bc->addchar(1);
|
259
|
-
return copytype(VALTOPNT(TABGET(VALTOPNT(TABGET(p,REF_TYPE)),TYPEHEADER_LENGTH+1)));
|
260
|
-
}
|
261
|
-
else if (code==CODE_CONS)
|
262
|
-
{
|
263
|
-
bcint_byte_or_int(VALTOINT(TABGET(p,REF_VAL)));
|
264
|
-
if (k=parseexpression()) return k;
|
265
|
-
bc->addchar(OPdeftabb);
|
266
|
-
bc->addchar(2);
|
267
|
-
if (k=createnodetuple(1)) return k;
|
268
|
-
if (k=copytype(VALTOPNT(TABGET(p,REF_TYPE)))) return k;
|
269
|
-
return unif_argfun();
|
270
|
-
}
|
271
|
-
val=0;
|
272
|
-
}
|
273
|
-
|
274
|
-
if (val!=-1)
|
275
|
-
{
|
276
|
-
int* p=VALTOPNT(ref);
|
277
|
-
int code=VALTOINT(TABGET(p,REF_CODE));
|
278
|
-
|
279
|
-
if (code>=0) // appel d'une fonction
|
280
|
-
{
|
281
|
-
int i; for(i=0;i<code;i++) if (k=parseexpression())
|
282
|
-
{
|
283
|
-
char * name=STRSTART(VALTOPNT(TABGET(p,REF_NAME)));
|
284
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : function %s requires %d arguments\n",name, code);
|
285
|
-
return k;
|
286
|
-
}
|
287
|
-
if ((TABGET(p,REF_VAL)!=NIL)&&(TABGET(VALTOPNT(TABGET(p,REF_VAL)),FUN_NBLOCALS)==NIL))
|
288
|
-
{ // appel natif
|
289
|
-
bc->addchar((char)VALTOINT(TABGET(VALTOPNT(TABGET(p,REF_VAL)),FUN_BC)));
|
290
|
-
}
|
291
|
-
else
|
292
|
-
{ // appel normal
|
293
|
-
bcint_byte_or_int(VALTOINT(TABGET(p,REF_PACKAGE)));
|
294
|
-
bc->addchar(OPexec);
|
295
|
-
}
|
296
|
-
if (k=createnodetuple(code)) return k;
|
297
|
-
if (p!=newref)
|
298
|
-
{
|
299
|
-
if (k=copytype(VALTOPNT(TABGET(p,REF_TYPE)))) return k;
|
300
|
-
}
|
301
|
-
else if (k=STACKPUSH(m,TABGET(p,REF_TYPE))) return k;
|
302
|
-
return unif_argfun();
|
303
|
-
}
|
304
|
-
else if (code==CODE_VAR || code==CODE_CONST) // lecture d'une r�f�rence
|
305
|
-
{
|
306
|
-
bc_byte_or_int(VALTOINT(TABGET(p,REF_PACKAGE)),OPgetglobalb,OPgetglobal);
|
307
|
-
if (k=STACKPUSH(m,TABGET(p,REF_TYPE))) return k;
|
308
|
-
return parsegetpoint();
|
309
|
-
}
|
310
|
-
}
|
311
|
-
|
312
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : unknown label '%s'\n",parser->token);
|
313
|
-
return MTLERR_SN;
|
314
|
-
}
|
315
|
-
|
316
|
-
// parsing (.Term/champ)* en lecture
|
317
|
-
int Compiler::parsegetpoint()
|
318
|
-
{
|
319
|
-
int k;
|
320
|
-
while(1)
|
321
|
-
{
|
322
|
-
if (!parser->next(0)) return 0;
|
323
|
-
if (strcmp(parser->token,"."))
|
324
|
-
{
|
325
|
-
parser->giveback();
|
326
|
-
return 0;
|
327
|
-
}
|
328
|
-
if (!parser->next(0))
|
329
|
-
{
|
330
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : expression or field name expected (found EOF)\n");
|
331
|
-
return MTLERR_SN;
|
332
|
-
}
|
333
|
-
|
334
|
-
int* p;
|
335
|
-
if ((islabel(parser->token))
|
336
|
-
&&(p=searchref(PNTTOVAL(newpackage),parser->token)) // recherche dans les autres globales
|
337
|
-
&&(VALTOINT(TABGET(p,REF_CODE))==CODE_FIELD))
|
338
|
-
{
|
339
|
-
bc_byte_or_int(VALTOINT(TABGET(VALTOPNT(TABGET(p,REF_VAL)),FIELD_NUM)),OPfetchb,OPfetch);
|
340
|
-
if (k=createnodetuple(1)) return k;
|
341
|
-
if (k=copytype(VALTOPNT(TABGET(p,REF_TYPE)))) return k;
|
342
|
-
if (k=unif_argfun()) return k;
|
343
|
-
}
|
344
|
-
else
|
345
|
-
{
|
346
|
-
parser->giveback();
|
347
|
-
if (k=parseterm()) return k;
|
348
|
-
bc->addchar(OPfetch);
|
349
|
-
if (k=createnodetuple(2)) return k;
|
350
|
-
if (k=copytype(VALTOPNT(TABGET(stdtypes,STDTYPE_fun__tab_u0_I__u0)))) return k;
|
351
|
-
if (k=unif_argfun()) return k;
|
352
|
-
}
|
353
|
-
}
|
354
|
-
}
|
355
|
-
|
356
|
-
|
357
|
-
// parsing du if ... then ... else (le 'if' a d�j� �t� lu)
|
358
|
-
int Compiler::parseif()
|
359
|
-
{
|
360
|
-
int k;
|
361
|
-
|
362
|
-
if (k=parseexpression()) return k; // lire la condition
|
363
|
-
|
364
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(TABGET(stdtypes,STDTYPE_I)))) return k;
|
365
|
-
STACKDROP(m);
|
366
|
-
if (k=parser->parsekeyword("then")) return k;
|
367
|
-
|
368
|
-
bc->addchar(OPelse);
|
369
|
-
int bc_else=bc->getsize();
|
370
|
-
bc->addshort(0); // on pr�pare le champ pour le saut 'else'
|
371
|
-
|
372
|
-
if (k=parseexpression()) return k; // lire l'expression 'then'
|
373
|
-
|
374
|
-
bc->addchar(OPgoto);
|
375
|
-
int bc_goto=bc->getsize();
|
376
|
-
bc->addshort(0); // on pr�pare le champ pour le saut du 'then'
|
377
|
-
|
378
|
-
bc->setshort(bc_else,bc->getsize()); // on r�gle le saut du else
|
379
|
-
|
380
|
-
if ((parser->next(0))&&(!strcmp(parser->token,"else")))
|
381
|
-
{
|
382
|
-
if (k=parseexpression()) return k; // lire l'expression 'else'
|
383
|
-
}
|
384
|
-
else // pas de else, on remplace par nil
|
385
|
-
{
|
386
|
-
parser->giveback();
|
387
|
-
bc->addchar(OPnil);
|
388
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
389
|
-
}
|
390
|
-
bc->setshort(bc_goto,bc->getsize()); // on r�gle le saut du 'goto'
|
391
|
-
|
392
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,1)))) return k;
|
393
|
-
STACKDROP(m);
|
394
|
-
return 0;
|
395
|
-
|
396
|
-
}
|
397
|
-
|
398
|
-
// parsing du while ... do ... (le 'while' a d�j� �t� lu)
|
399
|
-
int Compiler::parsewhile()
|
400
|
-
{
|
401
|
-
int k;
|
402
|
-
|
403
|
-
bc->addchar(OPnil); // on empile le premier r�sultat
|
404
|
-
|
405
|
-
int bc_while=bc->getsize(); // on retient la position pour le saut 'while'
|
406
|
-
if (k=parseexpression()) return k; // lire la condition
|
407
|
-
|
408
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(TABGET(stdtypes,STDTYPE_I)))) return k;
|
409
|
-
STACKDROP(m);
|
410
|
-
if (k=parser->parsekeyword("do")) return k;
|
411
|
-
bc->addchar(OPelse);
|
412
|
-
int bc_end=bc->getsize();
|
413
|
-
bc->addshort(0); // on pr�pare le champ pour le saut 'end'
|
414
|
-
bc->addchar(OPdrop); // on ignore le r�sultat pr�c�dent
|
415
|
-
|
416
|
-
if (k=parseexpression()) return k; // lire l'expression 'do'
|
417
|
-
|
418
|
-
bc->addchar(OPgoto);
|
419
|
-
bc->addshort(bc_while); // on retourne � la condition
|
420
|
-
|
421
|
-
bc->setshort(bc_end,bc->getsize()); // on r�gle le saut 'end'
|
422
|
-
|
423
|
-
return 0;
|
424
|
-
}
|
425
|
-
|
426
|
-
|
427
|
-
// parsing du for ...=... ; cond ; nextvalue do ... (le 'for' a d�j� �t� lu)
|
428
|
-
int Compiler::parsefor()
|
429
|
-
{
|
430
|
-
int k;
|
431
|
-
|
432
|
-
if (!parser->next(0))
|
433
|
-
{
|
434
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : label expected (found EOF)\n");
|
435
|
-
return MTLERR_SN;
|
436
|
-
}
|
437
|
-
if (!islabel(parser->token))
|
438
|
-
{
|
439
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : label expected (found '%s')\n",parser->token);
|
440
|
-
return MTLERR_SN;
|
441
|
-
}
|
442
|
-
if (k=STRPUSH(m,parser->token)) return k;
|
443
|
-
// [name_it]
|
444
|
-
if (k=parser->parsekeyword("=")) return k;
|
445
|
-
if (k=parseexpression()) return k; // lire la valeur d'initialisation
|
446
|
-
// [type_init name_it]
|
447
|
-
int i=nblabels(locals);
|
448
|
-
if (k=addlabel(locals,STRSTART(VALTOPNT(STACKGET(m,1))),INTTOVAL(i),STACKGET(m,0))) return k;
|
449
|
-
if (i+1>nblocals) nblocals=i+1; // nombre maximum de variables locales
|
450
|
-
|
451
|
-
// [type_init name_it]
|
452
|
-
bc_byte_or_int(i,OPsetlocalb,OPsetlocal);
|
453
|
-
|
454
|
-
if (k=parser->parsekeyword(";")) return k;
|
455
|
-
|
456
|
-
bc->addchar(OPnil); // on empile le premier r�sultat
|
457
|
-
|
458
|
-
int bc_cond=bc->getsize(); // on retient la position pour le saut 'while'
|
459
|
-
if (k=parseexpression()) return k; // lire la condition
|
460
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(TABGET(stdtypes,STDTYPE_I)))) return k;
|
461
|
-
STACKDROP(m);
|
462
|
-
|
463
|
-
bc->addchar(OPelse);
|
464
|
-
int bc_end=bc->getsize();
|
465
|
-
bc->addshort(0); // on pr�pare le champ pour le saut 'end'
|
466
|
-
|
467
|
-
if (!parser->next(0))
|
468
|
-
{
|
469
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : 'do' expected (found EOF)\n");
|
470
|
-
return MTLERR_SN;
|
471
|
-
}
|
472
|
-
if (!strcmp(parser->token,";"))
|
473
|
-
{
|
474
|
-
bc->addchar(OPgoto);
|
475
|
-
int bc_expr=bc->getsize();
|
476
|
-
bc->addshort(0); // on pr�pare le champ pour le saut 'expr'
|
477
|
-
|
478
|
-
int bc_next=bc->getsize();
|
479
|
-
if (k=parseexpression()) return k; // lire la valeur next
|
480
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,1)))) return k;
|
481
|
-
STACKDROP(m);
|
482
|
-
bc_byte_or_int(i,OPsetlocalb,OPsetlocal); // mise � jour de l'it�rateur
|
483
|
-
bc->addchar(OPgoto);
|
484
|
-
bc->addshort(bc_cond);
|
485
|
-
|
486
|
-
if (k=parser->parsekeyword("do")) return k;
|
487
|
-
|
488
|
-
bc->setshort(bc_expr,bc->getsize());
|
489
|
-
bc->addchar(OPdrop); // on ignore le r�sultat pr�c�dent
|
490
|
-
if (k=parseexpression()) return k; // lire la valeur it�r�e
|
491
|
-
bc->addchar(OPgoto);
|
492
|
-
bc->addshort(bc_next); // on retourne � l'it�rateur
|
493
|
-
}
|
494
|
-
else
|
495
|
-
{
|
496
|
-
parser->giveback();
|
497
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(TABGET(stdtypes,STDTYPE_I)))) return k;
|
498
|
-
if (k=parser->parsekeyword("do")) return k;
|
499
|
-
bc->addchar(OPdrop); // on ignore le r�sultat pr�c�dent
|
500
|
-
if (k=parseexpression()) return k; // lire la valeur it�r�e
|
501
|
-
bc_byte_or_int(i,OPgetlocalb,OPgetlocal); // i+1
|
502
|
-
bc->addchar(OPintb);
|
503
|
-
bc->addchar(1);
|
504
|
-
bc->addchar(OPadd);
|
505
|
-
bc_byte_or_int(i,OPsetlocalb,OPsetlocal); // mise � jour de l'it�rateur
|
506
|
-
bc->addchar(OPgoto);
|
507
|
-
bc->addshort(bc_cond); // on retourne � la condition
|
508
|
-
}
|
509
|
-
bc->setshort(bc_end,bc->getsize());
|
510
|
-
|
511
|
-
removenlabels(locals,1);
|
512
|
-
|
513
|
-
STACKSET(m,2,STACKGET(m,0));
|
514
|
-
STACKDROPN(m,2);
|
515
|
-
|
516
|
-
return 0;
|
517
|
-
}
|
518
|
-
|
519
|
-
// parsing du match ... with ... (le 'match' a d�j� �t� lu)
|
520
|
-
int Compiler::parsematch()
|
521
|
-
{
|
522
|
-
int k;
|
523
|
-
|
524
|
-
if (k=parseexpression()) return k; // lire l'objet
|
525
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k; // pr�parer le type du r�sultat
|
526
|
-
// [result src]
|
527
|
-
|
528
|
-
if (k=parser->parsekeyword("with")) return k;
|
529
|
-
|
530
|
-
int end;
|
531
|
-
if (k=parsematchcons(&end)) return k;
|
532
|
-
STACKSET(m,1,STACKGET(m,0));
|
533
|
-
STACKDROP(m);
|
534
|
-
return 0;
|
535
|
-
}
|
536
|
-
|
537
|
-
int Compiler::parsematchcons(int* end)
|
538
|
-
{
|
539
|
-
int k;
|
540
|
-
if (k=parser->parsekeyword("(")) return k;
|
541
|
-
if (!parser->next(0))
|
542
|
-
{
|
543
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : constructor expected (found EOF)\n");
|
544
|
-
return MTLERR_SN;
|
545
|
-
}
|
546
|
-
int* p=NULL;
|
547
|
-
if (!strcmp(parser->token,"_")) // cas par d�faut
|
548
|
-
{
|
549
|
-
bc->addchar(OPdrop);
|
550
|
-
if (k=parser->parsekeyword("->")) return k;
|
551
|
-
if (k=parseprogram()) return k; // lire le r�sultat
|
552
|
-
// [type_result result src]
|
553
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,1)))) return k;
|
554
|
-
STACKDROP(m);
|
555
|
-
// [result src]
|
556
|
-
if (k=parser->parsekeyword(")")) return k;
|
557
|
-
*end=bc->getsize();
|
558
|
-
return 0;
|
559
|
-
}
|
560
|
-
if ((islabel(parser->token)) // constructeur
|
561
|
-
&&(p=searchref(PNTTOVAL(newpackage),parser->token))) // recherche dans les autres globales
|
562
|
-
{
|
563
|
-
int code=VALTOINT(TABGET(p,REF_CODE));
|
564
|
-
if ((code==CODE_CONS)||(code==CODE_CONS0))
|
565
|
-
{
|
566
|
-
// [result src]
|
567
|
-
bc->addchar(OPfirst);
|
568
|
-
bcint_byte_or_int(VALTOINT(TABGET(p,REF_VAL)));
|
569
|
-
bc->addchar(OPeq);
|
570
|
-
bc->addchar(OPelse);
|
571
|
-
int bc_else=bc->getsize(); // on retient la position pour le saut 'else'
|
572
|
-
bc->addshort(0);
|
573
|
-
|
574
|
-
int nloc=nblabels(locals); // on sauvegarde le nombre de locales
|
575
|
-
if (code==CODE_CONS)
|
576
|
-
{
|
577
|
-
bc->addchar(OPfetchb);
|
578
|
-
bc->addchar(1);
|
579
|
-
if (k=parselocals()) return k;
|
580
|
-
if (k=createnodetuple(1)) return k;
|
581
|
-
}
|
582
|
-
else
|
583
|
-
{
|
584
|
-
bc->addchar(OPdrop);
|
585
|
-
if (k=createnodetuple(0)) return k;
|
586
|
-
}
|
587
|
-
// [[locals] result src]
|
588
|
-
int newnloc=nblabels(locals); // on sauvegarde le nombre de locales
|
589
|
-
if (newnloc>nblocals) nblocals=newnloc; // nombre maximum de variables locales
|
590
|
-
int nloctodelete=newnloc-nloc; // combien de variables locales ont �t� cr�es ?
|
591
|
-
|
592
|
-
if (k=copytype(VALTOPNT(TABGET(p,REF_TYPE)))) return k;
|
593
|
-
if (k=unif_argfun()) return k;
|
594
|
-
// [type_src result src]
|
595
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,2)))) return k;
|
596
|
-
STACKDROP(m);
|
597
|
-
// [result src]
|
598
|
-
if (k=parser->parsekeyword("->")) return k;
|
599
|
-
if (k=parseprogram()) return k; // lire le r�sultat
|
600
|
-
// [type_result result src]
|
601
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,1)))) return k;
|
602
|
-
STACKDROP(m);
|
603
|
-
// [result src]
|
604
|
-
removenlabels(locals,nloctodelete);
|
605
|
-
if (k=parser->parsekeyword(")")) return k;
|
606
|
-
bc->addchar(OPgoto);
|
607
|
-
int bc_goto=bc->getsize(); // on retient la position pour le saut 'else'
|
608
|
-
bc->addshort(0);
|
609
|
-
bc->setshort(bc_else,bc->getsize());
|
610
|
-
if ((parser->next(0))&&(!strcmp(parser->token,"|")))
|
611
|
-
{
|
612
|
-
if (k=parsematchcons(end)) return k;
|
613
|
-
bc->setshort(bc_goto,*end);
|
614
|
-
return 0;
|
615
|
-
}
|
616
|
-
parser->giveback();
|
617
|
-
bc->addchar(OPdrop);
|
618
|
-
bc->addchar(OPnil);
|
619
|
-
*end=bc->getsize();
|
620
|
-
bc->setshort(bc_goto,*end);
|
621
|
-
return 0;
|
622
|
-
}
|
623
|
-
}
|
624
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : constructor expected (found '%s')\n",parser->token);
|
625
|
-
return MTLERR_SN;
|
626
|
-
}
|
627
|
-
|
628
|
-
|
629
|
-
// parsing du let ... -> ... in (le 'let' a d�j� �t� lu)
|
630
|
-
int Compiler::parselet()
|
631
|
-
{
|
632
|
-
int k;
|
633
|
-
|
634
|
-
if (k=parseexpression()) return k; // lire la source
|
635
|
-
if (k=parser->parsekeyword("->")) return k;
|
636
|
-
|
637
|
-
int nloc=nblabels(locals); // on sauvegarde le nombre de locales
|
638
|
-
|
639
|
-
if (k=parselocals()) return k;
|
640
|
-
|
641
|
-
int newnloc=nblabels(locals); // on sauvegarde le nombre de locales
|
642
|
-
if (newnloc>nblocals) nblocals=newnloc; // nombre maximum de variables locales
|
643
|
-
int nloctodelete=newnloc-nloc; // combien de variables locales ont �t� cr�es ?
|
644
|
-
|
645
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,1)))) return k;
|
646
|
-
STACKDROPN(m,2);
|
647
|
-
if (k=parser->parsekeyword("in")) return k;
|
648
|
-
|
649
|
-
if (k=parseexpression()) return k; // lire l'expression du let
|
650
|
-
removenlabels(locals,nloctodelete);
|
651
|
-
return 0;
|
652
|
-
}
|
653
|
-
|
654
|
-
|
655
|
-
// parsing de variables locales structur�es
|
656
|
-
int Compiler::parselocals()
|
657
|
-
{
|
658
|
-
int k;
|
659
|
-
|
660
|
-
if (!parser->next(0))
|
661
|
-
{
|
662
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : term expected (found EOF)\n");
|
663
|
-
return MTLERR_SN;
|
664
|
-
}
|
665
|
-
else if (!strcmp(parser->token,"["))
|
666
|
-
{
|
667
|
-
int n=0;
|
668
|
-
while(1)
|
669
|
-
{
|
670
|
-
if (!parser->next(0))
|
671
|
-
{
|
672
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : ']' expected (found EOF)\n");
|
673
|
-
return MTLERR_SN;
|
674
|
-
}
|
675
|
-
if (!strcmp(parser->token,"]"))
|
676
|
-
{
|
677
|
-
bc->addchar(OPdrop);
|
678
|
-
return createnodetuple(n);
|
679
|
-
}
|
680
|
-
else if (!strcmp(parser->token,"_"))
|
681
|
-
{
|
682
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
683
|
-
n++;
|
684
|
-
}
|
685
|
-
else
|
686
|
-
{
|
687
|
-
parser->giveback();
|
688
|
-
bc->addchar(OPdup);
|
689
|
-
bc_byte_or_int(n,OPfetchb,OPfetch);
|
690
|
-
if (k=parselocals()) return k;
|
691
|
-
n++;
|
692
|
-
}
|
693
|
-
}
|
694
|
-
}
|
695
|
-
else if (!strcmp(parser->token,"("))
|
696
|
-
{
|
697
|
-
if (k=createnodetype(TYPENAME_LIST)) return k;
|
698
|
-
int* plist=VALTOPNT(STACKGET(m,0));
|
699
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
700
|
-
int* pval=VALTOPNT(STACKGET(m,0));
|
701
|
-
TABSET(m,plist,TYPEHEADER_LENGTH,STACKGET(m,0));
|
702
|
-
|
703
|
-
while(1) // la liste est dans la pile
|
704
|
-
{
|
705
|
-
if (!parser->next(0)) return parselocals();
|
706
|
-
if (!strcmp(parser->token,"_"))
|
707
|
-
{
|
708
|
-
if ((parser->next(0))&&(!strcmp(parser->token,")")))
|
709
|
-
{
|
710
|
-
bc->addchar(OPdrop);
|
711
|
-
STACKDROP(m);
|
712
|
-
return 0;
|
713
|
-
}
|
714
|
-
parser->giveback();
|
715
|
-
}
|
716
|
-
else if (islabel(parser->token))
|
717
|
-
{
|
718
|
-
int i=nblabels(locals);
|
719
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
720
|
-
if (k=addlabel(locals,parser->token,INTTOVAL(i),STACKGET(m,0))) return k;
|
721
|
-
if ((parser->next(0))&&(!strcmp(parser->token,")")))
|
722
|
-
{
|
723
|
-
bc_byte_or_int(i,OPsetlocalb,OPsetlocal);
|
724
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),plist)) return k;
|
725
|
-
STACKDROPN(m,2);
|
726
|
-
return 0;
|
727
|
-
}
|
728
|
-
parser->giveback();
|
729
|
-
bc->addchar(OPfirst);
|
730
|
-
bc_byte_or_int(i,OPsetlocalb,OPsetlocal);
|
731
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),pval)) return k;
|
732
|
-
STACKDROP(m);
|
733
|
-
}
|
734
|
-
else
|
735
|
-
{
|
736
|
-
parser->giveback();
|
737
|
-
bc->addchar(OPfirst);
|
738
|
-
if (k=parselocals()) return k;
|
739
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),pval)) return k;
|
740
|
-
STACKDROP(m);
|
741
|
-
}
|
742
|
-
if (!parser->next(0))
|
743
|
-
{
|
744
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : '::' expected (found EOF)\n");
|
745
|
-
return MTLERR_SN;
|
746
|
-
}
|
747
|
-
if (!strcmp(parser->token,"::"))
|
748
|
-
{
|
749
|
-
bc->addchar(OPfetchb);
|
750
|
-
bc->addchar(1);
|
751
|
-
}
|
752
|
-
else
|
753
|
-
{
|
754
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : '::' expected (found '%s')\n",parser->token);
|
755
|
-
return MTLERR_SN;
|
756
|
-
}
|
757
|
-
}
|
758
|
-
}
|
759
|
-
else if (!strcmp(parser->token,"_"))
|
760
|
-
{
|
761
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
762
|
-
bc->addchar(OPdrop);
|
763
|
-
return 0;
|
764
|
-
}
|
765
|
-
else if (islabel(parser->token))
|
766
|
-
{
|
767
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
768
|
-
int i=nblabels(locals);
|
769
|
-
bc_byte_or_int(i,OPsetlocalb,OPsetlocal);
|
770
|
-
|
771
|
-
if (k=addlabel(locals,parser->token,INTTOVAL(i),STACKGET(m,0))) return k;
|
772
|
-
return 0;
|
773
|
-
}
|
774
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : unexpected term '%s'\n",parser->token);
|
775
|
-
return MTLERR_SN;
|
776
|
-
}
|
777
|
-
|
778
|
-
// parsing du update ... with ... (le 'update' a d�j� �t� lu)
|
779
|
-
int Compiler::parseupdate()
|
780
|
-
{
|
781
|
-
int k;
|
782
|
-
|
783
|
-
if (k=parseexpression()) return k; // lire la source
|
784
|
-
if (k=parser->parsekeyword("with")) return k;
|
785
|
-
if (k=parser->parsekeyword("[")) return k;
|
786
|
-
|
787
|
-
if (k=parseupdatevals()) return k;
|
788
|
-
|
789
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,1)))) return k;
|
790
|
-
STACKDROP(m);
|
791
|
-
return 0;
|
792
|
-
}
|
793
|
-
|
794
|
-
// parsing des valeurs d'un update (le premier '[' a d�j� �t� lu)
|
795
|
-
int Compiler::parseupdatevals()
|
796
|
-
{
|
797
|
-
int k;
|
798
|
-
|
799
|
-
int n=0;
|
800
|
-
while(1)
|
801
|
-
{
|
802
|
-
if (!parser->next(0))
|
803
|
-
{
|
804
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : ']' expected (found EOF)\n");
|
805
|
-
return MTLERR_SN;
|
806
|
-
}
|
807
|
-
if (!strcmp(parser->token,"["))
|
808
|
-
{
|
809
|
-
bc->addchar(OPdup);
|
810
|
-
bc_byte_or_int(n,OPfetchb,OPfetch);
|
811
|
-
parseupdatevals();
|
812
|
-
bc->addchar(OPdrop);
|
813
|
-
n++;
|
814
|
-
}
|
815
|
-
else if (!strcmp(parser->token,"]"))
|
816
|
-
{
|
817
|
-
return createnodetuple(n);
|
818
|
-
}
|
819
|
-
else if (!strcmp(parser->token,"_"))
|
820
|
-
{
|
821
|
-
if (k=createnodetype(TYPENAME_UNDEF)) return k;
|
822
|
-
n++;
|
823
|
-
}
|
824
|
-
else
|
825
|
-
{
|
826
|
-
parser->giveback();
|
827
|
-
if (k=parseexpression()) return k;
|
828
|
-
bc_byte_or_int(n,OPsetstructb,OPsetstruct);
|
829
|
-
n++;
|
830
|
-
}
|
831
|
-
}
|
832
|
-
}
|
833
|
-
|
834
|
-
|
835
|
-
// parsing d'un set ... = ... (le 'set' a d�j� �t� lu)
|
836
|
-
int Compiler::parseset()
|
837
|
-
{
|
838
|
-
int k;
|
839
|
-
int val;
|
840
|
-
int ref;
|
841
|
-
int opstore=-1;
|
842
|
-
|
843
|
-
if (!parser->next(0))
|
844
|
-
{
|
845
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : reference expected (found EOF)\n");
|
846
|
-
return MTLERR_SN;
|
847
|
-
}
|
848
|
-
if (!islabel(parser->token))
|
849
|
-
{
|
850
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : reference expected (found '%s')\n",parser->token);
|
851
|
-
return MTLERR_SN;
|
852
|
-
}
|
853
|
-
|
854
|
-
if (!searchlabel_byname(locals,parser->token,&val,&ref)) // recherche dans les variables locales
|
855
|
-
{
|
856
|
-
if (k=STACKPUSH(m,ref)) return k;
|
857
|
-
if (k=parsesetpoint(1,VALTOINT(val),&opstore)) return k;
|
858
|
-
}
|
859
|
-
else
|
860
|
-
{
|
861
|
-
val=-1;
|
862
|
-
int *p;
|
863
|
-
if (p=searchref(PNTTOVAL(newpackage),parser->token)) // recherche dans les autres globales
|
864
|
-
{
|
865
|
-
ref=PNTTOVAL(p);
|
866
|
-
val=0;
|
867
|
-
}
|
868
|
-
if (val!=-1)
|
869
|
-
{
|
870
|
-
int* p=VALTOPNT(ref);
|
871
|
-
int code=VALTOINT(TABGET(p,REF_CODE));
|
872
|
-
|
873
|
-
if (code==CODE_VAR) // variable
|
874
|
-
{
|
875
|
-
if (k=STACKPUSH(m,TABGET(p,REF_TYPE))) return k;
|
876
|
-
if (k=parsesetpoint(0,VALTOINT(TABGET(p,REF_PACKAGE)),&opstore)) return k;
|
877
|
-
|
878
|
-
// la variable a �t� sett�e au moins une fois maintenant
|
879
|
-
TABSET(m,p,REF_SET,INTTOVAL(2));
|
880
|
-
}
|
881
|
-
else if (code == CODE_CONST) // constante
|
882
|
-
{
|
883
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : '%s' is a const, it cannot be set\n",parser->token);
|
884
|
-
return MTLERR_SN;
|
885
|
-
}
|
886
|
-
}
|
887
|
-
}
|
888
|
-
if (opstore==-1)
|
889
|
-
{
|
890
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : reference expected (found '%s')\n",parser->token);
|
891
|
-
return MTLERR_SN;
|
892
|
-
}
|
893
|
-
if (k=parser->parsekeyword("=")) return k;
|
894
|
-
if (k=parseexpression()) return k; // lire la source
|
895
|
-
bc->addchar(opstore);
|
896
|
-
|
897
|
-
if (k=unif(VALTOPNT(STACKGET(m,0)),VALTOPNT(STACKGET(m,1)))) return k;
|
898
|
-
STACKDROP(m);
|
899
|
-
return 0;
|
900
|
-
}
|
901
|
-
|
902
|
-
// parsing (.Term/champ)* en �criture
|
903
|
-
int Compiler::parsesetpoint(int local,int ind,int* opstore)
|
904
|
-
{
|
905
|
-
int k;
|
906
|
-
|
907
|
-
if (!parser->next(0)) return 0;
|
908
|
-
if (strcmp(parser->token,"."))
|
909
|
-
{
|
910
|
-
bcint_byte_or_int(ind);
|
911
|
-
if (local) *opstore=OPsetlocal2;
|
912
|
-
else *opstore=OPsetglobal;
|
913
|
-
parser->giveback();
|
914
|
-
return 0;
|
915
|
-
}
|
916
|
-
if (local) bc_byte_or_int(ind,OPgetlocalb,OPgetlocal);
|
917
|
-
else bc_byte_or_int(ind,OPgetglobalb,OPgetglobal);
|
918
|
-
*opstore=OPstore;
|
919
|
-
while(1)
|
920
|
-
{
|
921
|
-
if (!parser->next(0))
|
922
|
-
{
|
923
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : expression or field name expected (found EOF)\n");
|
924
|
-
return MTLERR_SN;
|
925
|
-
}
|
926
|
-
|
927
|
-
ind=-1;
|
928
|
-
int* p;
|
929
|
-
if ((islabel(parser->token))
|
930
|
-
&&(p=searchref(PNTTOVAL(newpackage),parser->token)) // recherche dans les autres globales
|
931
|
-
&&(VALTOINT(TABGET(p,REF_CODE))==CODE_FIELD))
|
932
|
-
{
|
933
|
-
ind=VALTOINT(TABGET(VALTOPNT(TABGET(p,REF_VAL)),FIELD_NUM));
|
934
|
-
if (k=createnodetuple(1)) return k;
|
935
|
-
if (k=copytype(VALTOPNT(TABGET(p,REF_TYPE)))) return k;
|
936
|
-
if (k=unif_argfun()) return k;
|
937
|
-
}
|
938
|
-
else
|
939
|
-
{
|
940
|
-
parser->giveback();
|
941
|
-
|
942
|
-
if (k=parseterm()) return k;
|
943
|
-
if (k=createnodetuple(2)) return k;
|
944
|
-
if (k=copytype(VALTOPNT(TABGET(stdtypes,STDTYPE_fun__tab_u0_I__u0)))) return k;
|
945
|
-
if (k=unif_argfun()) return k;
|
946
|
-
}
|
947
|
-
if (!parser->next(0)) return 0;
|
948
|
-
if (strcmp(parser->token,"."))
|
949
|
-
{
|
950
|
-
parser->giveback();
|
951
|
-
if (ind>=0)
|
952
|
-
{
|
953
|
-
bcint_byte_or_int(ind);
|
954
|
-
}
|
955
|
-
return 0;
|
956
|
-
}
|
957
|
-
if (ind>=0) bc_byte_or_int(ind,OPfetchb,OPfetch);
|
958
|
-
else bc->addchar(OPfetch);
|
959
|
-
}
|
960
|
-
}
|
961
|
-
|
962
|
-
// parsing d'un pointeur de fonction
|
963
|
-
int Compiler::parsepntfun()
|
964
|
-
{
|
965
|
-
int k;
|
966
|
-
|
967
|
-
int val;
|
968
|
-
int ref;
|
969
|
-
|
970
|
-
if (!parser->next(0))
|
971
|
-
{
|
972
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : function name expected (found EOF)\n");
|
973
|
-
return MTLERR_SN;
|
974
|
-
}
|
975
|
-
val=-1;
|
976
|
-
int *p;
|
977
|
-
if (p=searchref(PNTTOVAL(newpackage),parser->token)) // recherche dans les autres globales
|
978
|
-
{
|
979
|
-
ref=PNTTOVAL(p);
|
980
|
-
val=0;
|
981
|
-
}
|
982
|
-
if (val!=-1)
|
983
|
-
{
|
984
|
-
int* p=VALTOPNT(ref);
|
985
|
-
int code=VALTOINT(TABGET(p,REF_CODE));
|
986
|
-
|
987
|
-
if (code>=0)
|
988
|
-
{
|
989
|
-
int v=0;
|
990
|
-
if (TABGET(p,REF_PACKAGE)!=NIL) v=VALTOINT(TABGET(p,REF_PACKAGE));
|
991
|
-
else
|
992
|
-
{
|
993
|
-
char *ppp=parser->token;
|
994
|
-
v=-VALTOINT(TABGET(VALTOPNT(TABGET(p,REF_VAL)),FUN_BC));
|
995
|
-
}
|
996
|
-
// pointeur d'une fonction virtuelle
|
997
|
-
bcint_byte_or_int(v);
|
998
|
-
if (p!=newref)
|
999
|
-
{
|
1000
|
-
if (k=copytype(VALTOPNT(TABGET(p,REF_TYPE)))) return k;
|
1001
|
-
}
|
1002
|
-
else if (k=STACKPUSH(m,TABGET(p,REF_TYPE))) return k;
|
1003
|
-
return 0;
|
1004
|
-
}
|
1005
|
-
}
|
1006
|
-
|
1007
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : function name expected (found '%s')\n",parser->token);
|
1008
|
-
return MTLERR_SN;
|
1009
|
-
}
|
1010
|
-
|
1011
|
-
|
1012
|
-
// parsing du call ... ... (le 'call' a d�j� �t� lu)
|
1013
|
-
int Compiler::parsecall()
|
1014
|
-
{
|
1015
|
-
int k;
|
1016
|
-
|
1017
|
-
if (k=parseexpression()) return k; // lire la fonction
|
1018
|
-
|
1019
|
-
if ((parser->next(0))&&(!strcmp(parser->token,"[")))
|
1020
|
-
{
|
1021
|
-
int nval=0;
|
1022
|
-
while(1)
|
1023
|
-
{
|
1024
|
-
if (!parser->next(0))
|
1025
|
-
{
|
1026
|
-
PRINTF(m)(LOG_COMPILER,"Compiler : ']' expected (found EOF)\n");
|
1027
|
-
return MTLERR_SN;
|
1028
|
-
}
|
1029
|
-
if (!strcmp(parser->token,"]"))
|
1030
|
-
{
|
1031
|
-
bc_byte_or_int(nval,OPcallrb,OPcallr);
|
1032
|
-
if (k=createnodetuple(nval)) return k;
|
1033
|
-
if (k=createnodetuple(2)) return k;
|
1034
|
-
if (k=copytype(VALTOPNT(TABGET(stdtypes,STDTYPE_fun__fun_u0_u1_u0__u1)))) return k;
|
1035
|
-
return unif_argfun();
|
1036
|
-
}
|
1037
|
-
parser->giveback();
|
1038
|
-
if (k=parseexpression()) return k;
|
1039
|
-
nval++;
|
1040
|
-
}
|
1041
|
-
}
|
1042
|
-
else
|
1043
|
-
{
|
1044
|
-
parser->giveback();
|
1045
|
-
if (k=parseexpression()) return k; // lire les arguments
|
1046
|
-
|
1047
|
-
bc->addchar(OPcall);
|
1048
|
-
if (k=createnodetuple(2)) return k;
|
1049
|
-
if (k=copytype(VALTOPNT(TABGET(stdtypes,STDTYPE_fun__fun_u0_u1_u0__u1)))) return k;
|
1050
|
-
return unif_argfun();
|
1051
|
-
}
|
1052
|
-
}
|
1053
|
-
|