diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-26 14:46:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-26 14:46:44 -0300 |
commit | fb7e5b76c9d41108c399cf4d16470018b717007b (patch) | |
tree | cfc2b875d139727f1847100d8ae0950bee3d4f56 /testes | |
parent | c1dc08e8e8e22af9902a6341b4a9a9a7811954cc (diff) | |
download | lua-fb7e5b76c9d41108c399cf4d16470018b717007b.tar.gz lua-fb7e5b76c9d41108c399cf4d16470018b717007b.tar.bz2 lua-fb7e5b76c9d41108c399cf4d16470018b717007b.zip |
Clearer code for controlling maximum registers
Plus, added a test to check that limit.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/code.lua | 15 |
1 files changed, 15 insertions, 0 deletions
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 | |||
445 | assert(T.listk(f2)[1] == nil) | 445 | assert(T.listk(f2)[1] == nil) |
446 | end | 446 | end |
447 | 447 | ||
448 | |||
449 | do -- check number of available registers | ||
450 | -- 1 register for local + 1 for function + 252 arguments | ||
451 | local source = "local a; return a(" .. string.rep("a, ", 252) .. "a)" | ||
452 | local prog = T.listcode(assert(load(source))) | ||
453 | -- maximum valid register is 254 | ||
454 | for i = 1, 254 do | ||
455 | assert(string.find(prog[2 + i], "MOVE%s*" .. i)) | ||
456 | end | ||
457 | -- one more argument would need register #255 (but that is reserved) | ||
458 | source = "local a; return a(" .. string.rep("a, ", 253) .. "a)" | ||
459 | local _, msg = load(source) | ||
460 | assert(string.find(msg, "too many registers")) | ||
461 | end | ||
462 | |||
448 | print 'OK' | 463 | print 'OK' |
449 | 464 | ||