diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-16 15:42:32 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-16 15:42:32 -0300 |
| commit | e4b69d6c9cb92658e39e5ae5cd85e01fcc8f6408 (patch) | |
| tree | 78a1a8ca7e12f51a142ba7a1e5ea7ee39bb6cb69 | |
| parent | c9a2dfeb2c71b1c6b8164a1e5aad4b178950e197 (diff) | |
| download | lua-e4b69d6c9cb92658e39e5ae5cd85e01fcc8f6408.tar.gz lua-e4b69d6c9cb92658e39e5ae5cd85e01fcc8f6408.tar.bz2 lua-e4b69d6c9cb92658e39e5ae5cd85e01fcc8f6408.zip | |
"order" and "concat" operations choose tag methods the same way that
"arith" operations do (first the first parameter, etc).
| -rw-r--r-- | opcode.c | 44 |
1 files changed, 13 insertions, 31 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_opcode="$Id: opcode.c,v 4.8 1997/06/12 18:27:29 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 4.9 1997/06/16 16:50:22 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -466,9 +466,7 @@ void lua_travstack (int (*fn)(TObject *)) | |||
| 466 | static void lua_message (char *s) | 466 | static void lua_message (char *s) |
| 467 | { | 467 | { |
| 468 | TObject *im = luaI_geterrorim(); | 468 | TObject *im = luaI_geterrorim(); |
| 469 | if (ttype(im) == LUA_T_NIL) | 469 | if (ttype(im) != LUA_T_NIL) { |
| 470 | fprintf(stderr, "lua: %s\n", s); | ||
| 471 | else { | ||
| 472 | lua_pushstring(s); | 470 | lua_pushstring(s); |
| 473 | callIM(im, 1, 0); | 471 | callIM(im, 1, 0); |
| 474 | } | 472 | } |
| @@ -1008,7 +1006,7 @@ void luaI_gcIM (TObject *o) | |||
| 1008 | } | 1006 | } |
| 1009 | 1007 | ||
| 1010 | 1008 | ||
| 1011 | static void call_arith (IMS event) | 1009 | static void call_binTM (IMS event, char *msg) |
| 1012 | { | 1010 | { |
| 1013 | TObject *im = luaI_getimbyObj(top-2, event); /* try first operand */ | 1011 | TObject *im = luaI_getimbyObj(top-2, event); /* try first operand */ |
| 1014 | if (ttype(im) == LUA_T_NIL) { | 1012 | if (ttype(im) == LUA_T_NIL) { |
| @@ -1016,30 +1014,20 @@ static void call_arith (IMS event) | |||
| 1016 | if (ttype(im) == LUA_T_NIL) { | 1014 | if (ttype(im) == LUA_T_NIL) { |
| 1017 | im = luaI_getim(0, event); /* try a 'global' i.m. */ | 1015 | im = luaI_getim(0, event); /* try a 'global' i.m. */ |
| 1018 | if (ttype(im) == LUA_T_NIL) | 1016 | if (ttype(im) == LUA_T_NIL) |
| 1019 | lua_error("unexpected type at arithmetic operation"); | 1017 | lua_error(msg); |
| 1020 | } | 1018 | } |
| 1021 | } | 1019 | } |
| 1022 | lua_pushstring(luaI_eventname[event]); | 1020 | lua_pushstring(luaI_eventname[event]); |
| 1023 | callIM(im, 3, 1); | 1021 | callIM(im, 3, 1); |
| 1024 | } | 1022 | } |
| 1025 | 1023 | ||
| 1026 | static void concim (TObject *o) | ||
| 1027 | { | ||
| 1028 | TObject *im = luaI_getimbyObj(o, IM_CONCAT); | ||
| 1029 | if (ttype(im) == LUA_T_NIL) | ||
| 1030 | lua_error("unexpected type at conversion to string"); | ||
| 1031 | callIM(im, 2, 1); | ||
| 1032 | } | ||
| 1033 | 1024 | ||
| 1034 | static void ordim (TObject *o, IMS event) | 1025 | static void call_arith (IMS event) |
| 1035 | { | 1026 | { |
| 1036 | TObject *im = luaI_getimbyObj(o, event); | 1027 | call_binTM(event, "unexpected type at arithmetic operation"); |
| 1037 | if (ttype(im) == LUA_T_NIL) | ||
| 1038 | lua_error("unexpected type at comparison"); | ||
| 1039 | lua_pushstring(luaI_eventname[event]); | ||
| 1040 | callIM(im, 3, 1); | ||
| 1041 | } | 1028 | } |
| 1042 | 1029 | ||
| 1030 | |||
| 1043 | static void comparison (lua_Type ttype_less, lua_Type ttype_equal, | 1031 | static void comparison (lua_Type ttype_less, lua_Type ttype_equal, |
| 1044 | lua_Type ttype_great, IMS op) | 1032 | lua_Type ttype_great, IMS op) |
| 1045 | { | 1033 | { |
| @@ -1048,16 +1036,12 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal, | |||
| 1048 | int result; | 1036 | int result; |
| 1049 | if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) | 1037 | if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) |
| 1050 | result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; | 1038 | result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; |
| 1051 | else if (tostring(l)) { | 1039 | else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) |
| 1052 | ordim(l, op); | 1040 | result = strcmp(svalue(l), svalue(r)); |
| 1053 | return; | 1041 | else { |
| 1054 | } | 1042 | call_binTM(op, "unexpected type at comparison"); |
| 1055 | else if (tostring(r)) { | ||
| 1056 | ordim(r, op); | ||
| 1057 | return; | 1043 | return; |
| 1058 | } | 1044 | } |
| 1059 | else | ||
| 1060 | result = strcmp(svalue(l), svalue(r)); | ||
| 1061 | top--; | 1045 | top--; |
| 1062 | nvalue(top-1) = 1; | 1046 | nvalue(top-1) = 1; |
| 1063 | ttype(top-1) = (result < 0) ? ttype_less : | 1047 | ttype(top-1) = (result < 0) ? ttype_less : |
| @@ -1372,10 +1356,8 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
| 1372 | case CONCOP: { | 1356 | case CONCOP: { |
| 1373 | TObject *l = top-2; | 1357 | TObject *l = top-2; |
| 1374 | TObject *r = top-1; | 1358 | TObject *r = top-1; |
| 1375 | if (tostring(l)) /* first argument is not a string */ | 1359 | if (tostring(l) || tostring(r)) |
| 1376 | concim(l); | 1360 | call_binTM(IM_CONCAT, "unexpected type for concatenation"); |
| 1377 | else if (tostring(r)) /* second argument is not a string */ | ||
| 1378 | concim(r); | ||
| 1379 | else { | 1361 | else { |
| 1380 | tsvalue(l) = lua_createstring(lua_strconc(svalue(l),svalue(r))); | 1362 | tsvalue(l) = lua_createstring(lua_strconc(svalue(l),svalue(r))); |
| 1381 | --top; | 1363 | --top; |
