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,872 +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
-
18
- // types
19
-
20
- // cr�ation d'un noeud de type basique (�ventuellement param�trique)
21
- int Compiler::createnodetypecore(const char* name)
22
- {
23
- int k;
24
-
25
- int* p=MALLOCCLEAR(m,TYPEHEADER_LENGTH+2);
26
- if (!p) return MTLERR_OM;
27
- if (STACKPUSH(m,PNTTOVAL(p))) return MTLERR_OM;
28
-
29
- if (k=STRPUSH(m,name)) return k;
30
-
31
- TABSET(m,p,TYPEHEADER_CODE,INTTOVAL(TYPENAME_CORE));
32
- TABSET(m,p,TYPEHEADER_LENGTH+1,STACKPULL(m));
33
- return 0;
34
- }
35
-
36
- // cr�ation d'un noeud de type basique (�ventuellement param�trique)
37
- int Compiler::createnodetypecore(int name)
38
- {
39
- int* p=MALLOCCLEAR(m,TYPEHEADER_LENGTH+2);
40
- if (!p) return MTLERR_OM;
41
- if (STACKPUSH(m,PNTTOVAL(p))) return MTLERR_OM;
42
-
43
- TABSET(m,p,TYPEHEADER_CODE,INTTOVAL(TYPENAME_CORE));
44
- TABSET(m,p,TYPEHEADER_LENGTH+1,name);
45
- return 0;
46
- }
47
-
48
- // cr�ation d'un noeud de type non basique
49
- int Compiler::createnodetype(int type)
50
- {
51
- int size=0;
52
- if ((type==TYPENAME_UNDEF)||(type==TYPENAME_WEAK)) size=0;
53
- if ((type==TYPENAME_LIST)||(type==TYPENAME_TAB)||(type==TYPENAME_REC)) size=1;
54
- if (type==TYPENAME_FUN) size=2;
55
-
56
- int* p=MALLOCCLEAR(m,TYPEHEADER_LENGTH+size);
57
- if (!p) return MTLERR_OM;
58
- if (STACKPUSH(m,PNTTOVAL(p))) return MTLERR_OM;
59
-
60
- TABSET(m,p,TYPEHEADER_CODE,INTTOVAL(type));
61
- return 0;
62
- }
63
-
64
- // cr�ation d'un noeud de type tuple (n �l�ments empil�s)
65
- // empile le r�sultat
66
- int Compiler::createnodetuple(int size)
67
- {
68
- int* p=MALLOCCLEAR(m,TYPEHEADER_LENGTH+size);
69
- if (!p) return MTLERR_OM;
70
- TABSET(m,p,TYPEHEADER_CODE,INTTOVAL(TYPENAME_TUPLE));
71
- int i; for(i=size-1;i>=0;i--) TABSET(m,p,TYPEHEADER_LENGTH+i,STACKPULL(m));
72
- if (STACKPUSH(m,PNTTOVAL(p))) return MTLERR_OM;
73
- return 0;
74
- }
75
-
76
- // cr�ation d'un noeud de type tuple dans la compilation de valeurs (n �l�ments empil�s au rangs 0, 2, 4, 2n-2)
77
- // empile le r�sultat, sans d�piler les valeurs du tuple
78
- int Compiler::createnodetupleval(int size)
79
- {
80
- int* p=MALLOCCLEAR(m,TYPEHEADER_LENGTH+size);
81
- if (!p) return MTLERR_OM;
82
- TABSET(m,p,TYPEHEADER_CODE,INTTOVAL(TYPENAME_TUPLE));
83
- int i; for(i=size-1;i>=0;i--) TABSET(m,p,TYPEHEADER_LENGTH+i,STACKGET(m,2*(size-1-i)));
84
- if (STACKPUSH(m,PNTTOVAL(p))) return MTLERR_OM;
85
- return 0;
86
- }
87
-
88
- // trouve le type �quivalent
89
- int* Compiler::actualtype(int* p)
90
- {
91
- int vp=TABGET(p,TYPEHEADER_ACTUAL);
92
- if (vp!=NIL) return actualtype(VALTOPNT(vp));
93
- return p;
94
- }
95
-
96
- // production d'un type
97
- int Compiler::parsegraph(Parser* p,int env,int mono,int rec,int labels,int newvars,int* rnode)
98
- {
99
- int k,n;
100
-
101
- if (!p->next(0))
102
- {
103
- PRINTF(m)(LOG_RUNTIME,"Compiler : uncomplete type reaches EOF\n");
104
- return MTLERR_SN;
105
- }
106
-
107
- int val;
108
- if (!searchlabel_byname(labels,p->token,&val,NULL)) return STACKPUSH(m,val);
109
- if ((p->token[0]=='w')&&(isdecimal(p->token+1)))
110
- {
111
- if (k=createnodetype(TYPENAME_WEAK)) return k;
112
- return addlabel(labels,p->token,STACKGET(m,0),NIL);
113
- }
114
- if (!strcmp(p->token,"_"))
115
- {
116
- return createnodetype(TYPENAME_WEAK);
117
- }
118
- if ((p->token[0]=='u')&&(isdecimal(p->token+1)))
119
- {
120
- if (mono)
121
- {
122
- PRINTF(m)(LOG_RUNTIME,"Compiler : polymorphism (%s) not accepted here\n",p->token);
123
- return MTLERR_SN;
124
- }
125
- if (!newvars)
126
- {
127
- PRINTF(m)(LOG_RUNTIME,"Compiler : cannot accept linked variable %s here\n",p->token);
128
- return MTLERR_SN;
129
- }
130
- if (k=createnodetype(TYPENAME_UNDEF)) return k;
131
- return addlabel(labels,p->token,STACKGET(m,0),NIL);
132
- }
133
- else if ((p->token[0]=='r')&&(isdecimal(p->token+1)))
134
- {
135
- int i=mtl_atoi(p->token+1);
136
- if ((i<0)||(i>=rec))
137
- {
138
- PRINTF(m)(LOG_RUNTIME,"Compiler : recursivity out of range %d [0 %d[\n",i,rec);
139
- return MTLERR_SN;
140
- }
141
- if (k=createnodetype(TYPENAME_REC)) return k;
142
- TABSET(m,VALTOPNT(STACKGET(m,0)),TYPEHEADER_LENGTH,INTTOVAL(i));
143
- *rnode=1;
144
- return 0;
145
- }
146
- else if (!strcmp(p->token,"tab"))
147
- {
148
- if (k=createnodetype(TYPENAME_TAB)) return k;
149
- if (k=parsegraph(p,env,mono,rec+1,labels,newvars,rnode)) return k;
150
- TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0));
151
- STACKDROP(m);
152
- return 0;
153
- }
154
- else if (!strcmp(p->token,"list"))
155
- {
156
- if (k=createnodetype(TYPENAME_LIST)) return k;
157
- if (k=parsegraph(p,env,mono,rec+1,labels,newvars,rnode)) return k;
158
- TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0));
159
- STACKDROP(m);
160
- return 0;
161
- }
162
- else if (!strcmp(p->token,"fun"))
163
- {
164
- if (k=createnodetype(TYPENAME_FUN)) return k;
165
- int nblab;
166
- if (newvars)
167
- {
168
- if (k=parsegraph(p,env,mono,rec+1,labels,1,rnode)) return k;
169
- nblab=0;
170
- }
171
- else
172
- {
173
- nblab=nblabels(labels);
174
- if (k=parsegraph(p,env,mono,rec+1,labels,1,rnode)) return k;
175
- nblab=nblabels(labels)-nblab;
176
- }
177
- TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0));
178
- STACKDROP(m);
179
- if (k=parsegraph(p,env,mono,rec+1,labels,newvars,rnode)) return k;
180
- TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH+1,STACKGET(m,0));
181
- STACKDROP(m);
182
- removenlabels(labels,nblab);
183
- return 0;
184
- }
185
- else if (!strcmp(p->token,"["))
186
- {
187
- n=0;
188
- while(1)
189
- {
190
- if (!p->next(0))
191
- {
192
- PRINTF(m)(LOG_RUNTIME,"Compiler : uncomplete type reaches EOF\n");
193
- return MTLERR_SN;
194
- }
195
- if (!strcmp(p->token,"]"))
196
- {
197
- return createnodetuple(n);
198
- }
199
- else
200
- {
201
- p->giveback();
202
- if (k=parsegraph(p,env,mono,rec+1,labels,newvars,rnode)) return k;
203
- n++;
204
- }
205
- }
206
- }
207
- else if (islabel(p->token))
208
- {
209
- int* t=searchtype(env,p->token);
210
- if (!t)
211
- {
212
- PRINTF(m)(LOG_RUNTIME,"Compiler : unknown type %s\n",p->token);
213
- return MTLERR_SN;
214
- }
215
- int* q=VALTOPNT(TABGET(t,REF_TYPE));
216
- int vargs=TABGET(q,TYPEHEADER_LENGTH);
217
- if (vargs==NIL) return STACKPUSH(m,TABGET(t,REF_TYPE));
218
- else
219
- {
220
- if (k=createnodetypecore(TABGET(q,TYPEHEADER_LENGTH+1))) return k;
221
- int n=TABLEN(VALTOPNT(vargs));
222
- int* t0=MALLOCCLEAR(m,TABLEN(VALTOPNT(vargs)));
223
- if (!t0) return MTLERR_OM;
224
- if (k=STACKPUSH(m,PNTTOVAL(t0))) return k;
225
- if (!p->next(0))
226
- {
227
- PRINTF(m)(LOG_RUNTIME,"Compiler : '(' expected (found EOF)\n");
228
- return MTLERR_SN;
229
- }
230
- if (strcmp(p->token,"("))
231
- {
232
- PRINTF(m)(LOG_RUNTIME,"Compiler : '(' expected (found '%s')\n",parser->token);
233
- return MTLERR_SN;
234
- }
235
- int i;for(i=0;i<n;i++)
236
- {
237
- if (k=parsegraph(p,env,mono,rec+1,labels,newvars,rnode)) return k;
238
- TABSET(m,t0,i,STACKPULL(m));
239
- }
240
- if (!p->next(0))
241
- {
242
- PRINTF(m)(LOG_RUNTIME,"Compiler : ')' expected (found EOF)\n");
243
- return MTLERR_SN;
244
- }
245
- if (strcmp(p->token,")"))
246
- {
247
- PRINTF(m)(LOG_RUNTIME,"Compiler : ')' expected (found '%s')\n",parser->token);
248
- return MTLERR_SN;
249
- }
250
- TABSET(m,VALTOPNT(STACKGET(m,1)),TYPEHEADER_LENGTH,STACKGET(m,0));
251
- STACKDROP(m);
252
- }
253
- }
254
- else
255
- {
256
- PRINTF(m)(LOG_RUNTIME,"Compiler : unknown token %s\n",p->token);
257
- return MTLERR_SN;
258
- }
259
- return 0;
260
- }
261
-
262
- // gestion des noeuds rec : on les lie avec le champ ACTUAL
263
- int Compiler::parse_rnode(int *p)
264
- {
265
- int k,i;
266
-
267
- int c=VALTOINT(TABGET(p,TYPEHEADER_CODE));
268
- if ((c==TYPENAME_WEAK)||(c==TYPENAME_UNDEF)) return 0; // type faible ou non d�fini, pas de r�cursion
269
- if ((c==TYPENAME_CORE)&&(TABGET(p,TYPEHEADER_LENGTH)==NIL)) return 0; // type de base, non param�trique
270
-
271
- if (c==TYPENAME_REC)
272
- {
273
- TABSET(m,p,TYPEHEADER_ACTUAL,STACKGET(m,VALTOINT(TABGET(p,TYPEHEADER_LENGTH))));
274
- return 0;
275
- }
276
- if (k=STACKPUSH(m,PNTTOVAL(p))) return k;
277
-
278
- if (c==TYPENAME_CORE)
279
- {
280
- int* tup=VALTOPNT(TABGET(p,TYPEHEADER_LENGTH));
281
- for(i=0;i<TABLEN(tup);i++) if (k=parse_rnode(VALTOPNT(TABGET(tup,i)))) return k;
282
- }
283
- else if (c==TYPENAME_FUN)
284
- {
285
- if (k=parse_rnode(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
286
- if (k=parse_rnode(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH+1)))) return k;
287
- }
288
- else if (c==TYPENAME_LIST)
289
- {
290
- if (k=parse_rnode(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
291
- }
292
- else if (c==TYPENAME_TAB)
293
- {
294
- if (k=parse_rnode(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
295
- }
296
- else if (c==TYPENAME_TUPLE)
297
- {
298
- for(i=TYPEHEADER_LENGTH;i<TABLEN(p);i++) if (k=parse_rnode(VALTOPNT(TABGET(p,i)))) return k;
299
- }
300
- STACKDROP(m);
301
- return 0;
302
- }
303
-
304
- // cr�ation d'un graphe de type directement � partir d'un parser (utile pour les types �crits dans le code source)
305
- int Compiler::creategraph(Parser* p,int env,int mono)
306
- {
307
- int k,labels;
308
- int rnode=0;
309
- if (k=STACKPUSH(m,NIL)) return k;
310
- labels=STACKREF(m);
311
- //k=parsegraph(p,env,mono,0,labels,0,&rnode);
312
- if (k=parsegraph(p,env,mono,0,labels,0,&rnode)) return k;
313
- STACKSET(m,1,STACKGET(m,0));
314
- STACKDROP(m);
315
- if (rnode) return parse_rnode(VALTOPNT(STACKGET(m,0)));
316
- return 0;
317
- }
318
-
319
- // cr�ation d'un graphe de type directement � partir d'un parser (utile pour les types �crits dans le code source)
320
- // avec une liste de labels pr�-existante
321
- int Compiler::creategraph(Parser* p,int env,int mono,int labels)
322
- {
323
- int k;
324
- int rnode=0;
325
- if (k=parsegraph(p,env,mono,0,labels,0,&rnode)) return k;
326
- if (rnode) return parse_rnode(VALTOPNT(STACKGET(m,0)));
327
- return 0;
328
- }
329
-
330
-
331
- // cr�ation d'un graphe de type � partir d'une cha�ne
332
- int Compiler::creategraph(const char* src,int env,int mono)
333
- {
334
- // PRINTF(m)(LOG_DEVCORE,"Compiler : creategraph : %s\n",src);
335
-
336
- Parser* p=new Parser(m->term,src);
337
- int k=creategraph(p,env,mono);
338
- delete p;
339
- return k;
340
- }
341
-
342
-
343
-
344
-
345
- int Compiler::recechograph(Prodbuffer *output,int* p,int rec,int labels)
346
- {
347
- int i,k;
348
- p=actualtype(p);
349
- if (k=STACKPUSH(m,PNTTOVAL(p))) return k;
350
-
351
- for(i=0;i<rec;i++) if (STACKGET(m,0)==STACKGET(m,i+1))
352
- {
353
- STACKDROP(m);
354
- output->printf("r%d",i);
355
- return 0;
356
- }
357
- int v=VALTOINT(TABGET(p,TYPEHEADER_CODE));
358
- if (v==TYPENAME_CORE)
359
- {
360
- output->printf("%s",STRSTART(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH+1))));
361
- int vargs=TABGET(p,TYPEHEADER_LENGTH);
362
- if (vargs!=NIL)
363
- {
364
- output->printf("(");
365
- int* tup=VALTOPNT(vargs);
366
- for(i=0;i<TABLEN(tup);i++)
367
- {
368
- if (i) output->printf(" ");
369
- recechograph(output,VALTOPNT(TABGET(tup,i)),rec+1,labels);
370
- }
371
- output->printf(")");
372
- }
373
- }
374
- else if (v==TYPENAME_FUN)
375
- {
376
- output->printf("fun ");
377
- recechograph(output,VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)),rec+1,labels);
378
- output->printf(" ");
379
- recechograph(output,VALTOPNT(TABGET(p,TYPEHEADER_LENGTH+1)),rec+1,labels);
380
- }
381
- else if (v==TYPENAME_LIST)
382
- {
383
- output->printf("list ");
384
- recechograph(output,VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)),rec+1,labels);
385
- }
386
- else if (v==TYPENAME_TAB)
387
- {
388
- output->printf("tab ");
389
- recechograph(output,VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)),rec+1,labels);
390
- }
391
- else if (v==TYPENAME_TUPLE)
392
- {
393
- output->printf("[");
394
- for(i=TYPEHEADER_LENGTH;i<TABLEN(p);i++)
395
- {
396
- if (i>TYPEHEADER_LENGTH) output->printf(" ");
397
- recechograph(output,VALTOPNT(TABGET(p,i)),rec+1,labels);
398
- }
399
- output->printf("]");
400
- }
401
- else if (v==TYPENAME_UNDEF)
402
- {
403
- char* name;
404
- if (!searchlabel_byval(labels,PNTTOVAL(p),&name))
405
- output->printf("%s",name);
406
- else
407
- {
408
- char buf[16];
409
- sprintf(buf,"u%d",nblabels(labels));
410
- addlabel(labels,buf,PNTTOVAL(p),NIL);
411
- output->printf("%s",buf);
412
- }
413
- }
414
- else if (v==TYPENAME_WEAK)
415
- {
416
- char* name;
417
- if (!searchlabel_byval(labels,PNTTOVAL(p),&name))
418
- output->printf("%s",name);
419
- else
420
- {
421
- char buf[16];
422
- sprintf(buf,"w%d",nblabels(labels));
423
- addlabel(labels,buf,PNTTOVAL(p),NIL);
424
- output->printf("%s",buf);
425
- }
426
- }
427
- STACKDROP(m);
428
- return 0;
429
- }
430
-
431
-
432
- int Compiler::echograph(Prodbuffer *output,int* p)
433
- {
434
- int k,labels;
435
- if (k=STACKPUSH(m,NIL)) return k;
436
- labels=STACKREF(m);
437
- recechograph(output,p,0,labels);
438
- STACKDROP(m);
439
- return 0;
440
- }
441
-
442
-
443
- // copie de graphe
444
- int Compiler::reccopytype(int *p)
445
- {
446
- int k,i;
447
-
448
- p=actualtype(p);
449
- int vq=TABGET(p,TYPEHEADER_COPY);
450
- if (vq!=NIL) return STACKPUSH(m,vq); // �l�ment d�j� copi�
451
- int c=VALTOINT(TABGET(p,TYPEHEADER_CODE));
452
- if ((c==TYPENAME_CORE)&&(TABGET(p,TYPEHEADER_LENGTH)==NIL))
453
- return STACKPUSH(m,PNTTOVAL(p)); // type basique, ne pas copier
454
-
455
- if (c==TYPENAME_TUPLE)
456
- {
457
- for(i=TYPEHEADER_LENGTH;i<TABLEN(p);i++) if (k=STACKPUSH(m,NIL)) return k;
458
- if (k=createnodetuple(TABLEN(p)-TYPEHEADER_LENGTH)) return k;
459
- TABSET(m,p,TYPEHEADER_COPY,STACKGET(m,0)); // positionne le champ 'copy' de l'original
460
- int* q=VALTOPNT(STACKGET(m,0));
461
- for(i=TYPEHEADER_LENGTH;i<TABLEN(p);i++)
462
- {
463
- if (k=reccopytype(VALTOPNT(TABGET(p,i)))) return k;
464
- TABSET(m,q,i,STACKPULL(m));
465
- }
466
- return 0;
467
- }
468
-
469
- if (c==TYPENAME_WEAK) return STACKPUSH(m,PNTTOVAL(p)); // type faible, ne pas copier
470
-
471
- if (c==TYPENAME_CORE) k=createnodetypecore(TABGET(p,TYPEHEADER_LENGTH+1));
472
- else k=createnodetype(c);
473
- if (k) return k; // copie le noeud
474
- TABSET(m,p,TYPEHEADER_COPY,STACKGET(m,0)); // positionne le champ 'copy' de l'original
475
-
476
- int* q=VALTOPNT(STACKGET(m,0));
477
- if (c==TYPENAME_FUN)
478
- {
479
- if (k=reccopytype(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
480
- TABSET(m,q,TYPEHEADER_LENGTH,STACKPULL(m));
481
- if (k=reccopytype(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH+1)))) return k;
482
- TABSET(m,q,TYPEHEADER_LENGTH+1,STACKPULL(m));
483
- }
484
- else if (c==TYPENAME_LIST)
485
- {
486
- if (k=reccopytype(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
487
- TABSET(m,q,TYPEHEADER_LENGTH,STACKPULL(m));
488
- }
489
- else if (c==TYPENAME_TAB)
490
- {
491
- if (k=reccopytype(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
492
- TABSET(m,q,TYPEHEADER_LENGTH,STACKPULL(m));
493
- }
494
- else if (c==TYPENAME_CORE)
495
- {
496
- int vargs=TABGET(p,TYPEHEADER_LENGTH);
497
- if (vargs==NIL) return 0;
498
- else
499
- {
500
- int* tup=VALTOPNT(vargs);
501
- for(i=0;i<TABLEN(tup);i++) if (k=reccopytype(VALTOPNT(TABGET(tup,i)))) return k;
502
- if (k=DEFTAB(m,TABLEN(tup))) return k;
503
- TABSET(m,q,TYPEHEADER_LENGTH,STACKPULL(m));
504
- }
505
- }
506
- else if (c==TYPENAME_UNDEF)
507
- {
508
- }
509
- return 0;
510
- }
511
-
512
- // remise � nil du champ 'copy' d'un graphe
513
- int Compiler::recresetcopy(int *p)
514
- {
515
- int k,i;
516
-
517
- p=actualtype(p);
518
- int vq=TABGET(p,TYPEHEADER_COPY);
519
- if (vq==NIL) return 0; // �l�ment d�j� reset�
520
-
521
- TABSET(m,p,TYPEHEADER_COPY,NIL); // reset le champ 'copy'
522
-
523
- int c=VALTOINT(TABGET(p,TYPEHEADER_CODE));
524
- if (c==TYPENAME_WEAK) return 0; // type faible, pas de r�cursion
525
- else if (c==TYPENAME_CORE)
526
- {
527
- int vargs=TABGET(p,TYPEHEADER_LENGTH);
528
- if (vargs==NIL) return 0;
529
- else
530
- {
531
- int* tup=VALTOPNT(vargs);
532
- for(i=0;i<TABLEN(tup);i++) if (k=recresetcopy(VALTOPNT(TABGET(tup,i)))) return k;
533
- }
534
- }
535
- else if (c==TYPENAME_FUN)
536
- {
537
- if (k=recresetcopy(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
538
- if (k=recresetcopy(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH+1)))) return k;
539
- }
540
- else if (c==TYPENAME_LIST)
541
- {
542
- if (k=recresetcopy(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
543
- }
544
- else if (c==TYPENAME_TAB)
545
- {
546
- if (k=recresetcopy(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
547
- }
548
- else if (c==TYPENAME_TUPLE)
549
- {
550
- for(i=TYPEHEADER_LENGTH;i<TABLEN(p);i++) if (k=recresetcopy(VALTOPNT(TABGET(p,i)))) return k;
551
- }
552
- else if (c==TYPENAME_UNDEF)
553
- {
554
- }
555
- return 0;
556
- }
557
-
558
- int Compiler::copytype(int *p)
559
- {
560
- int k;
561
- if (k=reccopytype(p)) return k;
562
- if (k=recresetcopy(p)) return k;
563
- return 0;
564
- }
565
-
566
-
567
- // passage des UNDEF en WEAK
568
- int Compiler::recgoweak(int *p)
569
- {
570
- int k,i;
571
-
572
- p=actualtype(p);
573
- int vq=TABGET(p,TYPEHEADER_COPY);
574
- if (vq!=NIL) return 0; // �l�ment d�j� trait�
575
- int c=VALTOINT(TABGET(p,TYPEHEADER_CODE));
576
- if (c==TYPENAME_WEAK) return 0; // type faible, ne pas traiter
577
-
578
- TABSET(m,p,TYPEHEADER_COPY,INTTOVAL(1)); // positionne le champ 'copy' de l'original
579
- if (c==TYPENAME_CORE)
580
- {
581
- int vargs=TABGET(p,TYPEHEADER_LENGTH);
582
- if (vargs==NIL) return 0;
583
- else
584
- {
585
- int* tup=VALTOPNT(vargs);
586
- for(i=0;i<TABLEN(tup);i++) if (k=recgoweak(VALTOPNT(TABGET(tup,i)))) return k;
587
- }
588
- }
589
- else if (c==TYPENAME_FUN)
590
- {
591
- if (k=recgoweak(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
592
- if (k=recgoweak(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH+1)))) return k;
593
- }
594
- else if (c==TYPENAME_LIST)
595
- {
596
- if (k=recgoweak(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
597
- }
598
- else if (c==TYPENAME_TAB)
599
- {
600
- if (k=recgoweak(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH)))) return k;
601
- }
602
- else if (c==TYPENAME_TUPLE)
603
- {
604
- for(i=TYPEHEADER_LENGTH;i<TABLEN(p);i++) if (k=recgoweak(VALTOPNT(TABGET(p,i)))) return k;
605
- }
606
- else if (c==TYPENAME_UNDEF)
607
- {
608
- TABSET(m,p,TYPEHEADER_CODE,INTTOVAL(TYPENAME_WEAK));
609
- }
610
- return 0;
611
- }
612
-
613
-
614
- // unification de graphe
615
- int Compiler::restoreactual(int* t,int* s,int vt,int vs,int k)
616
- {
617
- TABSET(m,t,TYPEHEADER_ACTUAL,vt);
618
- TABSET(m,s,TYPEHEADER_ACTUAL,vs);
619
- return k;
620
- }
621
-
622
- int Compiler::recunif(int* s,int* t)
623
- {
624
- s=actualtype(s);
625
- t=actualtype(t);
626
- if (s==t) return 0; // ceci g�re le cas des types basiques
627
-
628
- int ns=VALTOINT(TABGET(s,TYPEHEADER_CODE));
629
- int nt=VALTOINT(TABGET(t,TYPEHEADER_CODE));
630
- int ok=1;
631
- if ((ns!=TYPENAME_UNDEF)&&(ns!=TYPENAME_WEAK)
632
- &&(nt!=TYPENAME_UNDEF)&&(nt!=TYPENAME_WEAK) // si les deux noeuds bien d�finis ...
633
- &&(ns!=nt) ) ok=0;
634
- else if ((ns==nt)&&(ns==TYPENAME_CORE)&&(TABGET(s,TYPEHEADER_LENGTH+1)!=TABGET(t,TYPEHEADER_LENGTH+1))) ok=0;
635
- if (!ok)
636
- {
637
- PRINTF(m)(LOG_COMPILER,"Compiler : ");
638
- echonode(ns,s);
639
- PRINTF(m)(LOG_COMPILER," cannot be unified with ");
640
- echonode(nt,t);
641
- PRINTF(m)(LOG_COMPILER,"\n");
642
- return MTLERR_TYPE; // ... il doivent �tre du m�me type
643
- }
644
-
645
- int vt=TABGET(t,TYPEHEADER_ACTUAL); // on sauvegarde avant unification
646
- int vs=TABGET(s,TYPEHEADER_ACTUAL);
647
-
648
- if ((ns==TYPENAME_UNDEF) /* union des noeuds */
649
- || ((ns==TYPENAME_WEAK)&&(nt!=TYPENAME_UNDEF)) )
650
- {
651
- TABSET(m,s,TYPEHEADER_ACTUAL,PNTTOVAL(t));
652
- if (ns==TYPENAME_WEAK)
653
- {
654
- recgoweak(t);
655
- recresetcopy(t);
656
- }
657
- }
658
- else
659
- {
660
- TABSET(m,t,TYPEHEADER_ACTUAL,PNTTOVAL(s));
661
- if (nt==TYPENAME_WEAK)
662
- {
663
- recgoweak(s);
664
- recresetcopy(s);
665
- }
666
- }
667
-
668
- if (ns==nt)
669
- {
670
- int k;
671
- if ((ns==TYPENAME_TAB)||(ns==TYPENAME_LIST)||(ns==TYPENAME_FUN))
672
- {
673
- if (k=recunif(VALTOPNT(TABGET(s,TYPEHEADER_LENGTH)),VALTOPNT(TABGET(t,TYPEHEADER_LENGTH))))
674
- return restoreactual(t,s,vt,vs,k);
675
- if ((ns==TYPENAME_FUN)
676
- &&(k=recunif(VALTOPNT(TABGET(s,TYPEHEADER_LENGTH+1)),VALTOPNT(TABGET(t,TYPEHEADER_LENGTH+1)))) )
677
- return restoreactual(t,s,vt,vs,k);
678
- }
679
- else if (ns==TYPENAME_TUPLE)
680
- {
681
- int len=TABLEN(s);
682
- if (len!=TABLEN(t)) return restoreactual(t,s,vt,vs,MTLERR_TYPE);
683
- int i; for(i=TYPEHEADER_LENGTH;i<len;i++)
684
- if (k=recunif(VALTOPNT(TABGET(s,i)),VALTOPNT(TABGET(t,i))))
685
- return restoreactual(t,s,vt,vs,k);
686
- }
687
- else if (ns==TYPENAME_CORE)
688
- {
689
- int vtups=TABGET(s,TYPEHEADER_LENGTH);
690
- int vtupt=TABGET(t,TYPEHEADER_LENGTH);
691
- if ((vtups==NIL)&&(vtupt==NIL)) return 0;
692
- if ((vtups==NIL)||(vtupt==NIL)) return restoreactual(t,s,vt,vs,MTLERR_TYPE);
693
- int* tups=VALTOPNT(vtups);
694
- int* tupt=VALTOPNT(vtupt);
695
- int len=TABLEN(tups);
696
- if (len!=TABLEN(tupt)) return restoreactual(t,s,vt,vs,MTLERR_TYPE);
697
- int i; for(i=0;i<len;i++)
698
- if (k=recunif(VALTOPNT(TABGET(tups,i)),VALTOPNT(TABGET(tupt,i))))
699
- return restoreactual(t,s,vt,vs,k);
700
- }
701
- }
702
- return 0;
703
- }
704
-
705
- int Compiler::unif(int* x,int* y)
706
- {
707
- int l;
708
-
709
- if (!(l=recunif(x,y))) return 0;
710
-
711
- Prodbuffer* output=new Prodbuffer();
712
-
713
- output->printf("Compiler :\n ");
714
- echograph(output,x);
715
- output->printf("\ndoes not match with\n ");
716
- echograph(output,y);
717
- output->printf("\n");
718
-
719
- PRINTF(m)(LOG_COMPILER,"%s",output->getstart());
720
- delete output;
721
-
722
- return l;
723
- }
724
-
725
- // [fun [arg]]
726
- int Compiler::unif_argfun()
727
- {
728
- int k;
729
- int* fun=VALTOPNT(STACKPULL(m));
730
- int* arg=VALTOPNT(STACKGET(m,0));
731
-
732
- if (k=unif(VALTOPNT(TABGET(fun,TYPEHEADER_LENGTH)),arg)) return k;
733
- STACKSET(m,0,TABGET(fun,TYPEHEADER_LENGTH+1));
734
- return 0;
735
- }
736
-
737
- int* Compiler::argsfromfun(int *f)
738
- {
739
- return VALTOPNT(TABGET(f,TYPEHEADER_LENGTH));
740
- }
741
-
742
- void Compiler::echonode(int code,int* p)
743
- {
744
- if (code==TYPENAME_CORE) PRINTF(m)(LOG_COMPILER,"%s",STRSTART(VALTOPNT(TABGET(p,TYPEHEADER_LENGTH+1))));
745
- else if (code==TYPENAME_UNDEF) PRINTF(m)(LOG_COMPILER,"u*");
746
- else if (code==TYPENAME_WEAK) PRINTF(m)(LOG_COMPILER,"w*");
747
- else if (code==TYPENAME_TAB) PRINTF(m)(LOG_COMPILER,"tab");
748
- else if (code==TYPENAME_LIST) PRINTF(m)(LOG_COMPILER,"list");
749
- else if (code==TYPENAME_TUPLE) PRINTF(m)(LOG_COMPILER,"tuple");
750
- else if (code==TYPENAME_FUN) PRINTF(m)(LOG_COMPILER,"fun");
751
- }
752
-
753
- // unification d'un plus grand vers un plus petit
754
- // attention, OPsearch suppose que seul MTLERR_TYPE peut arriver
755
- int Compiler::recunifbigger(int* s,int* t)
756
- {
757
- int* s0=s; // on retient le s initial
758
- s=actualtype(s);
759
- t=actualtype(t);
760
- if (s==t) return 0; // ceci g�re le cas des types basiques
761
-
762
- int ns=VALTOINT(TABGET(s,TYPEHEADER_CODE));
763
- int nt=VALTOINT(TABGET(t,TYPEHEADER_CODE));
764
- int ok=1;
765
- if ((ns!=TYPENAME_UNDEF)&&(ns!=TYPENAME_WEAK)
766
- &&(nt!=TYPENAME_UNDEF)&&(nt!=TYPENAME_WEAK) // si les deux noeuds bien d�finis ...
767
- &&(ns!=nt) ) ok=0;
768
- else if ((ns==nt)&&(ns==TYPENAME_CORE)&&(TABGET(s,TYPEHEADER_LENGTH+1)!=TABGET(t,TYPEHEADER_LENGTH+1))) ok=0;
769
- if (!ok)
770
- {
771
- PRINTF(m)(LOG_COMPILER,"Compiler : ");
772
- echonode(ns,s);
773
- PRINTF(m)(LOG_COMPILER," cannot be unified with ");
774
- echonode(nt,t);
775
- PRINTF(m)(LOG_COMPILER,"\n");
776
- return MTLERR_TYPE; // ... il doivent �tre du m�me type
777
- }
778
-
779
- int vt=TABGET(t,TYPEHEADER_ACTUAL); // on sauvegarde avant unification
780
- int vs=TABGET(s,TYPEHEADER_ACTUAL);
781
-
782
- if ((nt==TYPENAME_UNDEF)&&(ns!=TYPENAME_UNDEF))
783
- {
784
- PRINTF(m)(LOG_COMPILER,"Compiler : ");
785
- echonode(ns,s);
786
- PRINTF(m)(LOG_COMPILER," is smaller than ");
787
- echonode(nt,t);
788
- PRINTF(m)(LOG_COMPILER,"\n");
789
- return MTLERR_TYPE;
790
- }
791
- if ((ns==TYPENAME_UNDEF)&&(s0!=s))
792
- {
793
- PRINTF(m)(LOG_COMPILER,"Compiler : u* already unified\n");
794
- return MTLERR_TYPE;
795
- }
796
-
797
- if ((ns==TYPENAME_UNDEF) /* union des noeuds */
798
- || ((ns==TYPENAME_WEAK)&&(nt!=TYPENAME_UNDEF)) )
799
- {
800
- TABSET(m,s,TYPEHEADER_ACTUAL,PNTTOVAL(t));
801
- if (ns==TYPENAME_WEAK)
802
- {
803
- recgoweak(t);
804
- recresetcopy(t);
805
- }
806
- }
807
- else
808
- {
809
- TABSET(m,t,TYPEHEADER_ACTUAL,PNTTOVAL(s));
810
- if (nt==TYPENAME_WEAK)
811
- {
812
- recgoweak(s);
813
- recresetcopy(s);
814
- }
815
- }
816
-
817
- if (ns==nt)
818
- {
819
- int k;
820
- if ((ns==TYPENAME_TAB)||(ns==TYPENAME_LIST)||(ns==TYPENAME_FUN))
821
- {
822
- if (k=recunifbigger(VALTOPNT(TABGET(s,TYPEHEADER_LENGTH)),VALTOPNT(TABGET(t,TYPEHEADER_LENGTH))))
823
- return restoreactual(t,s,vt,vs,k);
824
- if ((ns==TYPENAME_FUN)
825
- &&(k=recunifbigger(VALTOPNT(TABGET(s,TYPEHEADER_LENGTH+1)),VALTOPNT(TABGET(t,TYPEHEADER_LENGTH+1)))) )
826
- return restoreactual(t,s,vt,vs,k);
827
- }
828
- else if (ns==TYPENAME_TUPLE)
829
- {
830
- int len=TABLEN(s);
831
- if (len!=TABLEN(t)) return restoreactual(t,s,vt,vs,MTLERR_TYPE);
832
- int i; for(i=TYPEHEADER_LENGTH;i<len;i++)
833
- if (k=recunifbigger(VALTOPNT(TABGET(s,i)),VALTOPNT(TABGET(t,i))))
834
- return restoreactual(t,s,vt,vs,k);
835
- }
836
- else if (ns==TYPENAME_CORE)
837
- {
838
- int vtups=TABGET(s,TYPEHEADER_LENGTH);
839
- int vtupt=TABGET(t,TYPEHEADER_LENGTH);
840
- if ((vtups==NIL)&&(vtupt==NIL)) return 0;
841
- if ((vtups==NIL)||(vtupt==NIL)) restoreactual(t,s,vt,vs,MTLERR_TYPE);
842
- int* tups=VALTOPNT(vtups);
843
- int* tupt=VALTOPNT(vtupt);
844
- int len=TABLEN(tups);
845
- if (len!=TABLEN(tupt)) return restoreactual(t,s,vt,vs,MTLERR_TYPE);
846
- int i; for(i=0;i<len;i++)
847
- if (k=recunifbigger(VALTOPNT(TABGET(tups,i)),VALTOPNT(TABGET(tupt,i))))
848
- return restoreactual(t,s,vt,vs,k);
849
- }
850
- }
851
- return 0;
852
- }
853
-
854
- int Compiler::unifbigger(int* x,int* y)
855
- {
856
- int l;
857
-
858
- if (!(l=recunifbigger(x,y))) return 0;
859
-
860
- Prodbuffer* output=new Prodbuffer();
861
-
862
- output->printf("Compiler :\n ");
863
- echograph(output,x);
864
- output->printf("\ndoes not match with or is smaller than\n ");
865
- echograph(output,y);
866
- output->printf("\n");
867
-
868
- PRINTF(m)(LOG_COMPILER,"%s",output->getstart());
869
- delete output;
870
-
871
- return l;
872
- }