Clearer code for controlling maximum registers
Plus, added a test to check that limit.
This commit is contained in:
@@ -445,5 +445,20 @@ do -- string constants
|
||||
assert(T.listk(f2)[1] == nil)
|
||||
end
|
||||
|
||||
|
||||
do -- check number of available registers
|
||||
-- 1 register for local + 1 for function + 252 arguments
|
||||
local source = "local a; return a(" .. string.rep("a, ", 252) .. "a)"
|
||||
local prog = T.listcode(assert(load(source)))
|
||||
-- maximum valid register is 254
|
||||
for i = 1, 254 do
|
||||
assert(string.find(prog[2 + i], "MOVE%s*" .. i))
|
||||
end
|
||||
-- one more argument would need register #255 (but that is reserved)
|
||||
source = "local a; return a(" .. string.rep("a, ", 253) .. "a)"
|
||||
local _, msg = load(source)
|
||||
assert(string.find(msg, "too many registers"))
|
||||
end
|
||||
|
||||
print 'OK'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user