nabaztag_hack_kit 0.1.0.beta3 → 0.1.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -2
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +2 -2
  5. data/CHANGELOG.md +17 -2
  6. data/LICENSE +21 -0
  7. data/README.md +115 -44
  8. data/Rakefile +2 -6
  9. data/bytecode/{Commands.md → _docs/commands.md} +0 -0
  10. data/bytecode/{Docs.md → _docs/grammar.md} +0 -0
  11. data/bytecode/_docs/grammar.pdf +0 -0
  12. data/bytecode/{src → _original}/README.md +0 -0
  13. data/bytecode/{src → _original}/lib/arp.mtl +0 -0
  14. data/bytecode/{src → _original}/lib/cfg.mtl +0 -0
  15. data/bytecode/{src → _original}/lib/choreos.mtl +0 -0
  16. data/bytecode/{src → _original}/lib/dhcp.mtl +0 -0
  17. data/bytecode/{src → _original}/lib/dns.mtl +0 -0
  18. data/bytecode/{src → _original}/lib/http.mtl +0 -0
  19. data/bytecode/{src → _original}/lib/tcp.mtl +0 -0
  20. data/bytecode/{src → _original}/lib/udp.mtl +0 -0
  21. data/bytecode/{src → _original}/lib/util.mtl +0 -0
  22. data/bytecode/{src → _original}/lib/var.mtl +0 -0
  23. data/bytecode/{src → _original}/lib/wav.mtl +0 -0
  24. data/bytecode/{src → _original}/lib/wifi.mtl +0 -0
  25. data/bytecode/{src → _original}/nominal-ping.mtl +0 -0
  26. data/bytecode/main.mtl +11 -11
  27. data/bytecode/test/test.mtl +8 -8
  28. data/examples/basic/Gemfile +1 -3
  29. data/examples/basic/config.ru +14 -4
  30. data/examples/record/Gemfile +0 -5
  31. data/examples/record/{config.ru.example → config.ru} +2 -2
  32. data/examples/record/server.rb +0 -2
  33. data/ext/Makefile +10 -0
  34. data/ext/bin/mtl_comp +29 -0
  35. data/{bytecode → ext}/bin/mtl_merge +0 -0
  36. data/ext/bin/mtl_simu +29 -0
  37. data/{bytecode/src/mtl → ext}/extconf.rb +0 -0
  38. data/ext/mtl_linux/.gitignore +7 -0
  39. data/ext/mtl_linux/LICENSE +21 -0
  40. data/ext/mtl_linux/Makefile +116 -0
  41. data/ext/mtl_linux/MetalC.project +196 -0
  42. data/ext/mtl_linux/conf.bin +0 -0
  43. data/{bytecode/src/mtl → ext/mtl_linux}/conf.bin.sans_password +0 -0
  44. data/{bytecode/src/mtl → ext/mtl_linux}/config.txt +0 -0
  45. data/ext/mtl_linux/inc/log.h +21 -0
  46. data/{bytecode/src/mtl → ext/mtl_linux/inc}/properties.h +0 -0
  47. data/{bytecode/src/mtl/linux_simuaudio.h → ext/mtl_linux/inc/simu/linux/simuaudio.h} +0 -0
  48. data/{bytecode/src/mtl/linux_simunet.h → ext/mtl_linux/inc/simu/linux/simunet.h} +0 -0
  49. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simuaudio.h +18 -18
  50. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simunet.h +0 -0
  51. data/ext/mtl_linux/inc/vcomp/compiler.h +200 -0
  52. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/file.h +11 -11
  53. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/filesystem.h +0 -0
  54. data/ext/mtl_linux/inc/vcomp/interpreter.h +121 -0
  55. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/memory.h +120 -92
  56. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/param.h +0 -0
  57. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/parser.h +27 -27
  58. data/ext/mtl_linux/inc/vcomp/prodbuffer.h +42 -0
  59. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/resource.h +1 -1
  60. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/terminal.h +8 -8
  61. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/util.h +7 -7
  62. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vaudio.h +0 -0
  63. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vbc.h +1 -1
  64. data/ext/mtl_linux/inc/vm/vbc_str.h +167 -0
  65. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vinterp.h +0 -0
  66. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vloader.h +0 -0
  67. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vlog.h +0 -0
  68. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vmem.h +0 -0
  69. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vnet.h +0 -0
  70. data/ext/mtl_linux/nominal.mtl +3959 -0
  71. data/ext/mtl_linux/src/comp/main.cpp +123 -0
  72. data/ext/mtl_linux/src/simu/dumpbc.c +2566 -0
  73. data/ext/mtl_linux/src/simu/linux/main.cpp +288 -0
  74. data/ext/mtl_linux/src/simu/linux/simu.c +309 -0
  75. data/ext/mtl_linux/src/simu/linux/simuaudio.c +44 -0
  76. data/ext/mtl_linux/src/simu/linux/simunet.c +707 -0
  77. data/ext/mtl_linux/src/simu/log.c +340 -0
  78. data/ext/mtl_linux/src/simu/properties.c +368 -0
  79. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/GTKANAL.H +0 -0
  80. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/LAYER3.C +0 -0
  81. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/TABINIT.C +0 -0
  82. data/ext/mtl_linux/src/simu/win/mp3/common.c +302 -0
  83. data/ext/mtl_linux/src/simu/win/mp3/dct64_i386.c +316 -0
  84. data/ext/mtl_linux/src/simu/win/mp3/decode_i386.c +160 -0
  85. data/ext/mtl_linux/src/simu/win/mp3/huffman.h +332 -0
  86. data/ext/mtl_linux/src/simu/win/mp3/interface.c +276 -0
  87. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/mpg123.h +34 -30
  88. data/ext/mtl_linux/src/simu/win/mp3/mpglib.h +47 -0
  89. data/ext/mtl_linux/src/simu/win/simu.c +819 -0
  90. data/ext/mtl_linux/src/simu/win/simuaudio.c +787 -0
  91. data/ext/mtl_linux/src/simu/win/simunet.c +489 -0
  92. data/ext/mtl_linux/src/vcomp/bootstrap.cpp +95 -0
  93. data/ext/mtl_linux/src/vcomp/compiler.cpp +587 -0
  94. data/ext/mtl_linux/src/vcomp/compiler_file.cpp +1253 -0
  95. data/ext/mtl_linux/src/vcomp/compiler_prog.cpp +437 -0
  96. data/ext/mtl_linux/src/vcomp/compiler_term.cpp +1500 -0
  97. data/ext/mtl_linux/src/vcomp/compiler_type.cpp +1238 -0
  98. data/ext/mtl_linux/src/vcomp/compiler_var.cpp +502 -0
  99. data/ext/mtl_linux/src/vcomp/file.cpp +100 -0
  100. data/ext/mtl_linux/src/vcomp/interpreter.cpp +93 -0
  101. data/ext/mtl_linux/src/vcomp/memory.cpp +313 -0
  102. data/ext/mtl_linux/src/vcomp/parser.cpp +584 -0
  103. data/ext/mtl_linux/src/vcomp/parser_xml.cpp +137 -0
  104. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/prodbuffer.cpp +57 -36
  105. data/ext/mtl_linux/src/vcomp/stdlib_core.cpp +130 -0
  106. data/ext/mtl_linux/src/vcomp/terminal.cpp +80 -0
  107. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/util.cpp +18 -11
  108. data/ext/mtl_linux/src/vm/vaudio.c +830 -0
  109. data/ext/mtl_linux/src/vm/vinterp.c +1780 -0
  110. data/ext/mtl_linux/src/vm/vloader.c +139 -0
  111. data/ext/mtl_linux/src/vm/vlog.c +782 -0
  112. data/ext/mtl_linux/src/vm/vmem.c +461 -0
  113. data/ext/mtl_linux/src/vm/vnet.c +298 -0
  114. data/{bytecode/src/mtl → ext/mtl_linux}/utils/correct_const.sh +0 -0
  115. data/lib/nabaztag_hack_kit/server.rb +4 -7
  116. data/lib/nabaztag_hack_kit/version.rb +1 -1
  117. data/lib/nabaztag_hack_kit.rb +2 -2
  118. data/nabaztag_hack_kit.gemspec +10 -11
  119. data/spec/integration/server_spec.rb +3 -3
  120. data/spec/spec_helper.rb +2 -0
  121. data/spec/unit/message_spec.rb +12 -18
  122. data/spec/unit/server_spec.rb +13 -10
  123. metadata +145 -137
  124. data/bytecode/bin/mtl_comp +0 -50
  125. data/bytecode/bin/mtl_simu +0 -49
  126. data/bytecode/src/mtl/Makefile +0 -42
  127. data/bytecode/src/mtl/README.md +0 -13
  128. data/bytecode/src/mtl/bc.cpp +0 -1891
  129. data/bytecode/src/mtl/dumpbc.c +0 -2566
  130. data/bytecode/src/mtl/linux_simu.c +0 -271
  131. data/bytecode/src/mtl/linux_simuaudio.c +0 -16
  132. data/bytecode/src/mtl/linux_simunet.c +0 -620
  133. data/bytecode/src/mtl/log.c +0 -297
  134. data/bytecode/src/mtl/log.h +0 -20
  135. data/bytecode/src/mtl/main_compiler.cpp +0 -104
  136. data/bytecode/src/mtl/main_simu.cpp +0 -221
  137. data/bytecode/src/mtl/mp3/common.c +0 -265
  138. data/bytecode/src/mtl/mp3/dct64_i386.c +0 -316
  139. data/bytecode/src/mtl/mp3/decode_i386.c +0 -155
  140. data/bytecode/src/mtl/mp3/huffman.h +0 -332
  141. data/bytecode/src/mtl/mp3/interface.c +0 -258
  142. data/bytecode/src/mtl/mp3/mpglib.h +0 -44
  143. data/bytecode/src/mtl/properties.c +0 -293
  144. data/bytecode/src/mtl/simu.c +0 -750
  145. data/bytecode/src/mtl/simuaudio.c +0 -662
  146. data/bytecode/src/mtl/simunet.c +0 -400
  147. data/bytecode/src/mtl/vaudio.c +0 -677
  148. data/bytecode/src/mtl/vbc_str.h +0 -166
  149. data/bytecode/src/mtl/vcomp/Makefile +0 -29
  150. data/bytecode/src/mtl/vcomp/bootstrap.cpp +0 -89
  151. data/bytecode/src/mtl/vcomp/compiler.cpp +0 -470
  152. data/bytecode/src/mtl/vcomp/compiler.h +0 -200
  153. data/bytecode/src/mtl/vcomp/compiler_file.cpp +0 -929
  154. data/bytecode/src/mtl/vcomp/compiler_prog.cpp +0 -250
  155. data/bytecode/src/mtl/vcomp/compiler_term.cpp +0 -1053
  156. data/bytecode/src/mtl/vcomp/compiler_type.cpp +0 -872
  157. data/bytecode/src/mtl/vcomp/compiler_var.cpp +0 -289
  158. data/bytecode/src/mtl/vcomp/file.cpp +0 -79
  159. data/bytecode/src/mtl/vcomp/interpreter.cpp +0 -85
  160. data/bytecode/src/mtl/vcomp/interpreter.h +0 -121
  161. data/bytecode/src/mtl/vcomp/memory.cpp +0 -241
  162. data/bytecode/src/mtl/vcomp/parser.cpp +0 -427
  163. data/bytecode/src/mtl/vcomp/parser_xml.cpp +0 -124
  164. data/bytecode/src/mtl/vcomp/prodbuffer.h +0 -42
  165. data/bytecode/src/mtl/vcomp/stdlib_core.cpp +0 -122
  166. data/bytecode/src/mtl/vcomp/terminal.cpp +0 -73
  167. data/bytecode/src/mtl/vinterp.c +0 -1349
  168. data/bytecode/src/mtl/vloader.c +0 -127
  169. data/bytecode/src/mtl/vlog.c +0 -589
  170. data/bytecode/src/mtl/vmem.c +0 -424
  171. data/bytecode/src/mtl/vnet.c +0 -255
  172. data/examples/basic/Procfile +0 -2
  173. data/examples/basic/server.rb +0 -14
