From 9904c253da9690728710082cfb94654709ab89e7 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 27 Jun 2024 11:24:27 -0300 Subject: Flexible limit for use of registers by constructors Instead of a fixed limit of 50 registers (which, in a bad worst case, can limit the nesting of constructors to 5 levels), the compiler computes an individual limit for each constructor based on how many registers are available when it runs. This limit then controls the frequency of SETLIST instructions. --- testes/code.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'testes') diff --git a/testes/code.lua b/testes/code.lua index 329619f1..08b3e23f 100644 --- a/testes/code.lua +++ b/testes/code.lua @@ -460,5 +460,16 @@ do -- check number of available registers assert(string.find(msg, "too many registers")) end + +do -- basic check for SETLIST + -- create a list constructor with 50 elements + local source = "local a; return {" .. string.rep("a, ", 50) .. "}" + local func = assert(load(source)) + local code = table.concat(T.listcode(func), "\n") + local _, count = string.gsub(code, "SETLIST", "") + -- code uses only 1 SETLIST for the constructor + assert(count == 1) +end + print 'OK' -- cgit v1.2.3-55-g6feb