diff options
-rw-r--r-- | lopcodes.h | 26 | ||||
-rw-r--r-- | lparser.c | 17 | ||||
-rw-r--r-- | lvm.c | 11 |
3 files changed, 22 insertions, 32 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.32 1999/03/10 14:09:45 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.33 1999/06/17 17:04:03 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -20,12 +20,12 @@ typedef enum { | |||
20 | ENDCODE,/* - - (return) */ | 20 | ENDCODE,/* - - (return) */ |
21 | RETCODE,/* b - (return) */ | 21 | RETCODE,/* b - (return) */ |
22 | 22 | ||
23 | CALL,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */ | 23 | CALL,/* b c v_n-v_1 f(at c) r_b-r_1 f(v1,...,v_n) */ |
24 | 24 | ||
25 | TAILCALL,/* b c v_c...v_1 f (return) f(v1,...,v_c) */ | 25 | TAILCALL,/* b c v_c-v_1 f (return) f(v1,...,v_c) */ |
26 | 26 | ||
27 | PUSHNIL,/* b - nil_0...nil_b */ | 27 | PUSHNIL,/* b - nil_0-nil_b */ |
28 | POP,/* b a_b...a_1 - */ | 28 | POP,/* b a_b-a_1 - */ |
29 | 29 | ||
30 | PUSHNUMBERW,/* w - (float)w */ | 30 | PUSHNUMBERW,/* w - (float)w */ |
31 | PUSHNUMBER,/* b - (float)b */ | 31 | PUSHNUMBER,/* b - (float)b */ |
@@ -61,12 +61,12 @@ SETGLOBAL,/* b x - VAR[CNST[b]]=x */ | |||
61 | 61 | ||
62 | SETTABLEPOP,/* - v i t - t[i]=v */ | 62 | SETTABLEPOP,/* - v i t - t[i]=v */ |
63 | 63 | ||
64 | SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ | 64 | SETTABLE,/* b v a_b-a_1 i t a_b-a_1 i t t[i]=v */ |
65 | 65 | ||
66 | SETLISTW,/* w c v_c...v_1 t t t[i+w*FPF]=v_i */ | 66 | SETLISTW,/* w c v_c-v_1 t t t[i+w*FPF]=v_i */ |
67 | SETLIST,/* b c v_c...v_1 t t t[i+b*FPF]=v_i */ | 67 | SETLIST,/* b c v_c-v_1 t t t[i+b*FPF]=v_i */ |
68 | 68 | ||
69 | SETMAP,/* b v_b k_b ...v_0 k_0 t t t[k_i]=v_i */ | 69 | SETMAP,/* b v_b k_b - v_0 k_0 t t t[k_i]=v_i */ |
70 | 70 | ||
71 | NEQOP,/* - y x (x~=y)? 1 : nil */ | 71 | NEQOP,/* - y x (x~=y)? 1 : nil */ |
72 | EQOP,/* - y x (x==y)? 1 : nil */ | 72 | EQOP,/* - y x (x==y)? 1 : nil */ |
@@ -96,16 +96,14 @@ IFTUPJMP,/* b x - (x!=nil)? PC-=b */ | |||
96 | IFFUPJMPW,/* w x - (x==nil)? PC-=w */ | 96 | IFFUPJMPW,/* w x - (x==nil)? PC-=w */ |
97 | IFFUPJMP,/* b x - (x==nil)? PC-=b */ | 97 | IFFUPJMP,/* b x - (x==nil)? PC-=b */ |
98 | 98 | ||
99 | CLOSUREW,/* w c v_c...v_1 closure(CNST[w], v_c...v_1) */ | 99 | CLOSUREW,/* w c v_c-v_1 closure(CNST[w], v_c-v_1) */ |
100 | CLOSURE,/* b c v_c...v_1 closure(CNST[b], v_c...v_1) */ | 100 | CLOSURE,/* b c v_c-v_1 closure(CNST[b], v_c-v_1) */ |
101 | 101 | ||
102 | SETLINEW,/* w - - LINE=w */ | 102 | SETLINEW,/* w - - LINE=w */ |
103 | SETLINE,/* b - - LINE=b */ | 103 | SETLINE,/* b - - LINE=b */ |
104 | 104 | ||
105 | LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */ | 105 | LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */ |
106 | LONGARG,/* b (add b*(1<<16) to arg of next instruction) */ | 106 | LONGARG /* b (add b*(1<<16) to arg of next instruction) */ |
107 | |||
108 | CHECKSTACK /* b (assert #temporaries == b; only for internal debuging!) */ | ||
109 | 107 | ||
110 | } OpCode; | 108 | } OpCode; |
111 | 109 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.42 1999/11/04 17:23:12 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.43 1999/11/22 13:12:07 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -426,12 +426,9 @@ static void close_exp (LexState *ls, int pc, int nresults) { | |||
426 | if (pc > 0) { /* expression is an open function call? */ | 426 | if (pc > 0) { /* expression is an open function call? */ |
427 | Byte *code = ls->fs->f->code; | 427 | Byte *code = ls->fs->f->code; |
428 | code[pc-1] = (Byte)nresults; /* set nresults */ | 428 | code[pc-1] = (Byte)nresults; /* set nresults */ |
429 | /* push results, pop params (at code[pc]) and function */ | 429 | if (nresults != MULT_RET) |
430 | deltastack(ls, nresults-(code[pc]+1)); | 430 | deltastack(ls, nresults); /* push results */ |
431 | } | 431 | } |
432 | #ifdef DEBUG | ||
433 | code_oparg(ls, CHECKSTACK, ls->fs->stacksize, 0); | ||
434 | #endif | ||
435 | } | 432 | } |
436 | 433 | ||
437 | 434 | ||
@@ -1152,7 +1149,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v) { | |||
1152 | 1149 | ||
1153 | static int funcparams (LexState *ls, int slf) { | 1150 | static int funcparams (LexState *ls, int slf) { |
1154 | FuncState *fs = ls->fs; | 1151 | FuncState *fs = ls->fs; |
1155 | int nparams = 1; /* in cases STRING and constructor */ | 1152 | int slevel = fs->stacksize - slf - 1; /* where is func in the stack */ |
1156 | switch (ls->token) { | 1153 | switch (ls->token) { |
1157 | case '(': { /* funcparams -> '(' explist ')' */ | 1154 | case '(': { /* funcparams -> '(' explist ')' */ |
1158 | int line = ls->linenumber; | 1155 | int line = ls->linenumber; |
@@ -1160,8 +1157,7 @@ static int funcparams (LexState *ls, int slf) { | |||
1160 | next(ls); | 1157 | next(ls); |
1161 | explist(ls, &e); | 1158 | explist(ls, &e); |
1162 | check_match(ls, ')', '(', line); | 1159 | check_match(ls, ')', '(', line); |
1163 | close_exp(ls, e.pc, 1); | 1160 | close_exp(ls, e.pc, MULT_RET); /* close 1 for old semantics */ |
1164 | nparams = e.n; | ||
1165 | break; | 1161 | break; |
1166 | } | 1162 | } |
1167 | 1163 | ||
@@ -1180,7 +1176,8 @@ static int funcparams (LexState *ls, int slf) { | |||
1180 | } | 1176 | } |
1181 | code_byte(ls, CALL); | 1177 | code_byte(ls, CALL); |
1182 | code_byte(ls, 0); /* save space for nresult */ | 1178 | code_byte(ls, 0); /* save space for nresult */ |
1183 | code_byte(ls, (Byte)(nparams+slf)); | 1179 | code_byte(ls, (Byte)slevel); |
1180 | fs->stacksize = slevel; /* call will remove func and params */ | ||
1184 | return fs->pc-1; | 1181 | return fs->pc-1; |
1185 | } | 1182 | } |
1186 | 1183 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.65 1999/11/04 17:22:26 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.66 1999/11/22 13:12:07 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -325,11 +325,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, StkId | |||
325 | goto ret; | 325 | goto ret; |
326 | 326 | ||
327 | case CALL: aux = *pc++; | 327 | case CALL: aux = *pc++; |
328 | luaD_calln(L, *pc++, aux); | 328 | luaD_call(L, (S->stack+base) + *pc++, aux); |
329 | break; | 329 | break; |
330 | 330 | ||
331 | case TAILCALL: aux = *pc++; | 331 | case TAILCALL: aux = *pc++; |
332 | luaD_calln(L, *pc++, MULT_RET); | 332 | luaD_call(L, (S->stack+base) + *pc++, MULT_RET); |
333 | base += aux; | 333 | base += aux; |
334 | goto ret; | 334 | goto ret; |
335 | 335 | ||
@@ -604,11 +604,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, StkId | |||
604 | aux = highbyte(L, highbyte(L, aux)); | 604 | aux = highbyte(L, highbyte(L, aux)); |
605 | goto switchentry; /* do not reset "aux" */ | 605 | goto switchentry; /* do not reset "aux" */ |
606 | 606 | ||
607 | case CHECKSTACK: aux = *pc++; | ||
608 | LUA_ASSERT(L, (S->top-S->stack)-base == aux && S->last >= S->top, | ||
609 | "wrong stack size"); | ||
610 | break; | ||
611 | |||
612 | } | 607 | } |
613 | } ret: | 608 | } ret: |
614 | if (L->callhook) | 609 | if (L->callhook) |