diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-22 13:37:17 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-22 13:37:17 -0300 |
| commit | 23e6bac8a0bbb9e5df43cbc0b7634b6d1395b0ff (patch) | |
| tree | b8f01be3b195252ecb414092dce98299fc325a54 /testes | |
| parent | 682054920ddc434fd4a7f8cc78027dbb03f47f00 (diff) | |
| download | lua-23e6bac8a0bbb9e5df43cbc0b7634b6d1395b0ff.tar.gz lua-23e6bac8a0bbb9e5df43cbc0b7634b6d1395b0ff.tar.bz2 lua-23e6bac8a0bbb9e5df43cbc0b7634b6d1395b0ff.zip | |
Keep correct type for immediate operands in comparisons
When calling metamethods for things like 'a < 3.0', which generates
the opcode OP_LTI, the C register tells that the operand was
converted to an integer, so that it can be corrected to float when
calling a metamethod.
This commit also includes some other stuff:
- file 'onelua.c' added to the project
- opcode OP_PREPVARARG renamed to OP_VARARGPREP
- comparison opcodes rewritten through macros
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/db.lua | 2 | ||||
| -rw-r--r-- | testes/events.lua | 99 |
2 files changed, 46 insertions, 55 deletions
diff --git a/testes/db.lua b/testes/db.lua index 0858dd20..95275fb4 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
| @@ -162,7 +162,7 @@ test([[for i,v in pairs{'a','b'} do | |||
| 162 | end | 162 | end |
| 163 | ]], {1,2,1,2,1,3}) | 163 | ]], {1,2,1,2,1,3}) |
| 164 | 164 | ||
| 165 | test([[for i=1,4 do a=1 end]], {1,1,1,1}, true) | 165 | test([[for i=1,4 do a=1 end]], {1,1,1,1}) |
| 166 | 166 | ||
| 167 | 167 | ||
| 168 | do -- testing line info/trace with large gaps in source | 168 | do -- testing line info/trace with large gaps in source |
diff --git a/testes/events.lua b/testes/events.lua index ac630d89..cf68d1e9 100644 --- a/testes/events.lua +++ b/testes/events.lua | |||
| @@ -138,64 +138,55 @@ t.__bxor = f("bxor") | |||
| 138 | t.__shl = f("shl") | 138 | t.__shl = f("shl") |
| 139 | t.__shr = f("shr") | 139 | t.__shr = f("shr") |
| 140 | t.__bnot = f("bnot") | 140 | t.__bnot = f("bnot") |
| 141 | t.__lt = f("lt") | ||
| 142 | t.__le = f("le") | ||
| 143 | |||
| 144 | |||
| 145 | local function checkcap (t) | ||
| 146 | assert(#cap + 1 == #t) | ||
| 147 | for i = 1, #t do | ||
| 148 | assert(cap[i - 1] == t[i]) | ||
| 149 | assert(math.type(cap[i - 1]) == math.type(t[i])) | ||
| 150 | end | ||
| 151 | end | ||
| 141 | 152 | ||
| 142 | -- Some tests are done inside small anonymous functions to ensure | 153 | -- Some tests are done inside small anonymous functions to ensure |
| 143 | -- that constants go to constant table even in debug compilation, | 154 | -- that constants go to constant table even in debug compilation, |
| 144 | -- when the constant table is very small. | 155 | -- when the constant table is very small. |
| 145 | assert(b+5 == b) | 156 | assert(b+5 == b); checkcap{"add", b, 5} |
| 146 | assert(cap[0] == "add" and cap[1] == b and cap[2] == 5 and cap[3]==undef) | 157 | assert(5.2 + b == 5.2); checkcap{"add", 5.2, b} |
| 147 | assert(5.2 + b == 5.2) | 158 | assert(b+'5' == b); checkcap{"add", b, '5'} |
| 148 | assert(cap[0] == "add" and cap[1] == 5.2 and cap[2] == b and cap[3]==undef) | 159 | assert(5+b == 5); checkcap{"add", 5, b} |
| 149 | assert(b+'5' == b) | 160 | assert('5'+b == '5'); checkcap{"add", '5', b} |
| 150 | assert(cap[0] == "add" and cap[1] == b and cap[2] == '5' and cap[3]==undef) | 161 | b=b-3; assert(getmetatable(b) == t); checkcap{"sub", b, 3} |
| 151 | assert(5+b == 5) | 162 | assert(5-a == 5); checkcap{"sub", 5, a} |
| 152 | assert(cap[0] == "add" and cap[1] == 5 and cap[2] == b and cap[3]==undef) | 163 | assert('5'-a == '5'); checkcap{"sub", '5', a} |
| 153 | assert('5'+b == '5') | 164 | assert(a*a == a); checkcap{"mul", a, a} |
| 154 | assert(cap[0] == "add" and cap[1] == '5' and cap[2] == b and cap[3]==undef) | 165 | assert(a/0 == a); checkcap{"div", a, 0} |
| 155 | b=b-3; assert(getmetatable(b) == t) | 166 | assert(a/0.0 == a); checkcap{"div", a, 0.0} |
| 156 | assert(cap[0] == "sub" and cap[1] == b and cap[2] == 3 and cap[3]==undef) | 167 | assert(a%2 == a); checkcap{"mod", a, 2} |
| 157 | assert(5-a == 5) | 168 | assert(a // (1/0) == a); checkcap{"idiv", a, 1/0} |
| 158 | assert(cap[0] == "sub" and cap[1] == 5 and cap[2] == a and cap[3]==undef) | 169 | ;(function () assert(a & "hi" == a) end)(); checkcap{"band", a, "hi"} |
| 159 | assert('5'-a == '5') | 170 | ;(function () assert(10 & a == 10) end)(); checkcap{"band", 10, a} |
| 160 | assert(cap[0] == "sub" and cap[1] == '5' and cap[2] == a and cap[3]==undef) | 171 | ;(function () assert(a | 10 == a) end)(); checkcap{"bor", a, 10} |
| 161 | assert(a*a == a) | 172 | assert(a | "hi" == a); checkcap{"bor", a, "hi"} |
| 162 | assert(cap[0] == "mul" and cap[1] == a and cap[2] == a and cap[3]==undef) | 173 | assert("hi" ~ a == "hi"); checkcap{"bxor", "hi", a} |
| 163 | assert(a/0 == a) | 174 | ;(function () assert(10 ~ a == 10) end)(); checkcap{"bxor", 10, a} |
| 164 | assert(cap[0] == "div" and cap[1] == a and cap[2] == 0 and cap[3]==undef) | 175 | assert(-a == a); checkcap{"unm", a, a} |
| 165 | assert(a%2 == a) | 176 | assert(a^4.0 == a); checkcap{"pow", a, 4.0} |
| 166 | assert(cap[0] == "mod" and cap[1] == a and cap[2] == 2 and cap[3]==undef) | 177 | assert(a^'4' == a); checkcap{"pow", a, '4'} |
| 167 | assert(a // (1/0) == a) | 178 | assert(4^a == 4); checkcap{"pow", 4, a} |
| 168 | assert(cap[0] == "idiv" and cap[1] == a and cap[2] == 1/0 and cap[3]==undef) | 179 | assert('4'^a == '4'); checkcap{"pow", '4', a} |
| 169 | ;(function () assert(a & "hi" == a) end)() | 180 | assert(#a == a); checkcap{"len", a, a} |
| 170 | assert(cap[0] == "band" and cap[1] == a and cap[2] == "hi" and cap[3]==undef) | 181 | assert(~a == a); checkcap{"bnot", a, a} |
| 171 | ;(function () assert(10 & a == 10) end)() | 182 | assert(a << 3 == a); checkcap{"shl", a, 3} |
| 172 | assert(cap[0] == "band" and cap[1] == 10 and cap[2] == a and cap[3]==undef) | 183 | assert(1.5 >> a == 1.5); checkcap{"shr", 1.5, a} |
| 173 | ;(function () assert(a | 10 == a) end)() | 184 | |
| 174 | assert(cap[0] == "bor" and cap[1] == a and cap[2] == 10 and cap[3]==undef) | 185 | -- for comparsion operators, all results are true |
| 175 | assert(a | "hi" == a) | 186 | assert(5.0 > a); checkcap{"lt", a, 5.0} |
| 176 | assert(cap[0] == "bor" and cap[1] == a and cap[2] == "hi" and cap[3]==undef) | 187 | assert(a >= 10); checkcap{"le", 10, a} |
| 177 | assert("hi" ~ a == "hi") | 188 | assert(a <= -10.0); checkcap{"le", a, -10.0} |
| 178 | assert(cap[0] == "bxor" and cap[1] == "hi" and cap[2] == a and cap[3]==undef) | 189 | assert(a < -10); checkcap{"lt", a, -10} |
| 179 | ;(function () assert(10 ~ a == 10) end)() | ||
| 180 | assert(cap[0] == "bxor" and cap[1] == 10 and cap[2] == a and cap[3]==undef) | ||
| 181 | assert(-a == a) | ||
| 182 | assert(cap[0] == "unm" and cap[1] == a) | ||
| 183 | assert(a^4 == a) | ||
| 184 | assert(cap[0] == "pow" and cap[1] == a and cap[2] == 4 and cap[3]==undef) | ||
| 185 | assert(a^'4' == a) | ||
| 186 | assert(cap[0] == "pow" and cap[1] == a and cap[2] == '4' and cap[3]==undef) | ||
| 187 | assert(4^a == 4) | ||
| 188 | assert(cap[0] == "pow" and cap[1] == 4 and cap[2] == a and cap[3]==undef) | ||
| 189 | assert('4'^a == '4') | ||
| 190 | assert(cap[0] == "pow" and cap[1] == '4' and cap[2] == a and cap[3]==undef) | ||
| 191 | assert(#a == a) | ||
| 192 | assert(cap[0] == "len" and cap[1] == a) | ||
| 193 | assert(~a == a) | ||
| 194 | assert(cap[0] == "bnot" and cap[1] == a) | ||
| 195 | assert(a << 3 == a) | ||
| 196 | assert(cap[0] == "shl" and cap[1] == a and cap[2] == 3) | ||
| 197 | assert(1.5 >> a == 1.5) | ||
| 198 | assert(cap[0] == "shr" and cap[1] == 1.5 and cap[2] == a) | ||
| 199 | 190 | ||
| 200 | 191 | ||
| 201 | -- test for rawlen | 192 | -- test for rawlen |
