aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-03-22 13:37:17 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-03-22 13:37:17 -0300
commit23e6bac8a0bbb9e5df43cbc0b7634b6d1395b0ff (patch)
treeb8f01be3b195252ecb414092dce98299fc325a54 /testes
parent682054920ddc434fd4a7f8cc78027dbb03f47f00 (diff)
downloadlua-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.lua2
-rw-r--r--testes/events.lua99
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
162end 162end
163]], {1,2,1,2,1,3}) 163]], {1,2,1,2,1,3})
164 164
165test([[for i=1,4 do a=1 end]], {1,1,1,1}, true) 165test([[for i=1,4 do a=1 end]], {1,1,1,1})
166 166
167 167
168do -- testing line info/trace with large gaps in source 168do -- 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")
138t.__shl = f("shl") 138t.__shl = f("shl")
139t.__shr = f("shr") 139t.__shr = f("shr")
140t.__bnot = f("bnot") 140t.__bnot = f("bnot")
141t.__lt = f("lt")
142t.__le = f("le")
143
144
145local 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
151end
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.
145assert(b+5 == b) 156assert(b+5 == b); checkcap{"add", b, 5}
146assert(cap[0] == "add" and cap[1] == b and cap[2] == 5 and cap[3]==undef) 157assert(5.2 + b == 5.2); checkcap{"add", 5.2, b}
147assert(5.2 + b == 5.2) 158assert(b+'5' == b); checkcap{"add", b, '5'}
148assert(cap[0] == "add" and cap[1] == 5.2 and cap[2] == b and cap[3]==undef) 159assert(5+b == 5); checkcap{"add", 5, b}
149assert(b+'5' == b) 160assert('5'+b == '5'); checkcap{"add", '5', b}
150assert(cap[0] == "add" and cap[1] == b and cap[2] == '5' and cap[3]==undef) 161b=b-3; assert(getmetatable(b) == t); checkcap{"sub", b, 3}
151assert(5+b == 5) 162assert(5-a == 5); checkcap{"sub", 5, a}
152assert(cap[0] == "add" and cap[1] == 5 and cap[2] == b and cap[3]==undef) 163assert('5'-a == '5'); checkcap{"sub", '5', a}
153assert('5'+b == '5') 164assert(a*a == a); checkcap{"mul", a, a}
154assert(cap[0] == "add" and cap[1] == '5' and cap[2] == b and cap[3]==undef) 165assert(a/0 == a); checkcap{"div", a, 0}
155b=b-3; assert(getmetatable(b) == t) 166assert(a/0.0 == a); checkcap{"div", a, 0.0}
156assert(cap[0] == "sub" and cap[1] == b and cap[2] == 3 and cap[3]==undef) 167assert(a%2 == a); checkcap{"mod", a, 2}
157assert(5-a == 5) 168assert(a // (1/0) == a); checkcap{"idiv", a, 1/0}
158assert(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"}
159assert('5'-a == '5') 170;(function () assert(10 & a == 10) end)(); checkcap{"band", 10, a}
160assert(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}
161assert(a*a == a) 172assert(a | "hi" == a); checkcap{"bor", a, "hi"}
162assert(cap[0] == "mul" and cap[1] == a and cap[2] == a and cap[3]==undef) 173assert("hi" ~ a == "hi"); checkcap{"bxor", "hi", a}
163assert(a/0 == a) 174;(function () assert(10 ~ a == 10) end)(); checkcap{"bxor", 10, a}
164assert(cap[0] == "div" and cap[1] == a and cap[2] == 0 and cap[3]==undef) 175assert(-a == a); checkcap{"unm", a, a}
165assert(a%2 == a) 176assert(a^4.0 == a); checkcap{"pow", a, 4.0}
166assert(cap[0] == "mod" and cap[1] == a and cap[2] == 2 and cap[3]==undef) 177assert(a^'4' == a); checkcap{"pow", a, '4'}
167assert(a // (1/0) == a) 178assert(4^a == 4); checkcap{"pow", 4, a}
168assert(cap[0] == "idiv" and cap[1] == a and cap[2] == 1/0 and cap[3]==undef) 179assert('4'^a == '4'); checkcap{"pow", '4', a}
169;(function () assert(a & "hi" == a) end)() 180assert(#a == a); checkcap{"len", a, a}
170assert(cap[0] == "band" and cap[1] == a and cap[2] == "hi" and cap[3]==undef) 181assert(~a == a); checkcap{"bnot", a, a}
171;(function () assert(10 & a == 10) end)() 182assert(a << 3 == a); checkcap{"shl", a, 3}
172assert(cap[0] == "band" and cap[1] == 10 and cap[2] == a and cap[3]==undef) 183assert(1.5 >> a == 1.5); checkcap{"shr", 1.5, a}
173;(function () assert(a | 10 == a) end)() 184
174assert(cap[0] == "bor" and cap[1] == a and cap[2] == 10 and cap[3]==undef) 185-- for comparsion operators, all results are true
175assert(a | "hi" == a) 186assert(5.0 > a); checkcap{"lt", a, 5.0}
176assert(cap[0] == "bor" and cap[1] == a and cap[2] == "hi" and cap[3]==undef) 187assert(a >= 10); checkcap{"le", 10, a}
177assert("hi" ~ a == "hi") 188assert(a <= -10.0); checkcap{"le", a, -10.0}
178assert(cap[0] == "bxor" and cap[1] == "hi" and cap[2] == a and cap[3]==undef) 189assert(a < -10); checkcap{"lt", a, -10}
179;(function () assert(10 ~ a == 10) end)()
180assert(cap[0] == "bxor" and cap[1] == 10 and cap[2] == a and cap[3]==undef)
181assert(-a == a)
182assert(cap[0] == "unm" and cap[1] == a)
183assert(a^4 == a)
184assert(cap[0] == "pow" and cap[1] == a and cap[2] == 4 and cap[3]==undef)
185assert(a^'4' == a)
186assert(cap[0] == "pow" and cap[1] == a and cap[2] == '4' and cap[3]==undef)
187assert(4^a == 4)
188assert(cap[0] == "pow" and cap[1] == 4 and cap[2] == a and cap[3]==undef)
189assert('4'^a == '4')
190assert(cap[0] == "pow" and cap[1] == '4' and cap[2] == a and cap[3]==undef)
191assert(#a == a)
192assert(cap[0] == "len" and cap[1] == a)
193assert(~a == a)
194assert(cap[0] == "bnot" and cap[1] == a)
195assert(a << 3 == a)
196assert(cap[0] == "shl" and cap[1] == a and cap[2] == 3)
197assert(1.5 >> a == 1.5)
198assert(cap[0] == "shr" and cap[1] == 1.5 and cap[2] == a)
199 190
200 191
201-- test for rawlen 192-- test for rawlen