summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-10-03 11:02:40 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-10-03 11:02:40 -0300
commit6dd0c6ccbcddc875933cab872008f57cbbbf997b (patch)
tree1be44c1159f8d1d0c06bd884e5c86498e7652f55
parenta77413acd0735754ffedde30bd09d86897964534 (diff)
downloadlua-6dd0c6ccbcddc875933cab872008f57cbbbf997b.tar.gz
lua-6dd0c6ccbcddc875933cab872008f57cbbbf997b.tar.bz2
lua-6dd0c6ccbcddc875933cab872008f57cbbbf997b.zip
numeral expressions keep their values in struct 'expdesc'
-rw-r--r--lcode.h6
-rw-r--r--lparser.c39
-rw-r--r--lparser.h8
3 files changed, 29 insertions, 24 deletions
diff --git a/lcode.h b/lcode.h
index 5a61b603..792693c6 100644
--- a/lcode.h
+++ b/lcode.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.h,v 1.44 2005/05/20 15:53:42 roberto Exp $ 2** $Id: lcode.h,v 1.45 2005/08/29 20:49:21 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*/
@@ -24,7 +24,7 @@
24** grep "ORDER OPR" if you change these enums 24** grep "ORDER OPR" if you change these enums
25*/ 25*/
26typedef enum BinOpr { 26typedef enum BinOpr {
27 OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_MOD, OPR_POW, 27 OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
28 OPR_CONCAT, 28 OPR_CONCAT,
29 OPR_NE, OPR_EQ, 29 OPR_NE, OPR_EQ,
30 OPR_LT, OPR_LE, OPR_GT, OPR_GE, 30 OPR_LT, OPR_LE, OPR_GT, OPR_GE,
@@ -37,7 +37,7 @@ typedef enum BinOpr {
37typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 37typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
38 38
39 39
40#define getcode(fs,e) ((fs)->f->code[(e)->info]) 40#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info])
41 41
42#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 42#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
43 43
diff --git a/lparser.c b/lparser.c
index 24c8e69e..d7964f1d 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.35 2005/08/29 20:49:21 roberto Exp roberto $ 2** $Id: lparser.c,v 2.36 2005/09/30 14:21:56 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -144,7 +144,7 @@ static TString *str_checkname (LexState *ls) {
144static void init_exp (expdesc *e, expkind k, int i) { 144static void init_exp (expdesc *e, expkind k, int i) {
145 e->f = e->t = NO_JUMP; 145 e->f = e->t = NO_JUMP;
146 e->k = k; 146 e->k = k;
147 e->info = i; 147 e->u.s.info = i;
148} 148}
149 149
150 150
@@ -203,7 +203,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
203 Proto *f = fs->f; 203 Proto *f = fs->f;
204 int oldsize = f->sizeupvalues; 204 int oldsize = f->sizeupvalues;
205 for (i=0; i<f->nups; i++) { 205 for (i=0; i<f->nups; i++) {
206 if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->info) { 206 if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {
207 lua_assert(f->upvalues[i] == name); 207 lua_assert(f->upvalues[i] == name);
208 return i; 208 return i;
209 } 209 }
@@ -217,7 +217,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
217 luaC_objbarrier(fs->L, f, name); 217 luaC_objbarrier(fs->L, f, name);
218 lua_assert(v->k == VLOCAL || v->k == VUPVAL); 218 lua_assert(v->k == VLOCAL || v->k == VUPVAL);
219 fs->upvalues[f->nups].k = cast(lu_byte, v->k); 219 fs->upvalues[f->nups].k = cast(lu_byte, v->k);
220 fs->upvalues[f->nups].info = cast(lu_byte, v->info); 220 fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info);
221 return f->nups++; 221 return f->nups++;
222} 222}
223 223
@@ -255,7 +255,7 @@ static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
255 else { /* not found at current level; try upper one */ 255 else { /* not found at current level; try upper one */
256 if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) 256 if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)
257 return VGLOBAL; 257 return VGLOBAL;
258 var->info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ 258 var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */
259 var->k = VUPVAL; /* upvalue in this level */ 259 var->k = VUPVAL; /* upvalue in this level */
260 return VUPVAL; 260 return VUPVAL;
261 } 261 }
@@ -267,7 +267,7 @@ static void singlevar (LexState *ls, expdesc *var) {
267 TString *varname = str_checkname(ls); 267 TString *varname = str_checkname(ls);
268 FuncState *fs = ls->fs; 268 FuncState *fs = ls->fs;
269 if (singlevaraux(fs, varname, var, 1) == VGLOBAL) 269 if (singlevaraux(fs, varname, var, 1) == VGLOBAL)
270 var->info = luaK_stringK(fs, varname); /* info points to global name */ 270 var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */
271} 271}
272 272
273 273
@@ -472,8 +472,8 @@ static void recfield (LexState *ls, struct ConsControl *cc) {
472 checknext(ls, '='); 472 checknext(ls, '=');
473 luaK_exp2RK(fs, &key); 473 luaK_exp2RK(fs, &key);
474 expr(ls, &val); 474 expr(ls, &val);
475 luaK_codeABC(fs, OP_SETTABLE, cc->t->info, luaK_exp2RK(fs, &key), 475 luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, luaK_exp2RK(fs, &key),
476 luaK_exp2RK(fs, &val)); 476 luaK_exp2RK(fs, &val));
477 fs->freereg = reg; /* free registers */ 477 fs->freereg = reg; /* free registers */
478} 478}
479 479
@@ -483,7 +483,7 @@ static void closelistfield (FuncState *fs, struct ConsControl *cc) {
483 luaK_exp2nextreg(fs, &cc->v); 483 luaK_exp2nextreg(fs, &cc->v);
484 cc->v.k = VVOID; 484 cc->v.k = VVOID;
485 if (cc->tostore == LFIELDS_PER_FLUSH) { 485 if (cc->tostore == LFIELDS_PER_FLUSH) {
486 luaK_setlist(fs, cc->t->info, cc->na, cc->tostore); /* flush */ 486 luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */
487 cc->tostore = 0; /* no more items pending */ 487 cc->tostore = 0; /* no more items pending */
488 } 488 }
489} 489}
@@ -493,13 +493,13 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
493 if (cc->tostore == 0) return; 493 if (cc->tostore == 0) return;
494 if (hasmultret(cc->v.k)) { 494 if (hasmultret(cc->v.k)) {
495 luaK_setmultret(fs, &cc->v); 495 luaK_setmultret(fs, &cc->v);
496 luaK_setlist(fs, cc->t->info, cc->na, LUA_MULTRET); 496 luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);
497 cc->na--; /* do not count last expression (unknown number of elements) */ 497 cc->na--; /* do not count last expression (unknown number of elements) */
498 } 498 }
499 else { 499 else {
500 if (cc->v.k != VVOID) 500 if (cc->v.k != VVOID)
501 luaK_exp2nextreg(fs, &cc->v); 501 luaK_exp2nextreg(fs, &cc->v);
502 luaK_setlist(fs, cc->t->info, cc->na, cc->tostore); 502 luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);
503 } 503 }
504} 504}
505 505
@@ -657,7 +657,7 @@ static void funcargs (LexState *ls, expdesc *f) {
657 } 657 }
658 } 658 }
659 lua_assert(f->k == VNONRELOC); 659 lua_assert(f->k == VNONRELOC);
660 base = f->info; /* base register for call */ 660 base = f->u.s.info; /* base register for call */
661 if (hasmultret(args.k)) 661 if (hasmultret(args.k))
662 nparams = LUA_MULTRET; /* open call */ 662 nparams = LUA_MULTRET; /* open call */
663 else { 663 else {
@@ -746,7 +746,8 @@ static void simpleexp (LexState *ls, expdesc *v) {
746 constructor | FUNCTION body | primaryexp */ 746 constructor | FUNCTION body | primaryexp */
747 switch (ls->t.token) { 747 switch (ls->t.token) {
748 case TK_NUMBER: { 748 case TK_NUMBER: {
749 init_exp(v, VK, luaK_numberK(ls->fs, ls->t.seminfo.r)); 749 init_exp(v, VKNUM, 0);
750 v->u.nval = ls->t.seminfo.r;
750 break; 751 break;
751 } 752 }
752 case TK_STRING: { 753 case TK_STRING: {
@@ -805,7 +806,7 @@ static BinOpr getbinopr (int op) {
805 switch (op) { 806 switch (op) {
806 case '+': return OPR_ADD; 807 case '+': return OPR_ADD;
807 case '-': return OPR_SUB; 808 case '-': return OPR_SUB;
808 case '*': return OPR_MULT; 809 case '*': return OPR_MUL;
809 case '/': return OPR_DIV; 810 case '/': return OPR_DIV;
810 case '%': return OPR_MOD; 811 case '%': return OPR_MOD;
811 case '^': return OPR_POW; 812 case '^': return OPR_POW;
@@ -927,18 +928,18 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
927 int conflict = 0; 928 int conflict = 0;
928 for (; lh; lh = lh->prev) { 929 for (; lh; lh = lh->prev) {
929 if (lh->v.k == VINDEXED) { 930 if (lh->v.k == VINDEXED) {
930 if (lh->v.info == v->info) { /* conflict? */ 931 if (lh->v.u.s.info == v->u.s.info) { /* conflict? */
931 conflict = 1; 932 conflict = 1;
932 lh->v.info = extra; /* previous assignment will use safe copy */ 933 lh->v.u.s.info = extra; /* previous assignment will use safe copy */
933 } 934 }
934 if (lh->v.aux == v->info) { /* conflict? */ 935 if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */
935 conflict = 1; 936 conflict = 1;
936 lh->v.aux = extra; /* previous assignment will use safe copy */ 937 lh->v.u.s.aux = extra; /* previous assignment will use safe copy */
937 } 938 }
938 } 939 }
939 } 940 }
940 if (conflict) { 941 if (conflict) {
941 luaK_codeABC(fs, OP_MOVE, fs->freereg, v->info, 0); /* make copy */ 942 luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */
942 luaK_reserveregs(fs, 1); 943 luaK_reserveregs(fs, 1);
943 } 944 }
944} 945}
diff --git a/lparser.h b/lparser.h
index 44729492..35bdaf47 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.54 2005/03/09 16:28:07 roberto Exp roberto $ 2** $Id: lparser.h,v 1.55 2005/04/25 19:24:10 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -23,6 +23,7 @@ typedef enum {
23 VTRUE, 23 VTRUE,
24 VFALSE, 24 VFALSE,
25 VK, /* info = index of constant in `k' */ 25 VK, /* info = index of constant in `k' */
26 VKNUM, /* nval = numerical value */
26 VLOCAL, /* info = local register */ 27 VLOCAL, /* info = local register */
27 VUPVAL, /* info = index of upvalue in `upvalues' */ 28 VUPVAL, /* info = index of upvalue in `upvalues' */
28 VGLOBAL, /* info = index of table; aux = index of global name in `k' */ 29 VGLOBAL, /* info = index of table; aux = index of global name in `k' */
@@ -36,7 +37,10 @@ typedef enum {
36 37
37typedef struct expdesc { 38typedef struct expdesc {
38 expkind k; 39 expkind k;
39 int info, aux; 40 union {
41 struct { int info, aux; } s;
42 lua_Number nval;
43 } u;
40 int t; /* patch list of `exit when true' */ 44 int t; /* patch list of `exit when true' */
41 int f; /* patch list of `exit when false' */ 45 int f; /* patch list of `exit when false' */
42} expdesc; 46} expdesc;