aboutsummaryrefslogtreecommitdiff
path: root/opcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-03-20 16:20:43 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-03-20 16:20:43 -0300
commit5d60470508aad81eac145ab4e004fbf150130267 (patch)
treee019d25234bccc195614a7303520db0b86aca2ed /opcode.c
parent88d7ffb0d0c7303ef1b766b1100e4220e775ab57 (diff)
downloadlua-5d60470508aad81eac145ab4e004fbf150130267.tar.gz
lua-5d60470508aad81eac145ab4e004fbf150130267.tar.bz2
lua-5d60470508aad81eac145ab4e004fbf150130267.zip
i.m. "arith" and "order" splited for different operations
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/opcode.c b/opcode.c
index b20901d9..31ecdf85 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.84 1997/03/11 18:44:28 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.85 1997/03/19 19:41:10 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -1006,18 +1006,18 @@ void luaI_gcIM (Object *o)
1006} 1006}
1007 1007
1008 1008
1009static void call_arith (char *op) 1009static void call_arith (IMS event)
1010{ 1010{
1011 Object *im = luaI_getimbyObj(top-2, IM_ARITH); /* try first operand */ 1011 Object *im = luaI_getimbyObj(top-2, event); /* try first operand */
1012 if (ttype(im) == LUA_T_NIL) { 1012 if (ttype(im) == LUA_T_NIL) {
1013 im = luaI_getimbyObj(top-1, IM_ARITH); /* try second operand */ 1013 im = luaI_getimbyObj(top-1, event); /* try second operand */
1014 if (ttype(im) == LUA_T_NIL) { 1014 if (ttype(im) == LUA_T_NIL) {
1015 im = luaI_getim(0, IM_ARITH); /* try a 'global' i.m. */ 1015 im = luaI_getim(0, event); /* try a 'global' i.m. */
1016 if (ttype(im) == LUA_T_NIL) 1016 if (ttype(im) == LUA_T_NIL)
1017 lua_error("unexpected type at conversion to number"); 1017 lua_error("unexpected type at conversion to number");
1018 } 1018 }
1019 } 1019 }
1020 lua_pushstring(op); 1020 lua_pushstring(luaI_eventname[event]);
1021 callIM(im, 3, 1); 1021 callIM(im, 3, 1);
1022} 1022}
1023 1023
@@ -1029,17 +1029,17 @@ static void concim (Object *o)
1029 callIM(im, 2, 1); 1029 callIM(im, 2, 1);
1030} 1030}
1031 1031
1032static void ordim (Object *o, char *op) 1032static void ordim (Object *o, IMS event)
1033{ 1033{
1034 Object *im = luaI_getimbyObj(o, IM_ORDER); 1034 Object *im = luaI_getimbyObj(o, event);
1035 if (ttype(im) == LUA_T_NIL) 1035 if (ttype(im) == LUA_T_NIL)
1036 lua_error("unexpected type at comparison"); 1036 lua_error("unexpected type at comparison");
1037 lua_pushstring(op); 1037 lua_pushstring(luaI_eventname[event]);
1038 callIM(im, 3, 1); 1038 callIM(im, 3, 1);
1039} 1039}
1040 1040
1041static void comparison (lua_Type ttype_less, lua_Type ttype_equal, 1041static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
1042 lua_Type ttype_great, char *op) 1042 lua_Type ttype_great, IMS op)
1043{ 1043{
1044 Object *l = top-2; 1044 Object *l = top-2;
1045 Object *r = top-1; 1045 Object *r = top-1;
@@ -1292,19 +1292,19 @@ static StkId lua_execute (Byte *pc, StkId base)
1292 break; 1292 break;
1293 1293
1294 case LTOP: 1294 case LTOP:
1295 comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, "lt"); 1295 comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT);
1296 break; 1296 break;
1297 1297
1298 case LEOP: 1298 case LEOP:
1299 comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, "le"); 1299 comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE);
1300 break; 1300 break;
1301 1301
1302 case GTOP: 1302 case GTOP:
1303 comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, "gt"); 1303 comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT);
1304 break; 1304 break;
1305 1305
1306 case GEOP: 1306 case GEOP:
1307 comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, "ge"); 1307 comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE);
1308 break; 1308 break;
1309 1309
1310 case ADDOP: 1310 case ADDOP:
@@ -1312,7 +1312,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1312 Object *l = top-2; 1312 Object *l = top-2;
1313 Object *r = top-1; 1313 Object *r = top-1;
1314 if (tonumber(r) || tonumber(l)) 1314 if (tonumber(r) || tonumber(l))
1315 call_arith("add"); 1315 call_arith(IM_ADD);
1316 else 1316 else
1317 { 1317 {
1318 nvalue(l) += nvalue(r); 1318 nvalue(l) += nvalue(r);
@@ -1326,7 +1326,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1326 Object *l = top-2; 1326 Object *l = top-2;
1327 Object *r = top-1; 1327 Object *r = top-1;
1328 if (tonumber(r) || tonumber(l)) 1328 if (tonumber(r) || tonumber(l))
1329 call_arith("sub"); 1329 call_arith(IM_SUB);
1330 else 1330 else
1331 { 1331 {
1332 nvalue(l) -= nvalue(r); 1332 nvalue(l) -= nvalue(r);
@@ -1340,7 +1340,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1340 Object *l = top-2; 1340 Object *l = top-2;
1341 Object *r = top-1; 1341 Object *r = top-1;
1342 if (tonumber(r) || tonumber(l)) 1342 if (tonumber(r) || tonumber(l))
1343 call_arith("mul"); 1343 call_arith(IM_MUL);
1344 else 1344 else
1345 { 1345 {
1346 nvalue(l) *= nvalue(r); 1346 nvalue(l) *= nvalue(r);
@@ -1354,7 +1354,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1354 Object *l = top-2; 1354 Object *l = top-2;
1355 Object *r = top-1; 1355 Object *r = top-1;
1356 if (tonumber(r) || tonumber(l)) 1356 if (tonumber(r) || tonumber(l))
1357 call_arith("div"); 1357 call_arith(IM_DIV);
1358 else 1358 else
1359 { 1359 {
1360 nvalue(l) /= nvalue(r); 1360 nvalue(l) /= nvalue(r);
@@ -1364,7 +1364,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1364 break; 1364 break;
1365 1365
1366 case POWOP: 1366 case POWOP:
1367 call_arith("pow"); 1367 call_arith(IM_POW);
1368 break; 1368 break;
1369 1369
1370 case CONCOP: { 1370 case CONCOP: {
@@ -1386,7 +1386,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1386 { 1386 {
1387 ttype(top) = LUA_T_NIL; 1387 ttype(top) = LUA_T_NIL;
1388 incr_top; 1388 incr_top;
1389 call_arith("unm"); 1389 call_arith(IM_UNM);
1390 } 1390 }
1391 else 1391 else
1392 nvalue(top-1) = - nvalue(top-1); 1392 nvalue(top-1) = - nvalue(top-1);