bitwise expressions compiler

This commit is contained in:
Onran
2025-04-06 22:16:04 +09:00
committed by GitHub
parent d9d4d2b305
commit cba48e3a0c
5 changed files with 484 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
local compiler = require "core:bitwise/compiler"
local cache = { }
local cacheLength = 512
local function hashOfArgs(args)
local str = ""
for i = 1, #args do
str = str..args[i]
if i ~= #args then
str = str..';'
end
end
return str
end
local function execute(str, args, ...)
local hasArgs = args and type(args) == 'table'
local expArgs
if hasArgs then
expArgs = args
else
expArgs = nil
end
local argsHash = hasArgs and hashOfArgs(args) or ""
local func
if (#str + #argsHash) <= cacheLength then
if cache[argsHash] then
local fun = cache[argsHash][str]
if fun then return fun end
end
local comp = compiler(str, expArgs)
cache[argsHash] = { }
cache[argsHash][str] = comp
func = comp
else
func = compiler(str, expArgs)
end
if hasArgs or not args then
return func(...)
else
return func(args, ...)
end
end
return execute