Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions lua/entities/gmod_wire_expression2/base/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@
local Node, NodeVariant = E2Lib.Parser.Node, E2Lib.Parser.Variant
local Operator = E2Lib.Operator
local newE2Table = E2Lib.newE2Table

local pairs, ipairs = pairs, ipairs

local TickQuota = GetConVar("wire_expression2_quotatick"):GetInt()

cvars.RemoveChangeCallback("wire_expression2_quotatick", "compiler_quota_check")
cvars.AddChangeCallback("wire_expression2_quotatick", function(_, old, new)
TickQuota = tonumber(new)
end, "compiler_quota_check")

---@class ScopeData
---@field dead "ret"|true?
---@field loop boolean?
Expand Down Expand Up @@ -265,7 +257,7 @@
if self.scope:ResolveData("loop") or self.scope:ResolveData("switch_case") then -- Inside loop or switch case, check if continued or broken
return function(state) ---@param state RuntimeContext
state.prf = state.prf + cost
if state.prf > TickQuota then error("perf", 0) end
if state.prf > e2_tickquota then error("perf", 0) end

for i = 1, nstmts do
state.trace = traces[i]
Expand All @@ -276,7 +268,7 @@
elseif self.scope:ResolveData("function") then -- If inside a function, check if returned.
return function(state) ---@param state RuntimeContext
state.prf = state.prf + cost
if state.prf > TickQuota then error("perf", 0) end
if state.prf > e2_tickquota then error("perf", 0) end

for i = 1, nstmts do
state.trace = traces[i]
Expand All @@ -287,7 +279,7 @@
else -- Most optimized case, not inside a function or loop.
return function(state) ---@param state RuntimeContext
state.prf = state.prf + cost
if state.prf > TickQuota then error("perf", 0) end
if state.prf > e2_tickquota then error("perf", 0) end

for i = 1, nstmts do
state.trace = traces[i]
Expand Down Expand Up @@ -407,7 +399,7 @@

---@param data { [1]: Token<string>, [2]: Node, [3]: Node, [4]: Node?, [5]: Node } var start stop step block
[NodeVariant.For] = function (self, trace, data)
local var, start, stop, step = data[1], self:CompileExpr(data[2]), self:CompileExpr(data[3]), data[4] and self:CompileExpr(data[4]) or data[4]

Check warning on line 402 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: step

local block = self:Scope(function(scope)
scope.data.loop = true
Expand Down Expand Up @@ -586,9 +578,9 @@

if state.__break__ then
state.__break__ = false
goto exit

Check warning on line 581 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
elseif state.__return__ then -- Yes this should only be checked if the switch is inside a function, but I don't care enough about the performance of switch case to add another duplicated 30 lines to the file
goto exit

Check warning on line 583 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
else -- Fallthrough, run every case until break found.
for j = i + 1, ncases do
cases[j][2](state)
Expand Down Expand Up @@ -1047,9 +1039,9 @@
state.GlobalScope[var], state.GlobalScope.vclk[var] = val, true

if state.GlobalScope.lookup[val] then
state.GlobalScope.lookup[val][var] = true

Check warning on line 1042 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
else
state.GlobalScope.lookup[val] = { [var] = true }

Check warning on line 1044 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
end
end
else
Expand Down Expand Up @@ -1867,7 +1859,7 @@
if fn.attributes.legacy then
local largs = { [1] = {}, [nargs + 2] = arg_types }
for i = 1, nargs do
largs[i + 1] = { [1] = function() return rargs[i] end }

Check warning on line 1862 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
end
return fn[3](state, largs, arg_types)
elseif varsig == "array(...)" then -- Need this since can't enforce compile time argument type restrictions on string calls. Woop. Array creation should not be a function..
Expand All @@ -1875,11 +1867,11 @@
while i <= #arg_types do
local ty = arg_types[i]
if BLOCKED_ARRAY_TYPES[ty] then
table.remove(rargs, i)

Check warning on line 1870 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
table.remove(arg_types, i)
state:forceThrow("Cannot use type " .. ty .. " for argument #" .. i .. " in stringcall array creation")
else
i = i + 1

Check warning on line 1874 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
end
end
end
Expand All @@ -1892,7 +1884,7 @@
if fn then
for _, ty in ipairs(arg_types) do -- Just block them entirely. Current method of finding variadics wouldn't allow a proper solution that works with x<yz> types. Would need to rewrite all of this which I don't think is worth it when already nobody is going to use this functionality.
if BLOCKED_ARRAY_TYPES[ty] then
state:forceThrow("Cannot pass array into variadic array function")

Check warning on line 1887 in lua/entities/gmod_wire_expression2/base/compiler.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
end
end

Expand Down
Loading