From fb7e5b76c9d41108c399cf4d16470018b717007b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 26 Jun 2024 14:46:44 -0300 Subject: Clearer code for controlling maximum registers Plus, added a test to check that limit. --- testes/code.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'testes') diff --git a/testes/code.lua b/testes/code.lua index bd4b10d0..329619f1 100644 --- a/testes/code.lua +++ b/testes/code.lua @@ -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' -- cgit v1.2.3-55-g6feb