@@ -1,470 +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 "prodbuffer.h"
15
- #include "interpreter.h"
16
- #include "compiler.h"
17
-
18
-
19
- Compiler::Compiler(Memory* mem)
20
- {
21
- m=mem;
22
- bc=new Prodbuffer();
23
- outputbuf=new Prodbuffer();
24
- brelease=new Prodbuffer();
25
- };
26
-
27
- Compiler::~Compiler()
28
- {
29
- delete bc;
30
- delete outputbuf;
31
- delete brelease;
32
- };
33
-
34
-
35
- int Compiler::start()
36
- {
37
- int k;
38
-
39
- // création du package systeme
40
- if (k=createpackage("system",8)) return k;
41
- systempackage=STACKGET(m,0);
42
- m->addroot(VALTOPNT(systempackage)); // le package systeme devient une racine
43
- if (k=addstdlibcore()) return k;
44
- int pck=STACKREF(m);
45
-
46
- // création du tableau des types utilisés par le compilateur
47
- if (k=creategraph("I",systempackage,0)) return k;
48
- if (k=creategraph("F",systempackage,0)) return k;
49
- if (k=creategraph("S",systempackage,0)) return k;
50
- if (k=creategraph("Env",systempackage,0)) return k;
51
- if (k=creategraph("Xml",systempackage,0)) return k;
52
-
53
- if (k=creategraph("fun[u0 list u0]list u0",systempackage,0)) return k;
54
- if (k=creategraph("fun[tab u0 I]u0",systempackage,0)) return k;
55
- if (k=creategraph("fun[fun u0 u1 u0]u1",systempackage,0)) return k;
56
- if (k=DEFTAB(m,STDTYPE_LENGTH)) return k;
57
- stdtypes=VALTOPNT(STACKPULL(m));
58
- m->addroot(stdtypes);
59
-
60
- // dumppackage(systempackage);
61
- return 0;
62
- }
63
-
64
- void Compiler::stop()
65
- {
66
- }
67
-
68
- int Compiler::getsystempackage()
69
- {
70
- return systempackage;
71
- }
72
-
73
- // crée et empile un package
74
- int Compiler::createpackage(const char* name,int loghach)
75
- {
76
- int k;
77
- if (k=PUSHMALLOCCLEAR(m,PACK_LENGTH)) return k;
78
- int* p=VALTOPNT(STACKGET(m,0));
79
-
80
- if (k=STRPUSH(m,name)) return k;
81
- TABSET(m,p,PACK_NAME,STACKPULL(m));
82
-
83
- if (k=PUSHMALLOCCLEAR(m,1+(1<<loghach))) return k;
84
- TABSET(m,p,PACK_HACH,STACKPULL(m));
85
-
86
- return 0;
87
- }
88
-
89
- // calcule la fonction de hachage d'une chaine (entre 0 et 255)
90
- int Compiler::hash(char* name)
91
- {
92
- int v=0;
93
- int i=0;
94
- while(*name)
95
- {
96
- int c=(*name++)&255;
97
- c=c<<i;
98
- v+=c+(c>>8);
99
- i=(i+1)&7;
100
- }
101
- return v&255;
102
- }
103
-
104
- // ajoute une référence à un package
105
- // [ref package] -> [package]
106
- void Compiler::addreftopackage(int* ref,int* package)
107
- {
108
- int v;
109
- if (TABGET(ref,REF_NAME)!=NIL) v=hash(STRSTART(VALTOPNT(TABGET(ref,REF_NAME))));
110
- else v=hash(STRSTART(VALTOPNT(TABGET(VALTOPNT(TABGET(ref,REF_TYPE)),TYPEHEADER_LENGTH+1))));
111
-
112
- int* p=VALTOPNT(TABGET(package,PACK_HACH));
113
-
114
- // TABSET(m,ref,REF_PACKAGE,PNTTOVAL(package));
115
- v&=TABLEN(p)-2;
116
- TABSET(m,ref,REF_NEXT,TABGET(p,v));
117
- TABSET(m,p,v,PNTTOVAL(ref));
118
- v=TABLEN(p)-1;
119
- TABSET(m,ref,REF_NEXTALL,TABGET(p,v));
120
- TABSET(m,p,v,PNTTOVAL(ref));
121
- }
122
-
123
- // recherche d'un type dans un environnement
124
- int* Compiler::searchtype(int env,char* name)
125
- {
126
- int v=hash(name);
127
- while(env!=NIL)
128
- {
129
- int* p=VALTOPNT(TABGET(VALTOPNT(env),PACK_HACH));
130
- int vref=TABGET(p,v&(TABLEN(p)-2));
131
- while(vref!=NIL)
132
- {
133
- int* ref=VALTOPNT(vref);
134
- if ((TABGET(ref,REF_NAME)==NIL)
135
- &&(!strcmp(name,STRSTART(VALTOPNT(TABGET(VALTOPNT(TABGET(ref,REF_TYPE)),TYPEHEADER_LENGTH+1))))) )
136
- return ref;
137
- vref=TABGET(ref,REF_NEXT);
138
- }
139
- env=TABGET(VALTOPNT(env),PACK_NEXT);
140
- }
141
- return NULL;
142
- }
143
-
144
- // recherche d'un type non défini dans un environnement
145
- int* Compiler::searchemptytype(int env,char* name)
146
- {
147
- int v=hash(name);
148
- while(env!=NIL)
149
- {
150
- int* p=VALTOPNT(TABGET(VALTOPNT(env),PACK_HACH));
151
- int vref=TABGET(p,v&(TABLEN(p)-2));
152
- while(vref!=NIL)
153
- {
154
- int* ref=VALTOPNT(vref);
155
- if ((TABGET(ref,REF_CODE)==INTTOVAL(CODE_EMPTYTYPE))
156
- &&(!strcmp(name,STRSTART(VALTOPNT(TABGET(VALTOPNT(TABGET(ref,REF_TYPE)),TYPEHEADER_LENGTH+1))))) )
157
- return ref;
158
- vref=TABGET(ref,REF_NEXT);
159
- }
160
- env=TABGET(VALTOPNT(env),PACK_NEXT);
161
- }
162
- return NULL;
163
- }
164
-
165
- void Compiler::dumppackage(int env)
166
- {
167
- while(env!=NIL)
168
- {
169
- PRINTF(m)(LOG_DEVCORE,"package %s",STRSTART(VALTOPNT(TABGET(VALTOPNT(env),PACK_NAME))));
170
- int* p=VALTOPNT(TABGET(VALTOPNT(env),PACK_HACH));
171
- int vref=TABGET(p,TABLEN(p)-1);
172
- while(vref!=NIL)
173
- {
174
- int* ref=VALTOPNT(vref);
175
- char* name=NULL;
176
- if (TABGET(ref,REF_NAME)!=NIL) name=STRSTART(VALTOPNT(TABGET(ref,REF_NAME)));
177
- if (!name) name=STRSTART(VALTOPNT(TABGET(VALTOPNT(TABGET(ref,REF_TYPE)),TYPEHEADER_LENGTH+1)));
178
- if (name) PRINTF(m)(LOG_DEVCORE," %s",name);
179
- vref=TABGET(ref,REF_NEXTALL);
180
- }
181
- PRINTF(m)(LOG_DEVCORE,"\n");
182
- env=TABGET(VALTOPNT(env),PACK_NEXT);
183
- }
184
- }
185
-
186
- int Compiler::searchbytype(int env,int type)
187
- {
188
- while(env!=NIL)
189
- {
190
- int* p=VALTOPNT(TABGET(VALTOPNT(env),PACK_HACH));
191
- int vref=TABGET(p,TABLEN(p)-1);
192
- while(vref!=NIL)
193
- {
194
- if (TABGET(VALTOPNT(vref),REF_TYPE)==type) return vref;
195
- vref=TABGET(VALTOPNT(vref),REF_NEXTALL);
196
- }
197
- env=TABGET(VALTOPNT(env),PACK_NEXT);
198
- }
199
- return NIL;
200
- }
201
-
202
- int Compiler::fillproto(int env,int* fun)
203
- {
204
- int k;
205
- int v=hash(STRSTART(VALTOPNT(TABGET(fun,REF_NAME))));
206
- while(env!=NIL)
207
- {
208
- int* p=VALTOPNT(TABGET(VALTOPNT(env),PACK_HACH));
209
- int vref=TABGET(p,v&(TABLEN(p)-2));
210
- while(vref!=NIL)
211
- {
212
- int* ref=VALTOPNT(vref);
213
- if ((ref!=fun)&&(VALTOINT(TABGET(ref,REF_CODE))>=0)) // on recherche des fonctions
214
- {
215
- if ( (!strcmp(STRSTART(VALTOPNT(TABGET(fun,REF_NAME))),STRSTART(VALTOPNT(TABGET(ref,REF_NAME)))))
216
- &&(TABGET(ref,REF_VAL)==NIL) )
217
- {
218
- if (k=unifbigger(VALTOPNT(TABGET(fun,REF_TYPE)),VALTOPNT(TABGET(ref,REF_TYPE))))
219
- {
220
- PRINTF(m)(LOG_COMPILER,"Compiler : prototype does not match\n");
221
- return k;
222
- }
223
- TABSET(m,ref,REF_VAL,TABGET(fun,REF_VAL));
224
- // TABSET(m,ref,REF_PACKAGE,TABGET(fun,REF_PACKAGE));
225
- }
226
- }
227
- vref=TABGET(ref,REF_NEXT);
228
- }
229
- env=TABGET(VALTOPNT(env),PACK_NEXT);
230
- }
231
- return 0;
232
- }
233
-
234
- int Compiler::findproto(int env,int* fun)
235
- {
236
- int v=hash(STRSTART(VALTOPNT(TABGET(fun,REF_NAME))));
237
- while(env!=NIL)
238
- {
239
- int* p=VALTOPNT(TABGET(VALTOPNT(env),PACK_HACH));
240
- int vref=TABGET(p,v&(TABLEN(p)-2));
241
- while(vref!=NIL)
242
- {
243
- int* ref=VALTOPNT(vref);
244
- if ((ref!=fun)&&(VALTOINT(TABGET(ref,REF_CODE))>=0)) // on recherche des fonctions
245
- {
246
- if ( (!strcmp(STRSTART(VALTOPNT(TABGET(fun,REF_NAME))),STRSTART(VALTOPNT(TABGET(ref,REF_NAME)))))
247
- &&(TABGET(ref,REF_VAL)==NIL) )
248
- {
249
- return TABGET(ref,REF_PACKAGE);
250
- }
251
- }
252
- vref=TABGET(ref,REF_NEXT);
253
- }
254
- env=TABGET(VALTOPNT(env),PACK_NEXT);
255
- }
256
- return NIL;
257
- }
258
-
259
- // recherche d'une référence dans un environnement
260
- int* Compiler::searchref(int env,char* name)
261
- {
262
- int v=hash(name);
263
- while(env!=NIL)
264
- {
265
- int* p=VALTOPNT(TABGET(VALTOPNT(env),PACK_HACH));
266
- int vref=TABGET(p,v&(TABLEN(p)-2));
267
- while(vref!=NIL)
268
- {
269
- int* ref=VALTOPNT(vref);
270
- if ((TABGET(ref,REF_NAME)!=NIL)
271
- &&(!strcmp(name,STRSTART(VALTOPNT(TABGET(ref,REF_NAME))))) )
272
- {
273
- // à partir du moment où on recherche cette référence, c'est
274
- // qu'elle est utlisé quelque part, donc...
275
- TABSET(m,ref,REF_USED,INTTOVAL(1));
276
-
277
- return ref;
278
- }
279
- vref=TABGET(ref,REF_NEXT);
280
- }
281
- env=TABGET(VALTOPNT(env),PACK_NEXT);
282
- }
283
- return NULL;
284
- }
285
-
286
- // recherche d'une référence dans un environnement, ne marque pas la référence comme utilisée
287
- int* Compiler::searchref_nosetused(int env,char* name)
288
- {
289
- int v=hash(name);
290
- while(env!=NIL)
291
- {
292
- int* p=VALTOPNT(TABGET(VALTOPNT(env),PACK_HACH));
293
- int vref=TABGET(p,v&(TABLEN(p)-2));
294
- while(vref!=NIL)
295
- {
296
- int* ref=VALTOPNT(vref);
297
- if ((TABGET(ref,REF_NAME)!=NIL)
298
- &&(!strcmp(name,STRSTART(VALTOPNT(TABGET(ref,REF_NAME))))) )
299
- return ref;
300
- vref=TABGET(ref,REF_NEXT);
301
- }
302
- env=TABGET(VALTOPNT(env),PACK_NEXT);
303
- }
304
- return NULL;
305
- }
306
-
307
-
308
-
309
- // ajout d'un label dans une liste de labels
310
- int Compiler::addlabel(int base,const char* name,int val,int ref)
311
- {
312
- int k;
313
- int* p=MALLOCCLEAR(m,LABELLIST_LENGTH);
314
- if (!p) return MTLERR_OM;
315
- TABSET(m,p,LABELLIST_NEXT,STACKGETFROMREF(m,base,0));
316
- STACKSETFROMREF(m,base,0,PNTTOVAL(p));
317
-
318
- if (k=STRPUSH(m,name)) return k;
319
- TABSET(m,p,LABELLIST_NAME,STACKPULL(m));
320
- TABSET(m,p,LABELLIST_VAL,val);
321
- TABSET(m,p,LABELLIST_REF,ref);
322
- return 0;
323
- }
324
-
325
- // compte le nombre de labels
326
- int Compiler::nblabels(int base)
327
- {
328
- int n=0;
329
- int vlab=STACKGETFROMREF(m,base,0);
330
- while(vlab!=NIL)
331
- {
332
- n++;
333
- vlab=TABGET(VALTOPNT(vlab),LABELLIST_NEXT);
334
- }
335
- return n;
336
- }
337
-
338
- void Compiler::removenlabels(int base,int n)
339
- {
340
- while(n>0)
341
- {
342
- STACKSETFROMREF(m,base,0,TABGET(VALTOPNT(STACKGETFROMREF(m,base,0)),LABELLIST_NEXT));
343
- n--;
344
- }
345
- }
346
-
347
- // recherche d'un label dans une liste de labels
348
- int Compiler::searchlabel_byname(int base,char* name,int* val,int* ref)
349
- {
350
- int vlab=STACKGETFROMREF(m,base,0);
351
- while(vlab!=NIL)
352
- {
353
- int* lab=VALTOPNT(vlab);
354
- if (!strcmp(name,STRSTART(VALTOPNT(TABGET(lab,LABELLIST_NAME)))) )
355
- {
356
- if (val) *val=TABGET(lab,LABELLIST_VAL);
357
- if (ref) *ref=TABGET(lab,LABELLIST_REF);
358
- return 0;
359
- }
360
- vlab=TABGET(lab,LABELLIST_NEXT);
361
- }
362
- return -1;
363
- }
364
-
365
- // recherche d'un label dans une liste de labels
366
- int Compiler::searchlabel_byval(int base,int val,char** name)
367
- {
368
- int vlab=STACKGETFROMREF(m,base,0);
369
- while(vlab!=NIL)
370
- {
371
- int* lab=VALTOPNT(vlab);
372
- if (val==TABGET(lab,LABELLIST_VAL))
373
- {
374
- *name=STRSTART(VALTOPNT(TABGET(lab,LABELLIST_NAME)));
375
- return 0;
376
- }
377
- vlab=TABGET(lab,LABELLIST_NEXT);
378
- }
379
- return -1;
380
- }
381
-
382
- // création d'un tuple à partir d'une liste de labels
383
- int* Compiler::tuplefromlabels(int base)
384
- {
385
- int n=nblabels(base);
386
- int* t=MALLOC(m,n,TYPE_TAB);
387
- if (!t) return t;
388
-
389
- int vlab=STACKGETFROMREF(m,base,0);
390
- int i; for(i=n-1;i>=0;i--)
391
- {
392
- int* lab=VALTOPNT(vlab);
393
- TABSET(m,t,i,TABGET(lab,LABELLIST_REF));
394
- vlab=TABGET(lab,LABELLIST_NEXT);
395
- }
396
- return t;
397
- }
398
-
399
-
400
- // ajoute des fonctions à un package
401
- int Compiler::addnative(int nref, const char** nameref, int* valref
402
- , int* coderef, const char** typeref,void* arg)
403
- {
404
- int i,k;
405
-
406
- for(i=0;i<nref;i++)
407
- {
408
- int* p=MALLOCCLEAR(m,REF_LENGTH);
409
- if (!p) return MTLERR_OM;
410
- if (k=STACKPUSH(m,PNTTOVAL(p))) return MTLERR_OM;
411
-
412
- if (nameref[i])
413
- {
414
- if (k=STRPUSH(m,nameref[i])) return k;
415
- TABSET(m,p,REF_NAME,STACKPULL(m));
416
- }
417
-
418
- TABSET(m,p,REF_CODE,INTTOVAL(coderef[i]));
419
-
420
- if (coderef[i]>=0)
421
- {
422
- if (k=creategraph(typeref[i],systempackage,0)) return k;
423
- TABSET(m,p,REF_TYPE,STACKPULL(m));
424
-
425
- // if (k=PUSHPNT(m,(int*)valref[i])) return k;
426
- if (k=STACKPUSH(m,INTTOVAL(valref[i]))) return k;
427
-
428
- int* fun=MALLOCCLEAR(m,FUN_LENGTH);
429
- if (!fun) return MTLERR_OM;
430
- TABSET(m,p,REF_VAL,PNTTOVAL(fun));
431
-
432
- TABSET(m,fun,FUN_NBARGS,INTTOVAL(coderef[i]));
433
- TABSET(m,fun,FUN_NBLOCALS,NIL);
434
- // PRINTF(m)(1,"valref %s = %x\n",nameref[i],valref[i]);
435
- // TABSET(m,fun,FUN_BC,((int)valref[i])<<1);
436
- TABSET(m,fun,FUN_BC,STACKPULL(m));
437
- TABSET(m,fun,FUN_REF,(int)arg);
438
- TABSET(m,fun,FUN_REFERENCE,PNTTOVAL(p));
439
- }
440
- else if ((coderef[i]==CODE_VAR)
441
- ||(coderef[i]==CODE_CONS)||(coderef[i]==CODE_CONS0))
442
- {
443
- if (k=creategraph(typeref[i],systempackage,0)) return k;
444
- TABSET(m,p,REF_TYPE,STACKPULL(m));
445
- TABSET(m,p,REF_VAL,(int)valref[i]);
446
- }
447
- else if (coderef[i]==CODE_FIELD)
448
- {
449
- if (k=creategraph(typeref[i],systempackage,0)) return k;
450
- if (k=STACKPUSH(m,(int)valref[i])) return k;
451
- int vtype=searchbytype(systempackage,
452
- TABGET(argsfromfun(VALTOPNT(STACKGET(m,1))),TYPEHEADER_LENGTH));
453
- if (k=STACKPUSH(m,vtype)) return k;
454
- if (k=DEFTAB(m,2)) return k;
455
- TABSET(m,p,REF_VAL,STACKPULL(m));
456
- TABSET(m,p,REF_TYPE,STACKPULL(m));
457
- }
458
- else if ((coderef[i]==CODE_TYPE)||(coderef[i]==CODE_SUM)||(coderef[i]==CODE_STRUCT))
459
- {
460
- if (k=createnodetypecore(typeref[i])) return k;
461
- TABSET(m,p,REF_TYPE,STACKPULL(m));
462
- TABSET(m,p,REF_VAL,(int)valref[i]);
463
- }
464
- addreftopackage(p,VALTOPNT(systempackage));
465
- STACKDROP(m);
466
- }
467
- return 0;
468
- }
469
-
470
-
@@ -1,200 +0,0 @@
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 _COMPILER_
10
- #define _COMPILER_
11
-
12
- #include"interpreter.h"
13
-
14
- class Memory;
15
- class Parser;
16
- class Prodbuffer;
17
-
18
- class Compiler
19
- {
20
- private:
21
- Memory* m;
22
- int systempackage;
23
- int* stdtypes;
24
-
25
- Prodbuffer* bc; // structure de production de bytecode
26
-
27
- Prodbuffer* outputbuf; // structure de production des messages de type
28
-
29
-
30
- Parser* parser;
31
- int* newpackage;
32
- int* newref;
33
- int globals;
34
- int locals;
35
- int nblocals;
36
-
37
- int ifuns;
38
-
39
- // typage
40
- int createnodetypecore(const char* name);
41
- int createnodetypecore(int name);
42
- int createnodetype(int type);
43
- int createnodetuple(int size);
44
- int createnodetupleval(int size);
45
-
46
- int* actualtype(int* p);
47
-
48
- int parsegraph(Parser* p,int env,int mono,int rec,int labels,int newvars,int* rnode);
49
- int parse_rnode(int* p);
50
-
51
- int creategraph(Parser* p,int env,int mono);
52
- int creategraph(Parser* p,int env,int mono,int labels);
53
- int creategraph(const char* src,int env,int mono);
54
-
55
- int recechograph(Prodbuffer *output,int* p,int rec,int labels);
56
-
57
- int reccopytype(int* p);
58
- int recresetcopy(int* p);
59
-
60
- int recgoweak(int* p);
61
-
62
- int restoreactual(int* t,int* s,int vt,int vs,int k);
63
- int recunif(int* x,int* y);
64
- int unif(int* x,int* y);
65
- int unif_argfun();
66
-
67
- int unifbigger(int* x,int* y);
68
-
69
- int* argsfromfun(int *f);
70
-
71
- void echonode(int code,int* p);
72
- // packages
73
- int hash(char* name);
74
- int createpackage(const char* name,int loghach);
75
- void addreftopackage(int* ref,int* package);
76
- int* searchtype(int env,char* name);
77
- int* searchemptytype(int env,char* name);
78
-
79
- void dumppackage(int env);
80
-
81
- int searchbytype(int env,int type);
82
-
83
- // liste de labels
84
- int addlabel(int base,const char* name,int val,int ref);
85
- int nblabels(int base);
86
- void removenlabels(int base,int n);
87
- int searchlabel_byname(int base,char* name,int* val,int* ref);
88
- int searchlabel_byval(int base,int val,char** name);
89
- int* tuplefromlabels(int base);
90
-
91
- // compilation
92
- int parsefile(int ifdef);
93
- int parsevar();
94
- int parseconst();
95
- int parseproto();
96
- int parseifdef(int ifndef);
97
- int skipifdef();
98
- int fillproto(int env,int* fun);
99
- int findproto(int env,int* fun);
100
- int parsetype();
101
- int parsestruct();
102
- int parsesum();
103
-
104
- int parsefun();
105
- int parseprogram();
106
- int parseexpression();
107
- int parsearithm();
108
- int parsea1();
109
- int parsea2();
110
- int parsea3();
111
- int parsea4();
112
- int parsea5();
113
- int parsea6();
114
- int parseterm();
115
- int parseref();
116
- int parseif();
117
- int parselet();
118
- int parseset();
119
- int parsewhile();
120
- int parsefor();
121
- int parsepntfun();
122
- int parselink();
123
- int parsecall();
124
- int parselocals();
125
- int parsestring();
126
- int parsefields(int* p);
127
- int parsematch();
128
- int parsematchcons(int* end);
129
-
130
- int parsegetpoint();
131
- int parsesetpoint(int local,int ind,int* opstore);
132
-
133
- int parseupdate();
134
- int parseupdatevals();
135
-
136
- // parsing variables
137
- int parseval();
138
- int parseval3();
139
- int parseval4();
140
- int parseval5();
141
- int parseval6();
142
- int parseval7();
143
-
144
- // production bytecode
145
- void bc_byte_or_int(int val,int opbyte,int opint);
146
- void bcint_byte_or_int(int val);
147
- // autres
148
- int addstdlibcore();
149
- int addstdlibstr();
150
- int addstdlibbuf();
151
- int addstdlibfiles();
152
-
153
- int recglobal(int val,Prodbuffer *b);
154
- int recglobals(int vlab,Prodbuffer *b);
155
- int recbc(int vref,Prodbuffer *b,Prodbuffer *btab,int offset);
156
-
157
- public:
158
- Prodbuffer* brelease;
159
- Compiler(Memory* mem);
160
- ~Compiler();
161
- int start();
162
- void stop();
163
- int addnative(int nref, const char** nameref, int* valref
164
- , int* coderef, const char** typeref,void* arg);
165
-
166
- int gocompile(int type); // [filename/src packages] -> [packages]
167
- int getsystempackage();
168
-
169
- int* searchref(int env,char* name);
170
- int* searchref_nosetused(int env,char* name);
171
-
172
-
173
- int echograph(Prodbuffer *output,int* p);
174
- int copytype(int* p);
175
- int recunifbigger(int* x,int* y);
176
-
177
- };
178
-
179
- #define LABELLIST_LENGTH 4
180
- #define LABELLIST_NAME 0
181
- #define LABELLIST_VAL 1
182
- #define LABELLIST_REF 2
183
- #define LABELLIST_NEXT 3
184
-
185
- #define STDTYPE_LENGTH 8
186
- #define STDTYPE_I 0
187
- #define STDTYPE_F 1
188
- #define STDTYPE_S 2
189
- #define STDTYPE_Env 3
190
- #define STDTYPE_Xml 4
191
- #define STDTYPE_fun__u0_list_u0__list_u0 5
192
- #define STDTYPE_fun__tab_u0_I__u0 6
193
- #define STDTYPE_fun__fun_u0_u1_u0__u1 7
194
-
195
-
196
- #define COMPILE_FROMFILE 0
197
- #define COMPILE_FROMSTRING 1
198
-
199
-
200
- #endif