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,241 +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
- #include <stdio.h>
10
- #include <string.h>
11
-
12
- #include "param.h"
13
- #include "terminal.h"
14
- #include "memory.h"
15
- #include "util.h"
16
- #include "interpreter.h"
17
-
18
- #define GCincPeriod 20
19
-
20
-
21
- // Gestion de la pile
22
- Stack::Stack()
23
- {
24
- base=NULL;
25
- }
26
- Stack::~Stack()
27
- {
28
- if (base) delete base;
29
- }
30
-
31
- void Stack::dump(FILE *f)
32
- {
33
- const char* buf="stck";
34
- fwrite((void*)buf,1,4,f);
35
- fwrite((void*)&size,1,4,f);
36
- fwrite((void*)&pp,1,4,f);
37
- fwrite((void*)&base,1,4,f);
38
- fwrite((void*)base,1,4*size,f);
39
- }
40
-
41
- void Stack::initialize(int s)
42
- {
43
- size=s;
44
- base=new int[size];
45
- pp=base;
46
- }
47
-
48
- int Stack::bigger(Memory* m)
49
- {
50
- int currentpp=pp-base;
51
-
52
- size*=2;
53
-
54
- int* newbase=new int[size];
55
- if (!newbase)
56
- {
57
- PRINTF(m)(LOG_RUNTIME,"Stack : out of Stack Memory\n");
58
- AbortMetal(m,1);
59
- return MTLERR_OM; // impossible d'augmenter la taille de la pile
60
- }
61
- int i; for(i=0;i<=currentpp;i++) newbase[i]=base[i];
62
- delete base;
63
- base=newbase;
64
- pp=&base[currentpp];
65
- return 0;
66
- }
67
-
68
-
69
-
70
-
71
- // ajout d'une racine
72
- int Memory::addroot(int *p)
73
- {
74
- int k;
75
-
76
- if (k=push(PNTTOVAL(p))) return k;
77
- int* r=malloc(LIST_LENGTH,TYPE_TAB);
78
- TABSET(this,r,LIST_VAL,PNTTOVAL(p));
79
- TABSET(this,r,LIST_NEXT,root);
80
- root=PNTTOVAL(r);
81
- STACKDROP(this);
82
- return 0;
83
- }
84
-
85
- // suppression d'une racine
86
- void Memory::removeroot(int *p)
87
- {
88
- int* last=NULL; // pointeur vers le précédent maillon de la liste
89
- int vq=root;
90
- while(vq!=NIL)
91
- {
92
- int* q=VALTOPNT(vq);
93
- if (TABGET(q,LIST_VAL)==PNTTOVAL(p))
94
- {
95
- if (last) TABSET(this,last,LIST_NEXT,TABGET(q,LIST_NEXT));
96
- else root=TABGET(q,LIST_NEXT);
97
- return;
98
- }
99
- last=q;
100
- vq=TABGET(q,LIST_NEXT);
101
- }
102
- }
103
-
104
- Memory::Memory(int size,Terminal *t,FileSystem *fs)
105
- {
106
- term=t;
107
- filesystem=fs;
108
- size0=size; // on retient la taille initiale, elle sert d'ordre de grandeur
109
- gcincperiod=GCincPeriod;
110
- abort=0;
111
-
112
- util=new Util(this);
113
- winutil=NULL;
114
- // listing();
115
- }
116
-
117
- Memory::~Memory()
118
- {
119
- // if (winutil) delete winutil;
120
- delete util;
121
- }
122
-
123
- void Memory::stop()
124
- {
125
- abort=1;
126
- util->stop();
127
- root=NIL;
128
- stack.pp=0;
129
- }
130
-
131
- int Memory::start()
132
- {
133
- root=NIL;
134
-
135
- stack.initialize(STACK_FIRST_SIZE);
136
-
137
- PRINTF(this)(LOG_RUNTIME,"Metal Virtual Machine\n");
138
- PRINTF(this)(LOG_RUNTIME,"V0.2 - Sylvain Huet - 2005\n");
139
- PRINTF(this)(LOG_RUNTIME,"--------------------------\n");
140
- return util->start();
141
- }
142
-
143
- void Memory::dump()
144
- {
145
- }
146
-
147
-
148
- int* Memory::malloc(int size,int type)
149
- {
150
- int *p=NULL;
151
-
152
- int blocsize=size+HEADER_LENGTH;
153
- p=new int[blocsize];
154
- if (!p) return p;
155
-
156
- HEADERSETSIZETYPE(p,blocsize,type);
157
-
158
- return p;
159
- }
160
-
161
-
162
-
163
- int* Memory::mallocClear(int size)
164
- {
165
- int* p=malloc(size,TYPE_TAB);
166
- if (!p) return p;
167
- int i;
168
- for(i=0;i<size;i++) TABSET(this,p,i,NIL);
169
- return p;
170
- }
171
-
172
- // allocation de type TYPE_EXT (la fonction fun(pnt) sera appelée lors de l'oubli du bloc)
173
- int* Memory::mallocExternal(void* pnt,FORGET fun)
174
- {
175
- int* p=malloc(2,TYPE_EXT);
176
- if (!p) return p;
177
- TABSET(this,p,0,(int)pnt);
178
- TABSET(this,p,1,(int)fun);
179
- return p;
180
- }
181
-
182
- // allocation de type TYPE_EXT (la fonction fun(pnt) sera appelée lors de l'oubli du bloc)
183
- int Memory::pushExternal(void* pnt,FORGET fun)
184
- {
185
- int* p=mallocExternal(pnt,fun);
186
- if (!p) return MTLERR_OM;
187
- return push(PNTTOVAL(p));
188
- }
189
-
190
- int* Memory::storenosrc(int size)
191
- {
192
- // calcul de la taille d'un bloc pouvant contenir une certain nombre de caractères
193
- // il faut 1 mot pour la taille et un octet nul final
194
- int l=2+(size>>2);
195
-
196
- int* p=malloc(l,TYPE_BINARY);
197
- if (!p) return p;
198
- STRSETLEN(p,size);
199
- STRSTART(p)[size]=0;
200
- return p;
201
- }
202
-
203
- int* Memory::storebinary(const char *src,int size)
204
- {
205
- // calcul de la taille d'un bloc pouvant contenir une certain nombre de caractères
206
- // il faut 1 mot pour la taille et un octet nul final
207
- int l=2+(size>>2);
208
-
209
- int* p=malloc(l,TYPE_BINARY);
210
- if (!p) return p;
211
- STRSETLEN(p,size);
212
- memcpy(STRSTART(p),src,size);
213
- STRSTART(p)[size]=0;
214
- return p;
215
- }
216
-
217
- int* Memory::storestring(const char *src)
218
- {
219
- return storebinary(src,strlen(src));
220
- }
221
-
222
- int Memory::deftab(int size)
223
- {
224
- int* p=malloc(size,TYPE_TAB);
225
- if (!p) return MTLERR_OM;
226
- int i; for(i=size-1;i>=0;i--) TABSET(this,p,i,STACKPULL(this));
227
- return push(PNTTOVAL(p));
228
- }
229
-
230
- const char* Memory::errorname(int err)
231
- {
232
- if (err==MTLERR_OM) return "Out of memory";
233
- else if (err==MTLERR_OP) return "Unknown Operand";
234
- else if (err==MTLERR_DIV) return "Division by zero";
235
- else if (err==MTLERR_RET) return "Bad implementation on 'return'";
236
- else if (err==MTLERR_NOFUN) return "No function defined";
237
- else if (err==MTLERR_SN) return "Syntax error";
238
- else if (err==MTLERR_TYPE) return "Typechecking error";
239
- else if (err==MTLERR_ABORT) return "Application aborted";
240
- else return "Unknown error";
241
- }
@@ -1,427 +0,0 @@
1
- //-------------------
2
- // Moteur 3d
3
- // version WIN32 et POCKETPC
4
- // Sylvain Huet
5
- // Premiere version : 03/09/2002
6
- // Derniere mise a jour : 05/10/2002
7
- //
8
-
9
-
10
-
11
- #include <stdio.h>
12
- #include <string.h>
13
-
14
- #include "param.h"
15
- #include "filesystem.h"
16
- #include "file.h"
17
- #include "parser.h"
18
- #include "terminal.h"
19
- #include "memory.h"
20
-
21
- // test de lettre
22
- int isletter(int c)
23
- {
24
- if ((c>='A')&&(c<='Z')) return 1;
25
- if ((c>='a')&&(c<='z')) return 1;
26
- if (c=='_') return 1;
27
- return 0;
28
- }
29
- // test de chiffre decimal
30
- int isnum(int c)
31
- {
32
- if ((c>='0')&&(c<='9')) return 1;
33
- return 0;
34
- }
35
- // test de lettre
36
- int ishex(int c)
37
- {
38
- if ((c>='0')&&(c<='9')) return 1;
39
- if ((c>='A')&&(c<='F')) return 1;
40
- if ((c>='a')&&(c<='f')) return 1;
41
- return 0;
42
- }
43
-
44
- // test de lettre ou de chiffre
45
- int isletnum(int c)
46
- {
47
- if ((c>='A')&&(c<='Z')) return 1;
48
- if ((c>='a')&&(c<='z')) return 1;
49
- if ((c>='0')&&(c<='9')) return 1;
50
- if (c=='_') return 1;
51
- return 0;
52
- }
53
-
54
- // test si un mot est un label (une lettre puis des lettres ou des chiffres)
55
- int islabel(char* src)
56
- {
57
- if (!isletter(*src++)) return 0;
58
- while(*src)
59
- {
60
- if (!isletnum(*src++)) return 0;
61
- }
62
- return 1;
63
- }
64
-
65
- // test si un mot est un nombre d�cimal (que des chiffres)
66
- int isdecimal(char* src)
67
- {
68
- while(*src)
69
- {
70
- if (!isnum(*src++)) return 0;
71
- }
72
- return 1;
73
- }
74
-
75
- // test si un mot est un nombre hexad�cimal (que des chiffres)
76
- int ishexadecimal(char* src)
77
- {
78
- while(*src)
79
- {
80
- if (!ishex(*src++)) return 0;
81
- }
82
- return 1;
83
- }
84
-
85
- // test si un mot est un nombre flottant (que des chiffres avec un point)
86
- int isfloat(char* src)
87
- {
88
- int debut=1;
89
- int point=0;
90
- while(*src)
91
- {
92
- if ((*src=='.')&&(!debut)&&(!point)) point=1;
93
- else if (!isnum(*src)) return 0;
94
- src++;
95
- debut=0;
96
- }
97
- return point;
98
- }
99
-
100
- // retourne le code ascii correspondant � un chiffre hexad�cimal
101
- int ctoh(int c)
102
- {
103
- c&=15;
104
- if (c<10) return '0'+c;
105
- return 'a'+c-10;
106
- }
107
-
108
- // retourne le chiffre correspondant � un code ascii hexad�cimal
109
- int htoc(int c)
110
- {
111
- if ((c>='0')&&(c<='9')) return c-'0';
112
- else if ((c>='A')&&(c<='F')) return c-'A'+10;
113
- else if ((c>='a')&&(c<='f')) return c-'a'+10;
114
- return 0;
115
- }
116
-
117
- // lecture d'une cha�ne d�cimale (s'arr�te au premier caract�re incorrect)
118
- int mtl_atoi(char* src)
119
- {
120
- int x,c,s;
121
- x=s=0;
122
- if ((*src)=='-') { s=1; src++; }
123
- while(c=*src++)
124
- {
125
- if ((c>='0')&&(c<='9')) x=(x*10)+c-'0';
126
- else return (s?(-x):x);
127
- }
128
- return (s?(-x):x);
129
- }
130
-
131
- // lecture d'une cha�ne hexad�cimale (s'arr�te au premier caract�re incorrect)
132
- int mtl_htoi(char* src)
133
- {
134
- int x,c;
135
- x=0;
136
- while(c=*src++)
137
- {
138
- if ((c>='0')&&(c<='9')) x=(x<<4)+c-'0';
139
- else if ((c>='A')&&(c<='F')) x=(x<<4)+c-'A'+10;
140
- else if ((c>='a')&&(c<='f')) x=(x<<4)+c-'a'+10;
141
- else return x;
142
- }
143
- return x;
144
- }
145
-
146
- // lecture d'une cha�ne flottante (s'arr�te au premier caract�re incorrect)
147
- mtl_float mtl_atof(char* src)
148
- {
149
- int c;
150
- mtl_float f=0;
151
- mtl_float div=1;
152
- int point=0;
153
- while(c=*src++)
154
- {
155
- if ((c=='.')&&(!point)) point=1;
156
- else if ((c>='0')&&(c<='9'))
157
- {
158
- f=(f*10)+c-'0';
159
- if (point) div*=10;
160
- }
161
- else return f/div;
162
- }
163
- return f/div;
164
- }
165
-
166
- Parser::Parser(Terminal* t,FileSystem* fs,const char *filename)
167
- {
168
- term=t;
169
-
170
- srcname=new char[strlen(filename)+1];
171
- strcpy(srcname,filename);
172
-
173
- File* file=new File(fs);
174
- int size;
175
-
176
- src=NULL;
177
- if (!file->openread(filename)) src=file->getcontent(&size);
178
- delete file;
179
- if (!src)
180
- {
181
- t->printf(LOG_WARNING,"Parser : cannot open file %s\n",filename);
182
- src=new char[1];
183
- src[0]=0;
184
- }
185
- index=0;
186
-
187
- indexsavedchar=-1;
188
-
189
- again=0;
190
-
191
- lign=offligne=0;
192
- lign0=offligne0=offchar0=0;
193
-
194
- token=NULL;
195
- }
196
-
197
- Parser::Parser(Terminal* t,const char *buf)
198
- {
199
- srcname=NULL;
200
- term=t;
201
- src=new char[strlen(buf)+1];
202
- strcpy(src,buf);
203
- index=0;
204
-
205
- indexsavedchar=-1;
206
-
207
- again=0;
208
-
209
- lign=offligne=0;
210
- lign0=offligne0=offchar0=0;
211
-
212
- token=NULL;
213
- }
214
-
215
-
216
- Parser::~Parser()
217
- {
218
- delete src;
219
- if (srcname) delete srcname;
220
- }
221
-
222
- void Parser::giveback()
223
- {
224
- again=1;
225
- }
226
-
227
- char* Parser::next(int filter)
228
- {
229
- if (again)
230
- {
231
- again=0;
232
- return token;
233
- }
234
-
235
- int i;
236
- while(1)
237
- {
238
- int k;
239
- do
240
- {
241
- k=gettoken(filter);
242
- } while (k==-2);
243
- if (k)
244
- {
245
- token=NULL;
246
- return NULL;
247
- }
248
- // term->printf(0,"token=%s\n",token);
249
- if (strcmp(token,"/*")) return token; // ok
250
- i=1; // gestion des commentaires
251
- while(i)
252
- {
253
- if (gettoken(filter)==-1)
254
- {
255
- term->printf(LOG_COMPILER,"unbalanced comment reaches EOF\n");
256
- token=NULL;
257
- return NULL;
258
- }
259
- if (!strcmp(token,"/*")) i++;
260
- if (!strcmp(token,"*/")) i--;
261
- }
262
- }
263
- }
264
-
265
- void Parser::savechar(int i)
266
- {
267
- indexsavedchar=i;
268
- savedchar=src[i];
269
- src[i]=0;
270
- }
271
-
272
- // demande de relire le dernier caract�re
273
- void Parser::againchar()
274
- {
275
- index--;
276
- if (src[index]==10) lign--;
277
- }
278
-
279
- // lit le prochain caract�re
280
- int Parser::nextchar()
281
- {
282
- int c;
283
-
284
- c=src[index];
285
- if (c)
286
- {
287
- index++;
288
- if (c==10)
289
- {
290
- offligne=index;
291
- lign++;
292
- }
293
- }
294
- return c;
295
- }
296
-
297
-
298
- void Parser::restorechar()
299
- {
300
- // on restaure le caract�re escamot� � la fin du token pr�c�dent
301
- if (indexsavedchar!=-1)
302
- {
303
- src[indexsavedchar]=savedchar;
304
- indexsavedchar=-1;
305
- }
306
- }
307
-
308
- int Parser::gettoken(int filter)
309
- {
310
- int c,d,f;
311
-
312
- restorechar();
313
-
314
- do
315
- { // recherche le d�but du token
316
- // on sauvegarde la position dans le source
317
- lign0=lign;
318
- offligne0=offligne;
319
- offchar0=index;
320
- c=nextchar();
321
- if (!c) return -1; // fin du fichier, pas de nouveau token
322
- } while(c<=32);
323
-
324
- token=&src[offchar0];
325
-
326
- f=0;
327
- if (c=='\"') // token cha�ne de caract�res
328
- while(1)
329
- {
330
- c=nextchar();
331
- if (!c)
332
- {
333
- term->printf(LOG_COMPILER,"uncomplete string reaches EOF\n");
334
- return -1;
335
- }
336
- if ((c=='\"')&&(f==0))
337
- {
338
- savechar(index);
339
- return 0;
340
- }
341
- if (c=='\\') f=1-f;
342
- else f=0;
343
- }
344
- if (isletnum(c)) // token nombre ou label
345
- {
346
- int onlynum=1;
347
- while(1)
348
- {
349
- if (!isnum(c)) onlynum=0;
350
- c=nextchar();
351
- if (!c) return 0;
352
- if ((c=='.')&&(onlynum)) // nombre flottant
353
- {
354
- while(1)
355
- {
356
- c=nextchar();
357
- if (!c) return 0;
358
- if (!isnum(c))
359
- {
360
- againchar();
361
- savechar(index);
362
- return 0;
363
- }
364
- }
365
- }
366
- if (!isletnum(c))
367
- {
368
- againchar();
369
- savechar(index);
370
- return 0;
371
- }
372
- }
373
- }
374
- d=nextchar();
375
- if (!d) return 0; // fin du fichier sur un caract�re sp�cial
376
-
377
- if ( ((c=='&')&&(d=='&'))
378
- ||((c=='|')&&(d=='|'))
379
- ||((c==':')&&(d==':'))
380
- ||((c=='^')&&(d=='^'))
381
- ||((c==';')&&(d==';'))
382
- ||((c=='-')&&(d=='>'))
383
- ||((c=='<')&&((d=='<')||(d=='/')))
384
- ||((c=='>')&&(d=='>'))
385
- ||((c=='=')&&(d=='='))
386
- ||((c=='/')&&((d=='*')||(d=='>')))
387
- ||((c=='*')&&(d=='/'))
388
- )
389
- {
390
- // caract�re double reconnu
391
- }
392
- else if ((c=='/')&&(d=='/'))
393
- {
394
- do // cas du commentaire //
395
- {
396
- c=nextchar();
397
- if (c==10) return -2;
398
- } while (c);
399
- return -1; // fin de fichier, pas de nouveau token
400
- }
401
- else if (((c=='!')||(c=='>')||(c=='<'))&&(d=='='))
402
- {
403
- /* d=nextchar();
404
- if (!d) return 0; // fin du fichier sur un caract�re sp�cial compos�
405
- if (d!='.') againchar();
406
- */ }
407
- else
408
- againchar();
409
- savechar(index);
410
- return 0;
411
- }
412
-
413
-
414
- void Parser::echoposition()
415
- {
416
- restorechar();
417
- if (srcname) term->printf(LOG_COMPILER,">line %d in '%s' :\n>",lign0+1,srcname);
418
- else term->printf(LOG_COMPILER,">line %d :\n>",lign0+1);
419
- char* p=&src[offligne0];
420
- int i=0;
421
- while((p[i])&&(p[i]!='\n')) i++;
422
- term->echo(LOG_COMPILER,p,i);
423
- term->printf(LOG_COMPILER,"\n>");
424
- for(i=0;i<offchar0-offligne0;i++) { term->printf(LOG_COMPILER, "%c", (p[i]!='\t') ? ' ' : '\t'); }
425
- term->printf(LOG_COMPILER,"^\n");
426
- }
427
-