diff --git a/tests/comptests/inputs/25_bits.lua b/tests/comptests/inputs/25_bits.lua index 722a926..bdd7f9a 100644 --- a/tests/comptests/inputs/25_bits.lua +++ b/tests/comptests/inputs/25_bits.lua @@ -1,5 +1,5 @@ f = compiler.load([[ -function doit(a, 25_bits.luawhat) +function doit(a, what) local f: integer = ~0 if what == '&' then return a&f @@ -25,4 +25,4 @@ assert(math.abs(doit(16, '|') - ~0) < 1e-15) assert(math.abs(doit(16, '<<') - 32) < 1e-15) assert(math.abs(doit(16, '>>') - 8) < 1e-15) assert(math.abs(doit(16, '~') - ~16) < 1e-15) -print 'Ok' \ No newline at end of file +print 'Ok' diff --git a/tests/language/ravi_tests1.ravi b/tests/language/ravi_tests1.ravi index d27cc2a..9767d0a 100644 --- a/tests/language/ravi_tests1.ravi +++ b/tests/language/ravi_tests1.ravi @@ -1842,6 +1842,42 @@ do end print 'Test 87 OK' +do + local function doit(a: integer, what) + local f: integer = ~0 + if what == '&' then + return a&f + elseif what == '|' then + return a|f + elseif what == '<<' then + return a<<1 + elseif what == '>>' then + return a>>1 + elseif what == '~' then + return ~a + else + return 0 + end + end + check(doit, 'TOINT', 'LOADK', 'EQ', 'JMP', 'BAND_II', + 'RETURN', 'JMP', 'EQ', 'JMP', 'BOR_II', 'RETURN', + 'JMP', 'EQ', 'JMP', 'SHL_II', 'RETURN', 'JMP', 'EQ', + 'JMP', 'SHR_II', 'RETURN', 'JMP', 'EQ', 'JMP', + 'BNOT_I', 'RETURN', 'JMP', 'LOADK', 'RETURN', 'RETURN') + assert(doit and type(doit) == 'function') + assert(math.abs(doit(16, '&') - 16) < 1e-15) + assert(math.abs(doit(16, '|') - ~0) < 1e-15) + assert(math.abs(doit(16, '<<') - 32) < 1e-15) + assert(math.abs(doit(16, '>>') - 8) < 1e-15) + assert(math.abs(doit(16, '~') - ~16) < 1e-15) + compile(doit) + assert(math.abs(doit(16, '&') - 16) < 1e-15) + assert(math.abs(doit(16, '|') - ~0) < 1e-15) + assert(math.abs(doit(16, '<<') - 32) < 1e-15) + assert(math.abs(doit(16, '>>') - 8) < 1e-15) + assert(math.abs(doit(16, '~') - ~16) < 1e-15) +end +print 'Test 88 OK' for k,v in pairs(opcodes_coverage) do