diff options
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 1.53 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.54 2000/12/26 18:46:09 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -102,14 +102,14 @@ void luaK_kstr (LexState *ls, int c) { | |||
102 | static int number_constant (FuncState *fs, lua_Number r) { | 102 | static int number_constant (FuncState *fs, lua_Number r) { |
103 | /* check whether `r' has appeared within the last LOOKBACKNUMS entries */ | 103 | /* check whether `r' has appeared within the last LOOKBACKNUMS entries */ |
104 | Proto *f = fs->f; | 104 | Proto *f = fs->f; |
105 | int c = f->nknum; | 105 | int c = fs->nknum; |
106 | int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS; | 106 | int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS; |
107 | while (--c >= lim) | 107 | while (--c >= lim) |
108 | if (f->knum[c] == r) return c; | 108 | if (f->knum[c] == r) return c; |
109 | /* not found; create a new entry */ | 109 | /* not found; create a new entry */ |
110 | luaM_growvector(fs->L, f->knum, f->nknum, fs->sizeknum, lua_Number, | 110 | luaM_growvector(fs->L, f->knum, fs->nknum, f->sizeknum, lua_Number, |
111 | MAXARG_U, "constant table overflow"); | 111 | MAXARG_U, "constant table overflow"); |
112 | c = f->nknum++; | 112 | c = fs->nknum++; |
113 | f->knum[c] = r; | 113 | f->knum[c] = r; |
114 | return c; | 114 | return c; |
115 | } | 115 | } |
@@ -424,13 +424,13 @@ static void codelineinfo (FuncState *fs) { | |||
424 | LexState *ls = fs->ls; | 424 | LexState *ls = fs->ls; |
425 | if (ls->lastline > fs->lastline) { | 425 | if (ls->lastline > fs->lastline) { |
426 | if (ls->lastline > fs->lastline+1) { | 426 | if (ls->lastline > fs->lastline+1) { |
427 | luaM_growvector(fs->L, f->lineinfo, f->nlineinfo, fs->sizelineinfo, int, | 427 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, |
428 | MAX_INT, "line info overflow"); | 428 | MAX_INT, "line info overflow"); |
429 | f->lineinfo[f->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); | 429 | f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); |
430 | } | 430 | } |
431 | luaM_growvector(fs->L, f->lineinfo, f->nlineinfo, fs->sizelineinfo, int, | 431 | luaM_growvector(fs->L, f->lineinfo, fs->nlineinfo, f->sizelineinfo, int, |
432 | MAX_INT, "line info overflow"); | 432 | MAX_INT, "line info overflow"); |
433 | f->lineinfo[f->nlineinfo++] = fs->pc; | 433 | f->lineinfo[fs->nlineinfo++] = fs->pc; |
434 | fs->lastline = ls->lastline; | 434 | fs->lastline = ls->lastline; |
435 | } | 435 | } |
436 | } | 436 | } |
@@ -447,6 +447,7 @@ int luaK_code1 (FuncState *fs, OpCode o, int arg1) { | |||
447 | 447 | ||
448 | 448 | ||
449 | int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) { | 449 | int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) { |
450 | Proto *f; | ||
450 | Instruction i = previous_instruction(fs); | 451 | Instruction i = previous_instruction(fs); |
451 | int delta = (int)luaK_opproperties[o].push - (int)luaK_opproperties[o].pop; | 452 | int delta = (int)luaK_opproperties[o].push - (int)luaK_opproperties[o].pop; |
452 | int optm = 0; /* 1 when there is an optimization */ | 453 | int optm = 0; /* 1 when there is an optimization */ |
@@ -629,9 +630,10 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) { | |||
629 | break; | 630 | break; |
630 | } | 631 | } |
631 | } | 632 | } |
633 | f = fs->f; | ||
632 | luaK_deltastack(fs, delta); | 634 | luaK_deltastack(fs, delta); |
633 | if (optm) { /* optimize: put instruction in place of last one */ | 635 | if (optm) { /* optimize: put instruction in place of last one */ |
634 | fs->f->code[fs->pc-1] = i; /* change previous instruction */ | 636 | f->code[fs->pc-1] = i; /* change previous instruction */ |
635 | return fs->pc-1; /* do not generate new instruction */ | 637 | return fs->pc-1; /* do not generate new instruction */ |
636 | } | 638 | } |
637 | /* else build new instruction */ | 639 | /* else build new instruction */ |
@@ -643,9 +645,9 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) { | |||
643 | } | 645 | } |
644 | codelineinfo(fs); | 646 | codelineinfo(fs); |
645 | /* put new instruction in code array */ | 647 | /* put new instruction in code array */ |
646 | luaM_growvector(fs->L, fs->f->code, fs->pc, fs->sizecode, Instruction, | 648 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, |
647 | MAX_INT, "code size overflow"); | 649 | MAX_INT, "code size overflow"); |
648 | fs->f->code[fs->pc] = i; | 650 | f->code[fs->pc] = i; |
649 | return fs->pc++; | 651 | return fs->pc++; |
650 | } | 652 | } |
651 | 653 | ||