diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-01-25 19:50:39 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-01-25 19:50:39 -0200 |
| commit | 74907fb71e69949d63d94c4c12b80938c974a6df (patch) | |
| tree | 6093d5e5af4870fe2600eff5815d5db96969c979 /lparser.c | |
| parent | b38e594ed738238d352bb5344446ef07d15510b4 (diff) | |
| download | lua-74907fb71e69949d63d94c4c12b80938c974a6df.tar.gz lua-74907fb71e69949d63d94c4c12b80938c974a6df.tar.bz2 lua-74907fb71e69949d63d94c4c12b80938c974a6df.zip | |
OP_LOADINT can be done by OP_LOADK
Diffstat (limited to 'lparser.c')
| -rw-r--r-- | lparser.c | 37 |
1 files changed, 18 insertions, 19 deletions
| @@ -130,12 +130,12 @@ static TString *str_checkname (LexState *ls) { | |||
| 130 | static void init_exp (expdesc *e, expkind k, int i) { | 130 | static void init_exp (expdesc *e, expkind k, int i) { |
| 131 | e->f = e->t = NO_JUMP; | 131 | e->f = e->t = NO_JUMP; |
| 132 | e->k = k; | 132 | e->k = k; |
| 133 | e->u.i.info = i; | 133 | e->info = i; |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | 136 | ||
| 137 | static void codestring (LexState *ls, expdesc *e, TString *s) { | 137 | static void codestring (LexState *ls, expdesc *e, TString *s) { |
| 138 | init_exp(e, VK, luaK_stringk(ls->fs, s)); | 138 | init_exp(e, VK, luaK_stringK(ls->fs, s)); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | 141 | ||
| @@ -201,7 +201,7 @@ static void new_localvarstr (LexState *ls, const char *name, int n) { | |||
| 201 | static int indexupvalue (FuncState *fs, expdesc *v) { | 201 | static int indexupvalue (FuncState *fs, expdesc *v) { |
| 202 | int i; | 202 | int i; |
| 203 | for (i=0; i<fs->f->nupvalues; i++) { | 203 | for (i=0; i<fs->f->nupvalues; i++) { |
| 204 | if (fs->upvalues[i].k == v->k && fs->upvalues[i].u.i.info == v->u.i.info) | 204 | if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->info) |
| 205 | return i; | 205 | return i; |
| 206 | } | 206 | } |
| 207 | /* new one */ | 207 | /* new one */ |
| @@ -228,10 +228,10 @@ static void singlevar (FuncState *fs, TString *n, expdesc *var, int baselevel) { | |||
| 228 | singlevar(fs->prev, n, var, 0); | 228 | singlevar(fs->prev, n, var, 0); |
| 229 | if (var->k == VGLOBAL) { | 229 | if (var->k == VGLOBAL) { |
| 230 | if (baselevel) | 230 | if (baselevel) |
| 231 | var->u.i.info = luaK_stringk(fs, n); /* info points to global name */ | 231 | var->info = luaK_stringK(fs, n); /* info points to global name */ |
| 232 | } | 232 | } |
| 233 | else { /* local variable in some upper level? */ | 233 | else { /* local variable in some upper level? */ |
| 234 | var->u.i.info = indexupvalue(fs, var); | 234 | var->info = indexupvalue(fs, var); |
| 235 | var->k = VUPVAL; /* upvalue in this level */ | 235 | var->k = VUPVAL; /* upvalue in this level */ |
| 236 | } | 236 | } |
| 237 | } | 237 | } |
| @@ -447,7 +447,7 @@ static void funcargs (LexState *ls, expdesc *f) { | |||
| 447 | } | 447 | } |
| 448 | } | 448 | } |
| 449 | lua_assert(f->k == VNONRELOC); | 449 | lua_assert(f->k == VNONRELOC); |
| 450 | base = f->u.i.info; /* base register for call */ | 450 | base = f->info; /* base register for call */ |
| 451 | if (args.k == VCALL) | 451 | if (args.k == VCALL) |
| 452 | nparams = LUA_MULTRET; /* open call */ | 452 | nparams = LUA_MULTRET; /* open call */ |
| 453 | else { | 453 | else { |
| @@ -489,7 +489,7 @@ static void recfield (LexState *ls, expdesc *t) { | |||
| 489 | luaK_exp2RK(fs, &key); | 489 | luaK_exp2RK(fs, &key); |
| 490 | expr(ls, &val); | 490 | expr(ls, &val); |
| 491 | luaK_exp2anyreg(fs, &val); | 491 | luaK_exp2anyreg(fs, &val); |
| 492 | luaK_codeABC(fs, OP_SETTABLE, val.u.i.info, t->u.i.info, | 492 | luaK_codeABC(fs, OP_SETTABLE, val.info, t->info, |
| 493 | luaK_exp2RK(fs, &key)); | 493 | luaK_exp2RK(fs, &key)); |
| 494 | fs->freereg = reg; /* free registers */ | 494 | fs->freereg = reg; /* free registers */ |
| 495 | } | 495 | } |
| @@ -526,7 +526,7 @@ static int listfields (LexState *ls, expdesc *t) { | |||
| 526 | luaK_exp2nextreg(fs, &v); | 526 | luaK_exp2nextreg(fs, &v); |
| 527 | luaX_checklimit(ls, n, MAXARG_Bc, "items in a constructor"); | 527 | luaX_checklimit(ls, n, MAXARG_Bc, "items in a constructor"); |
| 528 | if (n%LFIELDS_PER_FLUSH == 0) { | 528 | if (n%LFIELDS_PER_FLUSH == 0) { |
| 529 | luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); /* flush */ | 529 | luaK_codeABc(fs, OP_SETLIST, t->info, n-1); /* flush */ |
| 530 | fs->freereg = reg; /* free registers */ | 530 | fs->freereg = reg; /* free registers */ |
| 531 | } | 531 | } |
| 532 | expr(ls, &v); | 532 | expr(ls, &v); |
| @@ -534,11 +534,11 @@ static int listfields (LexState *ls, expdesc *t) { | |||
| 534 | } | 534 | } |
| 535 | if (v.k == VCALL) { | 535 | if (v.k == VCALL) { |
| 536 | luaK_setcallreturns(fs, &v, LUA_MULTRET); | 536 | luaK_setcallreturns(fs, &v, LUA_MULTRET); |
| 537 | luaK_codeABc(fs, OP_SETLISTO, t->u.i.info, n-1); | 537 | luaK_codeABc(fs, OP_SETLISTO, t->info, n-1); |
| 538 | } | 538 | } |
| 539 | else { | 539 | else { |
| 540 | luaK_exp2nextreg(fs, &v); | 540 | luaK_exp2nextreg(fs, &v); |
| 541 | luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); | 541 | luaK_codeABc(fs, OP_SETLIST, t->info, n-1); |
| 542 | } | 542 | } |
| 543 | fs->freereg = reg; /* free registers */ | 543 | fs->freereg = reg; /* free registers */ |
| 544 | return n; | 544 | return n; |
| @@ -686,8 +686,7 @@ static void simpleexp (LexState *ls, expdesc *v) { | |||
| 686 | | primaryexp */ | 686 | | primaryexp */ |
| 687 | switch (ls->t.token) { | 687 | switch (ls->t.token) { |
| 688 | case TK_NUMBER: { | 688 | case TK_NUMBER: { |
| 689 | init_exp(v, VNUMBER, 0); | 689 | init_exp(v, VK, luaK_numberK(ls->fs, ls->t.seminfo.r)); |
| 690 | v->u.n = ls->t.seminfo.r; | ||
| 691 | next(ls); /* must use `seminfo' before `next' */ | 690 | next(ls); /* must use `seminfo' before `next' */ |
| 692 | break; | 691 | break; |
| 693 | } | 692 | } |
| @@ -859,18 +858,18 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { | |||
| 859 | int conflict = 0; | 858 | int conflict = 0; |
| 860 | for (; lh; lh = lh->prev) { | 859 | for (; lh; lh = lh->prev) { |
| 861 | if (lh->v.k == VINDEXED) { | 860 | if (lh->v.k == VINDEXED) { |
| 862 | if (lh->v.u.i.info == v->u.i.info) { /* conflict? */ | 861 | if (lh->v.info == v->info) { /* conflict? */ |
| 863 | conflict = 1; | 862 | conflict = 1; |
| 864 | lh->v.u.i.info = extra; /* previous assignment will use safe copy */ | 863 | lh->v.info = extra; /* previous assignment will use safe copy */ |
| 865 | } | 864 | } |
| 866 | if (lh->v.u.i.aux == v->u.i.info) { /* conflict? */ | 865 | if (lh->v.aux == v->info) { /* conflict? */ |
| 867 | conflict = 1; | 866 | conflict = 1; |
| 868 | lh->v.u.i.aux = extra; /* previous assignment will use safe copy */ | 867 | lh->v.aux = extra; /* previous assignment will use safe copy */ |
| 869 | } | 868 | } |
| 870 | } | 869 | } |
| 871 | } | 870 | } |
| 872 | if (conflict) { | 871 | if (conflict) { |
| 873 | luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.i.info, 0); /* make copy */ | 872 | luaK_codeABC(fs, OP_MOVE, fs->freereg, v->info, 0); /* make copy */ |
| 874 | luaK_reserveregs(fs, 1); | 873 | luaK_reserveregs(fs, 1); |
| 875 | } | 874 | } |
| 876 | } | 875 | } |
| @@ -980,8 +979,8 @@ static void fornum (LexState *ls, TString *varname) { | |||
| 980 | exp1(ls); /* limit */ | 979 | exp1(ls); /* limit */ |
| 981 | if (optional(ls, ',')) | 980 | if (optional(ls, ',')) |
| 982 | exp1(ls); /* optional step */ | 981 | exp1(ls); /* optional step */ |
| 983 | else { | 982 | else { /* default step = 1 */ |
| 984 | luaK_codeAsBc(fs, OP_LOADINT, fs->freereg, 1); /* default step */ | 983 | luaK_codeABc(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); |
| 985 | luaK_reserveregs(fs, 1); | 984 | luaK_reserveregs(fs, 1); |
| 986 | } | 985 | } |
| 987 | new_localvar(ls, varname, 0); | 986 | new_localvar(ls, varname, 0); |
