diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-12-30 18:47:58 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-12-30 18:47:58 -0200 |
| commit | 1ea2d20f74cea9c61817d4a5ed67c4fc47cafb51 (patch) | |
| tree | bdedb3205963f8db43391aaef5be853cdeb59df4 /lobject.c | |
| parent | f5133aa1a55cee96b535ff788764437deacdc26a (diff) | |
| download | lua-1ea2d20f74cea9c61817d4a5ed67c4fc47cafb51.tar.gz lua-1ea2d20f74cea9c61817d4a5ed67c4fc47cafb51.tar.bz2 lua-1ea2d20f74cea9c61817d4a5ed67c4fc47cafb51.zip | |
first implementation of '<<', '>>', and '~' (bitwise not)
Diffstat (limited to 'lobject.c')
| -rw-r--r-- | lobject.c | 8 |
1 files changed, 6 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.69 2013/12/16 14:30:22 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.70 2013/12/18 14:12:03 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -82,7 +82,10 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1, | |||
| 82 | case LUA_OPBAND: return intop(&, v1, v2); | 82 | case LUA_OPBAND: return intop(&, v1, v2); |
| 83 | case LUA_OPBOR: return intop(|, v1, v2); | 83 | case LUA_OPBOR: return intop(|, v1, v2); |
| 84 | case LUA_OPBXOR: return intop(^, v1, v2); | 84 | case LUA_OPBXOR: return intop(^, v1, v2); |
| 85 | case LUA_OPSHL: return luaV_shiftl(v1, v2); | ||
| 86 | case LUA_OPSHR: return luaV_shiftl(v1, -v2); | ||
| 85 | case LUA_OPUNM: return intop(-, 0, v1); | 87 | case LUA_OPUNM: return intop(-, 0, v1); |
| 88 | case LUA_OPBNOT: return intop(^, cast_integer(-1), v1); | ||
| 86 | default: lua_assert(0); return 0; | 89 | default: lua_assert(0); return 0; |
| 87 | } | 90 | } |
| 88 | } | 91 | } |
| @@ -106,7 +109,8 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, | |||
| 106 | TValue *res) { | 109 | TValue *res) { |
| 107 | switch (op) { | 110 | switch (op) { |
| 108 | case LUA_OPIDIV: case LUA_OPBAND: case LUA_OPBOR: | 111 | case LUA_OPIDIV: case LUA_OPBAND: case LUA_OPBOR: |
| 109 | case LUA_OPBXOR: { /* operates only on integers */ | 112 | case LUA_OPBXOR: case LUA_OPSHL: case LUA_OPSHR: |
| 113 | case LUA_OPBNOT: { /* operates only on integers */ | ||
| 110 | lua_Integer i1; lua_Integer i2; | 114 | lua_Integer i1; lua_Integer i2; |
| 111 | if (tointeger(p1, &i1) && tointeger(p2, &i2)) { | 115 | if (tointeger(p1, &i1) && tointeger(p2, &i2)) { |
| 112 | setivalue(res, intarith(L, op, i1, i2)); | 116 | setivalue(res, intarith(L, op, i1, i2)); |
