Removed unused requires & added a new sanity check!#216
Merged
levno-710 merged 1 commit intoprometheus-lua:masterfrom Mar 9, 2026
Merged
Removed unused requires & added a new sanity check!#216levno-710 merged 1 commit intoprometheus-lua:masterfrom
levno-710 merged 1 commit intoprometheus-lua:masterfrom
Conversation
Member
|
It could be possible to modify Compiler:allocRegister to not always choose the first free register, but to have a set of the next n free registers and choosing one from them randomly. Something like this: local free_regs = {}
local next_free = 1
local free_count = 0
-- ensure at least n free registers exist
local function grow(n)
while free_count < n do
free_count = free_count + 1
free_regs[free_count] = next_free
next_free = next_free + 1
end
end
-- allocate a register randomly from the next n free registers
function alloc(n)
n = n or 8
grow(n)
local limit = math.min(n, free_count)
local idx = math.random(limit)
local reg = free_regs[idx]
-- remove chosen register (swap-remove)
free_regs[idx] = free_regs[free_count]
free_regs[free_count] = nil
free_count = free_count - 1
return reg
end
-- free a register
function free(reg)
free_count = free_count + 1
free_regs[free_count] = reg
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added a sanity check which works for all Lua versions to prevent someone from using registerArray[1] = true; (this sadly is a real thing, I don't think it can be fixed due to the way the VM is built.)
Why does this benefit the project? It prevents anyone going into any obfuscated file and quite literally beautifying it, looking for the loop, and looking for the first index expression you see, and say the base name was T,
you'd do
and if
UseDebugistrue, all you have to do is run the file and comment out the line of the error call.