aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-04-26 10:08:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-04-26 10:08:29 -0300
commita2f5c28a802ae99f2045ab96585fade2c65b2037 (patch)
treeeb2ab3d1fc8dc2084505ed4286502ed75b6721ba /lvm.c
parenta80a2b5e561b50c1f64e96c3692614611a325aba (diff)
downloadlua-a2f5c28a802ae99f2045ab96585fade2c65b2037.tar.gz
lua-a2f5c28a802ae99f2045ab96585fade2c65b2037.tar.bz2
lua-a2f5c28a802ae99f2045ab96585fade2c65b2037.zip
new operation '//' (integer division)
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/lvm.c b/lvm.c
index e129438d..d772590d 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.161 2013/04/25 19:12:41 roberto Exp roberto $ 2** $Id: lvm.c,v 2.162 2013/04/25 19:50:02 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*/
@@ -404,7 +404,7 @@ void luaV_finishOp (lua_State *L) {
404 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ 404 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
405 OpCode op = GET_OPCODE(inst); 405 OpCode op = GET_OPCODE(inst);
406 switch (op) { /* finish its execution */ 406 switch (op) { /* finish its execution */
407 case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: 407 case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_IDIV:
408 case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: 408 case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN:
409 case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: { 409 case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
410 setobjs2s(L, base + GETARG_A(inst), --L->top); 410 setobjs2s(L, base + GETARG_A(inst), --L->top);
@@ -640,6 +640,19 @@ void luaV_execute (lua_State *L) {
640 } 640 }
641 else { Protect(luaV_arith(L, ra, rb, rc, TM_DIV)); } 641 else { Protect(luaV_arith(L, ra, rb, rc, TM_DIV)); }
642 ) 642 )
643 vmcase(OP_IDIV, /* integer division */
644 TValue *rb = RKB(i);
645 TValue *rc = RKC(i);
646 if (ttisinteger(rb) && ttisinteger(rc)) {
647 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
648 setivalue(ra, luaV_div(L, ib, ic));
649 }
650 else if (ttisnumber(rb) && ttisnumber(rc)) {
651 lua_Number nb = nvalue(rb); lua_Number nc = nvalue(rc);
652 setnvalue(ra, luai_numidiv(L, nb, nc));
653 }
654 else { Protect(luaV_arith(L, ra, rb, rc, TM_IDIV)); }
655 )
643 vmcase(OP_MOD, 656 vmcase(OP_MOD,
644 TValue *rb = RKB(i); 657 TValue *rb = RKB(i);
645 TValue *rc = RKC(i); 658 TValue *rc = RKC(i);