diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-09-23 17:33:05 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-09-23 17:33:05 -0300 |
commit | fcc46467fa92c8e9951e63baf2c3e1b22bf20a1f (patch) | |
tree | 54e6ab8b2b6d720911251e6863ddca1e54a75cd0 /lcode.c | |
parent | f8e354e2404cbd0a91b4299598d4de9757e73fd7 (diff) | |
download | lua-fcc46467fa92c8e9951e63baf2c3e1b22bf20a1f.tar.gz lua-fcc46467fa92c8e9951e63baf2c3e1b22bf20a1f.tar.bz2 lua-fcc46467fa92c8e9951e63baf2c3e1b22bf20a1f.zip |
limit of constants per function changed to 2^26 using extra arguments
to opcodes LOADK, GETGLOBAL, and SETGLOBAL
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 103 |
1 files changed, 54 insertions, 49 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.40 2009/06/18 16:35:05 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.41 2009/08/10 15:31:44 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 | */ |
@@ -191,6 +191,55 @@ void luaK_concat (FuncState *fs, int *l1, int l2) { | |||
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
194 | static int luaK_code (FuncState *fs, Instruction i) { | ||
195 | Proto *f = fs->f; | ||
196 | dischargejpc(fs); /* `pc' will change */ | ||
197 | /* put new instruction in code array */ | ||
198 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, | ||
199 | MAX_INT, "opcodes"); | ||
200 | f->code[fs->pc] = i; | ||
201 | /* save corresponding line information */ | ||
202 | luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, | ||
203 | MAX_INT, "opcodes"); | ||
204 | f->lineinfo[fs->pc] = fs->ls->lastline; | ||
205 | return fs->pc++; | ||
206 | } | ||
207 | |||
208 | |||
209 | int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { | ||
210 | lua_assert(getOpMode(o) == iABC); | ||
211 | lua_assert(getBMode(o) != OpArgN || b == 0); | ||
212 | lua_assert(getCMode(o) != OpArgN || c == 0); | ||
213 | lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C); | ||
214 | return luaK_code(fs, CREATE_ABC(o, a, b, c)); | ||
215 | } | ||
216 | |||
217 | |||
218 | int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { | ||
219 | lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); | ||
220 | lua_assert(getCMode(o) == OpArgN); | ||
221 | lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx); | ||
222 | return luaK_code(fs, CREATE_ABx(o, a, bc)); | ||
223 | } | ||
224 | |||
225 | |||
226 | static int codeextraarg (FuncState *fs, int a) { | ||
227 | lua_assert(a <= MAXARG_Ax); | ||
228 | return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a)); | ||
229 | } | ||
230 | |||
231 | |||
232 | int luaK_codeABxX (FuncState *fs, OpCode o, int reg, int k) { | ||
233 | if (k < MAXARG_Bx) | ||
234 | return luaK_codeABx(fs, o, reg, k + 1); | ||
235 | else { | ||
236 | int p = luaK_codeABx(fs, o, reg, 0); | ||
237 | codeextraarg(fs, k); | ||
238 | return p; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | |||
194 | void luaK_checkstack (FuncState *fs, int n) { | 243 | void luaK_checkstack (FuncState *fs, int n) { |
195 | int newstack = fs->freereg + n; | 244 | int newstack = fs->freereg + n; |
196 | if (newstack > fs->f->maxstacksize) { | 245 | if (newstack > fs->f->maxstacksize) { |
@@ -238,7 +287,7 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { | |||
238 | oldsize = f->sizek; | 287 | oldsize = f->sizek; |
239 | k = fs->nk; | 288 | k = fs->nk; |
240 | setnvalue(idx, cast_num(k)); | 289 | setnvalue(idx, cast_num(k)); |
241 | luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Bx, "constants"); | 290 | luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); |
242 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); | 291 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); |
243 | setobj(L, &f->k[k], v); | 292 | setobj(L, &f->k[k], v); |
244 | fs->nk++; | 293 | fs->nk++; |
@@ -324,7 +373,7 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { | |||
324 | break; | 373 | break; |
325 | } | 374 | } |
326 | case VGLOBAL: { | 375 | case VGLOBAL: { |
327 | e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); | 376 | e->u.s.info = luaK_codeABxX(fs, OP_GETGLOBAL, 0, e->u.s.info); |
328 | e->k = VRELOCABLE; | 377 | e->k = VRELOCABLE; |
329 | break; | 378 | break; |
330 | } | 379 | } |
@@ -496,7 +545,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { | |||
496 | } | 545 | } |
497 | case VGLOBAL: { | 546 | case VGLOBAL: { |
498 | int e = luaK_exp2anyreg(fs, ex); | 547 | int e = luaK_exp2anyreg(fs, ex); |
499 | luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); | 548 | luaK_codeABxX(fs, OP_SETGLOBAL, e, var->u.s.info); |
500 | break; | 549 | break; |
501 | } | 550 | } |
502 | case VINDEXED: { | 551 | case VINDEXED: { |
@@ -802,50 +851,6 @@ void luaK_fixline (FuncState *fs, int line) { | |||
802 | } | 851 | } |
803 | 852 | ||
804 | 853 | ||
805 | static int luaK_code (FuncState *fs, Instruction i) { | ||
806 | Proto *f = fs->f; | ||
807 | dischargejpc(fs); /* `pc' will change */ | ||
808 | /* put new instruction in code array */ | ||
809 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, | ||
810 | MAX_INT, "opcodes"); | ||
811 | f->code[fs->pc] = i; | ||
812 | /* save corresponding line information */ | ||
813 | luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, | ||
814 | MAX_INT, "opcodes"); | ||
815 | f->lineinfo[fs->pc] = fs->ls->lastline; | ||
816 | return fs->pc++; | ||
817 | } | ||
818 | |||
819 | |||
820 | int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { | ||
821 | lua_assert(getOpMode(o) == iABC); | ||
822 | lua_assert(getBMode(o) != OpArgN || b == 0); | ||
823 | lua_assert(getCMode(o) != OpArgN || c == 0); | ||
824 | lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C); | ||
825 | return luaK_code(fs, CREATE_ABC(o, a, b, c)); | ||
826 | } | ||
827 | |||
828 | |||
829 | int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { | ||
830 | lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); | ||
831 | lua_assert(getCMode(o) == OpArgN); | ||
832 | lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx); | ||
833 | return luaK_code(fs, CREATE_ABx(o, a, bc)); | ||
834 | } | ||
835 | |||
836 | |||
837 | static int luaK_codeAx (FuncState *fs, OpCode o, int a) { | ||
838 | lua_assert(getOpMode(o) == iAx); | ||
839 | lua_assert(a <= MAXARG_Ax); | ||
840 | return luaK_code(fs, CREATE_Ax(o, a)); | ||
841 | } | ||
842 | |||
843 | |||
844 | void luaK_codek (FuncState *fs, int reg, int k) { | ||
845 | luaK_codeABx(fs, OP_LOADK, reg, k); | ||
846 | } | ||
847 | |||
848 | |||
849 | void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { | 854 | void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { |
850 | int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; | 855 | int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; |
851 | int b = (tostore == LUA_MULTRET) ? 0 : tostore; | 856 | int b = (tostore == LUA_MULTRET) ? 0 : tostore; |
@@ -854,7 +859,7 @@ void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { | |||
854 | luaK_codeABC(fs, OP_SETLIST, base, b, c); | 859 | luaK_codeABC(fs, OP_SETLIST, base, b, c); |
855 | else if (c <= MAXARG_Ax) { | 860 | else if (c <= MAXARG_Ax) { |
856 | luaK_codeABC(fs, OP_SETLIST, base, b, 0); | 861 | luaK_codeABC(fs, OP_SETLIST, base, b, 0); |
857 | luaK_codeAx(fs, OP_EXTRAARG, c); | 862 | codeextraarg(fs, c); |
858 | } | 863 | } |
859 | else | 864 | else |
860 | luaX_syntaxerror(fs->ls, "constructor too long"); | 865 | luaX_syntaxerror(fs->ls, "constructor too long"); |