summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lcode.c31
-rw-r--r--lcode.h4
-rw-r--r--lopcodes.c4
-rw-r--r--lopcodes.h3
-rw-r--r--lparser.c3
-rw-r--r--lvm.c17
6 files changed, 47 insertions, 15 deletions
diff --git a/lcode.c b/lcode.c
index 0fa0fdb0..14db070b 100644
--- a/lcode.c
+++ b/lcode.c
@@ -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
605void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { 605void 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
diff --git a/lcode.h b/lcode.h
index cafc6fde..c1fae300 100644
--- a/lcode.h
+++ b/lcode.h
@@ -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
37typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; 37typedef 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])
diff --git a/lopcodes.c b/lopcodes.c
index 3f6b4e78..16be5a56 100644
--- a/lopcodes.c
+++ b/lopcodes.c
@@ -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 */
diff --git a/lopcodes.h b/lopcodes.h
index 16d26d41..84880fc9 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -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) */
176OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ 176OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */
177OP_UNM,/* A B R(A) := -R(B) */ 177OP_UNM,/* A B R(A) := -R(B) */
178OP_NOT,/* A B R(A) := not R(B) */ 178OP_NOT,/* A B R(A) := not R(B) */
179OP_SIZ,/* A B R(A) := size of R(B) */
179 180
180OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ 181OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
181 182
diff --git a/lparser.c b/lparser.c
index a26f22f5..4355f5fc 100644
--- a/lparser.c
+++ b/lparser.c
@@ -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}
diff --git a/lvm.c b/lvm.c
index 54e631f7..d7d36c81 100644
--- a/lvm.c
+++ b/lvm.c
@@ -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);