diff options
-rw-r--r-- | lcode.c | 31 | ||||
-rw-r--r-- | lcode.h | 4 | ||||
-rw-r--r-- | lopcodes.c | 4 | ||||
-rw-r--r-- | lopcodes.h | 3 | ||||
-rw-r--r-- | lparser.c | 3 | ||||
-rw-r--r-- | lvm.c | 17 |
6 files changed, 47 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.10 2005/03/08 20:10:05 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.11 2005/03/09 16:28:07 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 | */ |
@@ -603,19 +603,32 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { | |||
603 | 603 | ||
604 | 604 | ||
605 | void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { | 605 | void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { |
606 | if (op == OPR_MINUS) { | 606 | switch (op) { |
607 | luaK_exp2val(fs, e); | 607 | case OPR_MINUS: { |
608 | if (e->k == VK && ttisnumber(&fs->f->k[e->info])) | 608 | luaK_exp2val(fs, e); |
609 | e->info = luaK_numberK(fs, luai_numunm(nvalue(&fs->f->k[e->info]))); | 609 | if (e->k == VK && ttisnumber(&fs->f->k[e->info])) |
610 | else { | 610 | e->info = luaK_numberK(fs, luai_numunm(nvalue(&fs->f->k[e->info]))); |
611 | else { | ||
612 | luaK_exp2anyreg(fs, e); | ||
613 | freeexp(fs, e); | ||
614 | e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0); | ||
615 | e->k = VRELOCABLE; | ||
616 | } | ||
617 | break; | ||
618 | } | ||
619 | case OPR_NOT: { | ||
620 | codenot(fs, e); | ||
621 | break; | ||
622 | } | ||
623 | case OPR_SIZE: { | ||
611 | luaK_exp2anyreg(fs, e); | 624 | luaK_exp2anyreg(fs, e); |
612 | freeexp(fs, e); | 625 | freeexp(fs, e); |
613 | e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0); | 626 | e->info = luaK_codeABC(fs, OP_SIZ, 0, e->info, 0); |
614 | e->k = VRELOCABLE; | 627 | e->k = VRELOCABLE; |
628 | break; | ||
615 | } | 629 | } |
630 | default: lua_assert(0); | ||
616 | } | 631 | } |
617 | else /* op == NOT */ | ||
618 | codenot(fs, e); | ||
619 | } | 632 | } |
620 | 633 | ||
621 | 634 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.h,v 1.40 2004/10/04 19:01:53 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.41 2005/03/08 18:00:16 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 | */ |
@@ -34,7 +34,7 @@ typedef enum BinOpr { | |||
34 | 34 | ||
35 | #define binopistest(op) ((op) >= OPR_NE) | 35 | #define binopistest(op) ((op) >= OPR_NE) |
36 | 36 | ||
37 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; | 37 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_SIZE, 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)->info]) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.c,v 1.30 2004/12/02 12:59:10 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.31 2005/03/08 18:00:16 roberto Exp roberto $ |
3 | ** See Copyright Notice in lua.h | 3 | ** See Copyright Notice in lua.h |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -36,6 +36,7 @@ const char *const luaP_opnames[NUM_OPCODES+1] = { | |||
36 | "POW", | 36 | "POW", |
37 | "UNM", | 37 | "UNM", |
38 | "NOT", | 38 | "NOT", |
39 | "SIZ", | ||
39 | "CONCAT", | 40 | "CONCAT", |
40 | "JMP", | 41 | "JMP", |
41 | "EQ", | 42 | "EQ", |
@@ -81,6 +82,7 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
81 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ | 82 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ |
82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ | 83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ |
83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ | 84 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ |
85 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_SIZ */ | ||
84 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ | 86 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ |
85 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ | 87 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ |
86 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ | 88 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.116 2005/03/08 20:10:05 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.117 2005/03/09 16:28:07 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 | */ |
@@ -176,6 +176,7 @@ OP_MOD,/* A B C R(A) := RK(B) % RK(C) */ | |||
176 | OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ | 176 | OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ |
177 | OP_UNM,/* A B R(A) := -R(B) */ | 177 | OP_UNM,/* A B R(A) := -R(B) */ |
178 | OP_NOT,/* A B R(A) := not R(B) */ | 178 | OP_NOT,/* A B R(A) := not R(B) */ |
179 | OP_SIZ,/* A B R(A) := size of R(B) */ | ||
179 | 180 | ||
180 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ | 181 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ |
181 | 182 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.17 2005/03/08 20:10:05 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.18 2005/03/09 16:28:07 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 | */ |
@@ -788,6 +788,7 @@ static UnOpr getunopr (int op) { | |||
788 | switch (op) { | 788 | switch (op) { |
789 | case TK_NOT: return OPR_NOT; | 789 | case TK_NOT: return OPR_NOT; |
790 | case '-': return OPR_MINUS; | 790 | case '-': return OPR_MINUS; |
791 | case '*': return OPR_SIZE; | ||
791 | default: return OPR_NOUNOPR; | 792 | default: return OPR_NOUNOPR; |
792 | } | 793 | } |
793 | } | 794 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.31 2005/03/08 20:10:05 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.32 2005/03/09 16:28: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 | */ |
@@ -562,6 +562,21 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
562 | setbvalue(ra, res); | 562 | setbvalue(ra, res); |
563 | continue; | 563 | continue; |
564 | } | 564 | } |
565 | case OP_SIZ: { | ||
566 | const TValue *rb = RB(i); | ||
567 | switch (ttype(rb)) { | ||
568 | case LUA_TTABLE: | ||
569 | setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb)))); | ||
570 | break; | ||
571 | case LUA_TSTRING: | ||
572 | setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); | ||
573 | break; | ||
574 | default: /* no metamethod?? */ | ||
575 | L->ci->savedpc = pc; | ||
576 | luaG_typeerror(L, rb, "get the size of"); | ||
577 | } | ||
578 | continue; | ||
579 | } | ||
565 | case OP_CONCAT: { | 580 | case OP_CONCAT: { |
566 | int b = GETARG_B(i); | 581 | int b = GETARG_B(i); |
567 | int c = GETARG_C(i); | 582 | int c = GETARG_C(i); |