diff --git a/lua/entities/gmod_wire_expression2/base/compiler.lua b/lua/entities/gmod_wire_expression2/base/compiler.lua index 58b23bcd80..071c163538 100644 --- a/lua/entities/gmod_wire_expression2/base/compiler.lua +++ b/lua/entities/gmod_wire_expression2/base/compiler.lua @@ -885,9 +885,9 @@ local CompileVisitors = { -- It can have indices, it already exists if #indices > 0 then - local setter = table.remove(indices) + local setter, id = table.remove(indices), existing.scope:Depth() stmts[i] = function(state) - return state.Scope[var] + return state.Scopes[id][var] end for j, index in ipairs(indices) do @@ -923,17 +923,39 @@ local CompileVisitors = { self:Assert(existing.type == value_ty, "Cannot assign type (" .. value_ty .. ") to variable of type (" .. existing.type .. ")", trace) local id = existing.scope:Depth() - stmts[i] = function(state) ---@param state RuntimeContext - state.Scopes[id][var] = value(state) + if id == 0 then + stmts[i] = function(state) ---@param state RuntimeContext + local val = value(state) + state.GlobalScope[var] = val + state.GlobalScope.vclk[var] = true + + if state.GlobalScope.lookup[val] then + state.GlobalScope.lookup[val][var] = true + else + state.GlobalScope.lookup[val] = { [var] = true } + end + end + else + stmts[i] = function(state) ---@param state RuntimeContext + state.Scopes[id][var] = value(state) + end end end else -- Cannot have indices. self:Assert(#indices == 0, "Variable (" .. var .. ") does not exist", trace) - self.scope:DeclVar(var, { type = value_ty, initialized = true, trace_if_unused = trace }) + self.global_scope:DeclVar(var, { type = value_ty, initialized = true, trace_if_unused = trace }) stmts[i] = function(state) ---@param state RuntimeContext - state.Scope[var] = value(state) + local val = value(state) + state.GlobalScope[var] = val + state.GlobalScope.vclk[var] = true + + if state.GlobalScope.lookup[val] then + state.GlobalScope.lookup[val][var] = true + else + state.GlobalScope.lookup[val] = { [var] = true } + end end end end @@ -1177,11 +1199,11 @@ local CompileVisitors = { local largs_lhs = { [1] = {}, [2] = { lhs }, [3] = { lhs_ty } } local largs_rhs = { [1] = {}, [2] = { rhs }, [3] = { rhs_ty } } return function(state) - return (op_lhs(lhs(state, largs_lhs)) ~= 0 and op_rhs(rhs(state, largs_rhs)) ~= 0) and 1 or 0 + return (op_lhs(state, lhs(state, largs_lhs)) ~= 0 and op_rhs(state, rhs(state, largs_rhs)) ~= 0) and 1 or 0 end else return function(state) - return (op_lhs(lhs(state)) ~= 0 and op_rhs(rhs(state)) ~= 0) and 1 or 0 + return (op_lhs(state, lhs(state)) ~= 0 and op_rhs(state, rhs(state)) ~= 0) and 1 or 0 end, "n" end end diff --git a/lua/entities/gmod_wire_expression2/core/angle.lua b/lua/entities/gmod_wire_expression2/core/angle.lua index 33d22f48ae..8ea3a1acb1 100644 --- a/lua/entities/gmod_wire_expression2/core/angle.lua +++ b/lua/entities/gmod_wire_expression2/core/angle.lua @@ -40,21 +40,6 @@ e2function angle ang(vector rv1) return Angle(rv1[1], rv1[2], rv1[3]) end - -registerOperator("ass", "a", "a", function(self, args) - local lhs, op2, scope = args[2], args[3], args[4] - local rhs = op2[1](self, op2) - - local Scope = self.Scopes[scope] - local lookup = Scope.lookup - if !lookup then lookup = {} Scope.lookup = lookup end - if lookup[rhs] then lookup[rhs][lhs] = true else lookup[rhs] = {[lhs] = true} end - - Scope[lhs] = rhs - Scope.vclk[lhs] = true - return rhs -end) - registerOperator("is", "a", "n", function(state, a) return a:IsZero() and 1 or 0 end, 1, nil, { legacy = false }) diff --git a/lua/entities/gmod_wire_expression2/core/array.lua b/lua/entities/gmod_wire_expression2/core/array.lua index d2dbfd5023..9d8186ff83 100644 --- a/lua/entities/gmod_wire_expression2/core/array.lua +++ b/lua/entities/gmod_wire_expression2/core/array.lua @@ -71,25 +71,6 @@ registerOperator( "kvarray", "", "r", function( self, args ) return ret end) --------------------------------------------------------------------------------- --- = operator --------------------------------------------------------------------------------- -registerOperator("ass", "r", "r", function(self, args) - local lhs, op2, scope = args[2], args[3], args[4] - local rhs = op2[1](self, op2) - - local Scope = self.Scopes[scope] - local lookup = Scope.lookup - if !lookup then lookup = {} Scope.lookup = lookup end - if lookup[rhs] then lookup[rhs][lhs] = true else lookup[rhs] = {[lhs] = true} end - - Scope[lhs] = rhs - Scope.vclk[lhs] = true - return rhs -end) - - - -------------------------------------------------------------------------------- -- IS operator -------------------------------------------------------------------------------- diff --git a/lua/entities/gmod_wire_expression2/core/bone.lua b/lua/entities/gmod_wire_expression2/core/bone.lua index 3598957804..c07a92820b 100644 --- a/lua/entities/gmod_wire_expression2/core/bone.lua +++ b/lua/entities/gmod_wire_expression2/core/bone.lua @@ -93,11 +93,6 @@ e2function number operator==(bone lhs, bone rhs) if lhs == rhs then return 1 else return 0 end end ---- B != B -e2function number operator!=(bone lhs, bone rhs) - if lhs ~= rhs then return 1 else return 0 end -end - --[[************************************************************************]]-- __e2setcost(3) diff --git a/lua/entities/gmod_wire_expression2/core/complex.lua b/lua/entities/gmod_wire_expression2/core/complex.lua index aba95179ef..c2498ee3ea 100644 --- a/lua/entities/gmod_wire_expression2/core/complex.lua +++ b/lua/entities/gmod_wire_expression2/core/complex.lua @@ -114,27 +114,6 @@ e2function number operator==(number lhs, complex rhs) else return 0 end end -e2function number operator!=(complex lhs, complex rhs) - if abs(lhs[1]-rhs[1])>delta or - abs(lhs[2]-rhs[2])>delta then - return 1 - else return 0 end -end - -e2function number operator!=(complex lhs, number rhs) - if abs(lhs[1]-rhs)>delta or - abs(lhs[2])>delta then - return 1 - else return 0 end -end - -e2function number operator!=(number lhs, complex rhs) - if abs(lhs-rhs[1])>delta or - abs(rhs[2])>delta then - return 1 - else return 0 end -end - /******************************************************************************/ e2function complex operator_neg(complex z) diff --git a/lua/entities/gmod_wire_expression2/core/core.lua b/lua/entities/gmod_wire_expression2/core/core.lua index 6e1b1de228..8e908c711b 100644 --- a/lua/entities/gmod_wire_expression2/core/core.lua +++ b/lua/entities/gmod_wire_expression2/core/core.lua @@ -34,7 +34,7 @@ end) __e2setcost(0) -- cascaded registerOperator("is", "n", "n", function(state, num) - return num ~= 0 and 1 or 0 + return (num ~= 0) and 1 or 0 end, 1, nil, { legacy = false }) -------------------------------------------------------------------------------- diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 5763b5685c..82f99422ee 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -63,14 +63,6 @@ end __e2setcost(5) -- temporary -registerOperator("ass", "e", "e", function(self, args) - local op1, op2, scope = args[2], args[3], args[4] - local rv2 = op2[1](self, op2) - self.Scopes[scope][op1] = rv2 - self.Scopes[scope].vclk[op1] = true - return rv2 -end) - /******************************************************************************/ e2function number operator_is(entity ent) @@ -81,10 +73,6 @@ e2function number operator==(entity lhs, entity rhs) if lhs == rhs then return 1 else return 0 end end -e2function number operator!=(entity lhs, entity rhs) - if lhs ~= rhs then return 1 else return 0 end -end - /******************************************************************************/ e2function entity entity(id) diff --git a/lua/entities/gmod_wire_expression2/core/globalvars.lua b/lua/entities/gmod_wire_expression2/core/globalvars.lua index 8fa124032f..7bc77bd066 100644 --- a/lua/entities/gmod_wire_expression2/core/globalvars.lua +++ b/lua/entities/gmod_wire_expression2/core/globalvars.lua @@ -30,20 +30,6 @@ registerType( "gtable", "xgt", {}, __e2setcost(1) -registerOperator("ass", "xgt", "xgt", function(self, args) - local lhs, op2, scope = args[2], args[3], args[4] - local rhs = op2[1](self, op2) - - local Scope = self.Scopes[scope] - local lookup = Scope.lookup - if !lookup then lookup = {} Scope.lookup = lookup end - if lookup[rhs] then lookup[rhs][lhs] = true else lookup[rhs] = {[lhs] = true} end - - Scope[lhs] = rhs - Scope.vclk[lhs] = true - return rhs -end) - e2function number operator_is( gtable tbl ) return istable(tbl) and 1 or 0 end diff --git a/lua/entities/gmod_wire_expression2/core/matrix.lua b/lua/entities/gmod_wire_expression2/core/matrix.lua index 1d22e5b17c..6a2bb967c1 100644 --- a/lua/entities/gmod_wire_expression2/core/matrix.lua +++ b/lua/entities/gmod_wire_expression2/core/matrix.lua @@ -115,14 +115,6 @@ e2function number operator==(matrix2 rv1, matrix2 rv2) then return 1 else return 0 end end -e2function number operator!=(matrix2 rv1, matrix2 rv2) - if rv1[1] - rv2[1] > delta and rv2[1] - rv1[1] > delta and - rv1[2] - rv2[2] > delta and rv2[2] - rv1[2] > delta and - rv1[3] - rv2[3] > delta and rv2[3] - rv1[3] > delta and - rv1[4] - rv2[4] > delta and rv2[4] - rv1[4] > delta - then return 1 else return 0 end -end - /******************************************************************************/ // Basic operations @@ -1056,26 +1048,6 @@ e2function number operator==(matrix4 rv1, matrix4 rv2) then return 1 else return 0 end end -e2function number operator!=(matrix4 rv1, matrix4 rv2) - if rv1[1] - rv2[1] > delta and rv2[1] - rv1[1] > delta and - rv1[2] - rv2[2] > delta and rv2[2] - rv1[2] > delta and - rv1[3] - rv2[3] > delta and rv2[3] - rv1[3] > delta and - rv1[4] - rv2[4] > delta and rv2[4] - rv1[4] > delta and - rv1[5] - rv2[5] > delta and rv2[5] - rv1[5] > delta and - rv1[6] - rv2[6] > delta and rv2[6] - rv1[6] > delta and - rv1[7] - rv2[7] > delta and rv2[7] - rv1[7] > delta and - rv1[8] - rv2[8] > delta and rv2[8] - rv1[8] > delta and - rv1[9] - rv2[9] > delta and rv2[9] - rv1[9] > delta and - rv1[10] - rv2[10] > delta and rv2[10] - rv1[10] > delta and - rv1[11] - rv2[11] > delta and rv2[11] - rv1[11] > delta and - rv1[12] - rv2[12] > delta and rv2[12] - rv1[12] > delta and - rv1[13] - rv2[13] > delta and rv2[13] - rv1[13] > delta and - rv1[14] - rv2[14] > delta and rv2[14] - rv1[14] > delta and - rv1[15] - rv2[15] > delta and rv2[15] - rv1[15] > delta and - rv1[16] - rv2[16] > delta and rv2[16] - rv1[16] > delta - then return 1 else return 0 end -end - /******************************************************************************/ // Basic operations diff --git a/lua/entities/gmod_wire_expression2/core/quaternion.lua b/lua/entities/gmod_wire_expression2/core/quaternion.lua index bc2bb8840e..ef0bcb3067 100644 --- a/lua/entities/gmod_wire_expression2/core/quaternion.lua +++ b/lua/entities/gmod_wire_expression2/core/quaternion.lua @@ -247,20 +247,6 @@ end __e2setcost(2) -registerOperator("ass", "q", "q", function(self, args) - local lhs, op2, scope = args[2], args[3], args[4] - local rhs = op2[1](self, op2) - - local Scope = self.Scopes[scope] - local lookup = Scope.lookup - if !lookup then lookup = {} Scope.lookup = lookup end - if lookup[rhs] then lookup[rhs][lhs] = true else lookup[rhs] = {[lhs] = true} end - - Scope[lhs] = rhs - Scope.vclk[lhs] = true - return rhs -end) - /******************************************************************************/ // TODO: define division as multiplication with (1/x), or is it not useful? @@ -474,15 +460,6 @@ e2function number operator==(quaternion lhs, quaternion rhs) then return 1 else return 0 end end -e2function number operator!=(quaternion lhs, quaternion rhs) - local rvd1, rvd2, rvd3, rvd4 = lhs[1] - rhs[1], lhs[2] - rhs[2], lhs[3] - rhs[3], lhs[4] - rhs[4] - if rvd1 > delta or rvd1 < -delta or - rvd2 > delta or rvd2 < -delta or - rvd3 > delta or rvd3 < -delta or - rvd4 > delta or rvd4 < -delta - then return 1 else return 0 end -end - /******************************************************************************/ __e2setcost(4) diff --git a/lua/entities/gmod_wire_expression2/core/table.lua b/lua/entities/gmod_wire_expression2/core/table.lua index d4408cabf2..9b61862145 100644 --- a/lua/entities/gmod_wire_expression2/core/table.lua +++ b/lua/entities/gmod_wire_expression2/core/table.lua @@ -252,22 +252,6 @@ end -- Operators -------------------------------------------------------------------------------- -__e2setcost(5) - -registerOperator("ass", "t", "t", function(self, args) - local lhs, op2, scope = args[2], args[3], args[4] - local rhs = op2[1](self, op2) - - local Scope = self.Scopes[scope] - local lookup = Scope.lookup - if not lookup then lookup = {} Scope.lookup = lookup end - if lookup[rhs] then lookup[rhs][lhs] = true else lookup[rhs] = {[lhs] = true} end - - Scope[lhs] = rhs - Scope.vclk[lhs] = true - return rhs -end) - __e2setcost(1) e2function number operator_is( table tbl ) @@ -278,10 +262,6 @@ e2function number operator==( table rv1, table rv2 ) return (rv1 == rv2) and 1 or 0 end -e2function number operator!=( table rv1, table rv2 ) - return (rv1 ~= rv2) and 1 or 0 -end - __e2setcost(nil) registerOperator( "kvtable", "", "t", function( self, args ) @@ -1253,7 +1233,7 @@ end) -------------------------------------------------------------------------------- -- these postexecute and construct hooks handle changes to both tables and arrays. -registerCallback("postexecute", function(self) +registerCallback("postexecute", function(self) --- @param self RuntimeContext local Scope = self.GlobalScope local vclk, lookup = Scope.vclk, Scope.lookup diff --git a/lua/entities/gmod_wire_expression2/core/vector.lua b/lua/entities/gmod_wire_expression2/core/vector.lua index d7c6f71982..cfe9923de1 100644 --- a/lua/entities/gmod_wire_expression2/core/vector.lua +++ b/lua/entities/gmod_wire_expression2/core/vector.lua @@ -70,22 +70,6 @@ end -------------------------------------------------------------------------------- -registerOperator("ass", "v", "v", function(self, args) - local lhs, op2, scope = args[2], args[3], args[4] - local rhs = op2[1](self, op2) - - local Scope = self.Scopes[scope] - local lookup = Scope.lookup - if !lookup then lookup = {} Scope.lookup = lookup end - if lookup[rhs] then lookup[rhs][lhs] = true else lookup[rhs] = {[lhs] = true} end - - Scope[lhs] = rhs - Scope.vclk[lhs] = true - return rhs -end) - --------------------------------------------------------------------------------- - e2function number vector:operator_is() if this[1] > delta or -this[1] > delta or this[2] > delta or -this[2] > delta or diff --git a/lua/entities/gmod_wire_expression2/core/vector2.lua b/lua/entities/gmod_wire_expression2/core/vector2.lua index 5ca6d29428..e4f8eb9aaa 100644 --- a/lua/entities/gmod_wire_expression2/core/vector2.lua +++ b/lua/entities/gmod_wire_expression2/core/vector2.lua @@ -57,24 +57,6 @@ registerFunction("vec2", "xv4", "xv2", function(self, args) return { rv1[1], rv1[2] } end) -/******************************************************************************/ - -registerOperator("ass", "xv2", "xv2", function(self, args) - local lhs, op2, scope = args[2], args[3], args[4] - local rhs = op2[1](self, op2) - - local Scope = self.Scopes[scope] - local lookup = Scope.lookup - if !lookup then lookup = {} Scope.lookup = lookup end - if lookup[rhs] then lookup[rhs][lhs] = true else lookup[rhs] = {[lhs] = true} end - - Scope[lhs] = rhs - Scope.vclk[lhs] = true - return rhs -end) - -/******************************************************************************/ - registerOperator("is", "xv2", "n", function(self, args) local op1 = args[2] local rv1 = op1[1](self, op1) @@ -167,15 +149,14 @@ registerOperator("div", "xv2xv2", "xv2", function(self, args) return { rv1[1] / rv2[1], rv1[2] / rv2[2] } end) -e2function number vector2:operator[](index) +registerOperator("idx", "xv2n", "n", function(state, this, index) return this[floor(math.Clamp(index, 1, 2) + 0.5)] -end +end) -e2function number vector2:operator[](index, value) +registerOperator("idx", "xv2nn", "", function(state, this, index, value) this[floor(math.Clamp(index, 1, 2) + 0.5)] = value - self.GlobalScope.vclk[this] = true - return value -end + state.GlobalScope.vclk[this] = true +end) /******************************************************************************/ @@ -610,22 +591,6 @@ end) /******************************************************************************/ -registerOperator("ass", "xv4", "xv4", function(self, args) - local lhs, op2, scope = args[2], args[3], args[4] - local rhs = op2[1](self, op2) - - local Scope = self.Scopes[scope] - local lookup = Scope.lookup - if !lookup then lookup = {} Scope.lookup = lookup end - if lookup[rhs] then lookup[rhs][lhs] = true else lookup[rhs] = {[lhs] = true} end - - Scope[lhs] = rhs - Scope.vclk[lhs] = true - return rhs -end) - -/******************************************************************************/ - registerOperator("is", "xv4", "n", function(self, args) local op1 = args[2] local rv1 = op1[1](self, op1) diff --git a/lua/entities/gmod_wire_expression2/core/wirelink.lua b/lua/entities/gmod_wire_expression2/core/wirelink.lua index e98f1e3c40..c791274bec 100644 --- a/lua/entities/gmod_wire_expression2/core/wirelink.lua +++ b/lua/entities/gmod_wire_expression2/core/wirelink.lua @@ -148,17 +148,13 @@ end) /******************************************************************************/ registerOperator("is", "xwl", "n", function(state, this) - return validWirelink(this) and 1 or 0 + return validWirelink(state, this) and 1 or 0 end, 2, nil, { legacy = false }) e2function number operator==(wirelink lhs, wirelink rhs) if lhs == rhs then return 1 else return 0 end end -e2function number operator!=(wirelink lhs, wirelink rhs) - if lhs ~= rhs then return 1 else return 0 end -end - /******************************************************************************/ e2function number wirelink:isHiSpeed() @@ -244,10 +240,7 @@ registerCallback("postinit", function() else -- all types without an input serializer -- a check for {} is not needed here, since array and table both have input serializers and are thus handled in the above branch. - function getf(self, args) - local this, portname = args[2], args[3] - this, portname = this[1](self, this), portname[1](self, portname) - + function getf(self, this, portname) if not validWirelink(self, this) then return zero end portname = mapOutputAlias(this, portname) @@ -261,10 +254,7 @@ registerCallback("postinit", function() end if output_serializer then - function setf(self, args) - local this, portname, value = args[2], args[3], args[4] - this, portname, value = this[1](self, this), portname[1](self, portname), value[1](self, value) - + function setf(self, this, portname, value) if not validWirelink(self, this) then return value end if not this.Inputs then return value end @@ -274,10 +264,7 @@ registerCallback("postinit", function() return value end else - function setf(self, args) - local this, portname, value = args[2], args[3], args[4] - this, portname, value = this[1](self, this), portname[1](self, portname), value[1](self, value) - + function setf(self, this, portname, value) if not validWirelink(self, this) then return value end if not this.Inputs then return value end