make net in port lists arrays

This commit is contained in:
Redo0 2021-05-25 17:18:57 -05:00
parent d25893566e
commit 730ca3fd64
5 changed files with 17 additions and 18 deletions

View File

@ -28,8 +28,8 @@ function Gate.addport(self, port)
Port.setgate(port, self)
end
function Gate.getportstate(self, index)
return self.ports[index].group.state
function Gate.getportstate(gate, index)
return gate.ports[index].group.state
end
function Gate.setportstate(self, index, state)

View File

@ -118,7 +118,7 @@ function Group.addport(self, port)
self.in_ports[port] = port
self.nin_ports = self.nin_ports + 1
if port.causeupdate then
self.in_ports_update[port] = port
table.insert(self.in_ports_update, port)
end
Simulation.queuegate(GSim, Port.getgate(port))
@ -147,7 +147,7 @@ function Group.removeport(self, port)
self.in_ports[port] = nil
self.nin_ports = self.nin_ports - 1
if port.causeupdate then
self.in_ports_update[port] = nil
array_remove(self.in_ports_update, port)
end
Simulation.queuegate(GSim, Port.getgate(port))
@ -198,7 +198,7 @@ function Group.setstate(self, state)
self.state = state
self.updatetick = sim.currenttick
for k, port in pairs(self.in_ports_update) do
for k, port in ipairs(self.in_ports_update) do
Simulation.queuegate(sim, Port.getgate(port))
end

View File

@ -262,7 +262,7 @@ while 1 do
local group = Wire.getgroup(wire)
local numwires = 0; for k, wire2 in pairs(group.wires ) do numwires = numwires +1 end
local numportsi = 0; for k, port in pairs(group.in_ports ) do numportsi = numportsi+1 end
local numportsu = 0; for k, port in pairs(group.in_ports_update) do numportsu = numportsu+1 end
local numportsu = #group.in_ports_update
local numportso = 0; local numportson=0;
for k, port in pairs(group.out_ports) do
numportso = numportso+1

View File

@ -270,18 +270,6 @@ function Simulation.queuegroup(self, group)
end
end
local function array_remove(array, value)
for i = 1, #array do
local v = array[i]
if v==value then
array[i] = array[#array]
array[#array] = nil
return
end
end
error("element not in array")
end
function Simulation.dequeuegroup(self, group)
if group.in_queue then
array_remove(self.groupqueue, group)

View File

@ -66,3 +66,14 @@ function tobitstring(num, len)
return bitstring
end
function array_remove(array, value)
for i = 1, #array do
local v = array[i]
if v==value then
array[i] = array[#array]
array[#array] = nil
return
end
end
error("element not in array")
end