aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-02-13 18:36:51 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-02-13 18:36:51 -0200
commit0ea84a3e799b45ea4a0e3dc2274e6034f0d2fb06 (patch)
treeabf432e7b389fd5eac0307ebb6256ce241ef46b4
parent2c9d30f9b0fc891b64c5f1e8492f112bbcb8f5fa (diff)
downloadlua-0ea84a3e799b45ea4a0e3dc2274e6034f0d2fb06.tar.gz
lua-0ea84a3e799b45ea4a0e3dc2274e6034f0d2fb06.tar.bz2
lua-0ea84a3e799b45ea4a0e3dc2274e6034f0d2fb06.zip
otimizacao do codigo para construtores.
pequenas modificacoes na execucao de LOADi e similares.
-rw-r--r--opcode.c85
1 files changed, 53 insertions, 32 deletions
diff --git a/opcode.c b/opcode.c
index ab470fb8..3ba6f2d2 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: $"; 6char *rcs_opcode="$Id: opcode.c,v 1.1 1993/12/17 18:41:19 celes Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <stdlib.h> 9#include <stdlib.h>
@@ -142,7 +142,8 @@ int lua_execute (Byte *pc)
142 base = top; 142 base = top;
143 while (1) 143 while (1)
144 { 144 {
145 switch ((OpCode)*pc++) 145 OpCode opcode;
146 switch (opcode = (OpCode)*pc++)
146 { 147 {
147 case NOP: break; 148 case NOP: break;
148 149
@@ -169,16 +170,10 @@ int lua_execute (Byte *pc)
169 } 170 }
170 break; 171 break;
171 172
172 case PUSHLOCAL0: *top++ = *(base + 0); break; 173 case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2:
173 case PUSHLOCAL1: *top++ = *(base + 1); break; 174 case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5:
174 case PUSHLOCAL2: *top++ = *(base + 2); break; 175 case PUSHLOCAL6: case PUSHLOCAL7: case PUSHLOCAL8:
175 case PUSHLOCAL3: *top++ = *(base + 3); break; 176 case PUSHLOCAL9: *top++ = *(base + (int)(opcode-PUSHLOCAL0)); break;
176 case PUSHLOCAL4: *top++ = *(base + 4); break;
177 case PUSHLOCAL5: *top++ = *(base + 5); break;
178 case PUSHLOCAL6: *top++ = *(base + 6); break;
179 case PUSHLOCAL7: *top++ = *(base + 7); break;
180 case PUSHLOCAL8: *top++ = *(base + 8); break;
181 case PUSHLOCAL9: *top++ = *(base + 9); break;
182 177
183 case PUSHLOCAL: *top++ = *(base + (*pc++)); break; 178 case PUSHLOCAL: *top++ = *(base + (*pc++)); break;
184 179
@@ -204,16 +199,10 @@ int lua_execute (Byte *pc)
204 199
205 case PUSHOBJECT: *top = *(top-3); top++; break; 200 case PUSHOBJECT: *top = *(top-3); top++; break;
206 201
207 case STORELOCAL0: *(base + 0) = *(--top); break; 202 case STORELOCAL0: case STORELOCAL1: case STORELOCAL2:
208 case STORELOCAL1: *(base + 1) = *(--top); break; 203 case STORELOCAL3: case STORELOCAL4: case STORELOCAL5:
209 case STORELOCAL2: *(base + 2) = *(--top); break; 204 case STORELOCAL6: case STORELOCAL7: case STORELOCAL8:
210 case STORELOCAL3: *(base + 3) = *(--top); break; 205 case STORELOCAL9: *(base + (int)(opcode-STORELOCAL0)) = *(--top); break;
211 case STORELOCAL4: *(base + 4) = *(--top); break;
212 case STORELOCAL5: *(base + 5) = *(--top); break;
213 case STORELOCAL6: *(base + 6) = *(--top); break;
214 case STORELOCAL7: *(base + 7) = *(--top); break;
215 case STORELOCAL8: *(base + 8) = *(--top); break;
216 case STORELOCAL9: *(base + 9) = *(--top); break;
217 206
218 case STORELOCAL: *(base + (*pc++)) = *(--top); break; 207 case STORELOCAL: *(base + (*pc++)) = *(--top); break;
219 208
@@ -248,31 +237,63 @@ int lua_execute (Byte *pc)
248 if (h == NULL) return 1; 237 if (h == NULL) return 1;
249 *h = *(top-1); 238 *h = *(top-1);
250 } 239 }
251 --top; 240 top--;
252 } 241 }
253 break; 242 break;
254 243
255 case STOREFIELD: 244 case STORELIST0:
256 if (tag(top-3) != T_ARRAY) 245 case STORELIST:
246 {
247 int m, n;
248 Object *arr;
249 if (opcode == STORELIST0) m = 0;
250 else m = *(pc++) * FIELDS_PER_FLUSH;
251 n = *(pc++);
252 arr = top-n-1;
253 if (tag(arr) != T_ARRAY)
257 { 254 {
258 lua_reportbug ("internal error - table expected"); 255 lua_reportbug ("internal error - table expected");
259 return 1; 256 return 1;
260 } 257 }
261 *(lua_hashdefine (avalue(top-3), top-2)) = *(top-1); 258 while (n)
262 top -= 2; 259 {
260 tag(top) = T_NUMBER; nvalue(top) = n+m;
261 *(lua_hashdefine (avalue(arr), top)) = *(top-1);
262 top--;
263 n--;
264 }
265 }
263 break; 266 break;
264 267
265 case ADJUST: 268 case STORERECORD:
266 { 269 {
267 Object *newtop = base + *(pc++); 270 int n = *(pc++);
268 if (top != newtop) 271 Object *arr = top-n-1;
272 if (tag(arr) != T_ARRAY)
269 { 273 {
270 while (top < newtop) tag(top++) = T_NIL; 274 lua_reportbug ("internal error - table expected");
271 top = newtop; 275 return 1;
276 }
277 while (n)
278 {
279 int w = *((Word *)(pc));
280 pc += sizeof(Word);
281 tag(top) = T_STRING; svalue(top) = lua_constant[w];
282 *(lua_hashdefine (avalue(arr), top)) = *(top-1);
283 top--;
284 n--;
272 } 285 }
273 } 286 }
274 break; 287 break;
275 288
289 case ADJUST:
290 {
291 Object *newtop = base + *(pc++);
292 while (top < newtop) tag(top++) = T_NIL;
293 top = newtop; /* top could be bigger than newtop */
294 }
295 break;
296
276 case CREATEARRAY: 297 case CREATEARRAY:
277 if (tag(top-1) == T_NIL) 298 if (tag(top-1) == T_NIL)
278 nvalue(top-1) = 101; 299 nvalue(top-1) = 101;