make sim queues use c objs
This commit is contained in:
@@ -13,6 +13,7 @@ function Simulation.new(sim)
|
||||
definitions = {},
|
||||
wires = {},
|
||||
gates = {},
|
||||
nets = {},
|
||||
nwires = 0,
|
||||
ngates = 0,
|
||||
ninports = 0,
|
||||
@@ -222,7 +223,9 @@ function Simulation.connectwire(sim, wire)
|
||||
end
|
||||
|
||||
if Wire.getgroup(wire)==nil then
|
||||
Group.addwire(Group.new(), wire)
|
||||
local newnet = Group.new()
|
||||
Simulation.add_net(sim, newnet)
|
||||
Group.addwire(newnet, wire)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -236,15 +239,21 @@ function Simulation.connectport(sim, port)
|
||||
end
|
||||
|
||||
if Port.getgroup(port) == nil then
|
||||
Group.addport(Group.new(), port)
|
||||
local newnet = Group.new()
|
||||
Simulation.add_net(sim, newnet)
|
||||
Group.addport(newnet, port)
|
||||
end
|
||||
end
|
||||
|
||||
-- Logic Critical
|
||||
function Simulation.queuegate(sim, gate)
|
||||
sim.gatequeue[sim.num_gatequeue+1] = gate
|
||||
function Simulation.queue_gate_c(sim, gatec)
|
||||
sim.gatequeue[sim.num_gatequeue+1] = gatec
|
||||
sim.num_gatequeue = sim.num_gatequeue + 1
|
||||
gate.in_queue[0] = 1
|
||||
gatec.in_queue[0] = 1
|
||||
end
|
||||
|
||||
function Simulation.queuegate(sim, gate)
|
||||
Simulation.queue_gate_c(sim, gate.c)
|
||||
end
|
||||
|
||||
function Simulation.queuegate_safe(sim, gate)
|
||||
@@ -274,10 +283,14 @@ function Simulation.queuegateinit(sim, gate)
|
||||
end
|
||||
|
||||
-- Logic Critical
|
||||
function Simulation.queuegroup(sim, group)
|
||||
sim.groupqueue[sim.num_groupqueue+1] = group
|
||||
function Simulation.queue_net_c(sim, netc)
|
||||
sim.groupqueue[sim.num_groupqueue+1] = netc
|
||||
sim.num_groupqueue = sim.num_groupqueue + 1
|
||||
group.in_queue[0] = 1
|
||||
netc.in_queue[0] = 1
|
||||
end
|
||||
|
||||
function Simulation.queuegroup(sim, net)
|
||||
Simulation.queue_net_c(sim, net.c)
|
||||
end
|
||||
|
||||
function Simulation.queuegroup_safe(sim, group)
|
||||
@@ -288,7 +301,7 @@ end
|
||||
|
||||
function Simulation.dequeuegroup(sim, group)
|
||||
if group.in_queue[0]~=0 then
|
||||
array_remove(sim.groupqueue, group, true)
|
||||
array_remove(sim.groupqueue, group.c, true)
|
||||
sim.num_groupqueue = sim.num_groupqueue - 1
|
||||
group.in_queue[0] = 0
|
||||
end
|
||||
@@ -320,12 +333,11 @@ end
|
||||
-- Logic Critical
|
||||
function Simulation.ticklogic(sim)
|
||||
for i = 1, sim.num_groupqueue do
|
||||
local group = sim.groupqueue[i]
|
||||
Group.update(group)
|
||||
group.in_queue[0] = 0
|
||||
local netc = sim.groupqueue[i]
|
||||
Group.update_net_c(netc, sim.current_tick)
|
||||
netc.in_queue[0] = 0
|
||||
sim.groupqueue[i] = nil
|
||||
end
|
||||
--sim.groupqueue = {}
|
||||
sim.num_groupqueue = 0
|
||||
|
||||
if sim.tickqueue[sim.current_tick] ~= nil then
|
||||
@@ -338,12 +350,12 @@ function Simulation.ticklogic(sim)
|
||||
end
|
||||
|
||||
for i = 1, sim.num_gatequeue do
|
||||
local gate = sim.gatequeue[i]
|
||||
local gatec = sim.gatequeue[i]
|
||||
local gate = sim.gate_from_gatec(sim, gatec)
|
||||
gate.logic(gate)
|
||||
gate.in_queue[0] = 0
|
||||
sim.gatequeue[i] = nil
|
||||
end
|
||||
--sim.gatequeue = {}
|
||||
sim.num_gatequeue = 0
|
||||
|
||||
sim.current_tick = sim.current_tick + 1
|
||||
@@ -403,3 +415,18 @@ function Simulation.sendcallbacks(sim)
|
||||
sim.callbacks = nil
|
||||
end
|
||||
end
|
||||
|
||||
function Simulation.add_net(sim, net)
|
||||
sim.nets[net.id] = net
|
||||
end
|
||||
function Simulation.remove_net(sim, net)
|
||||
sim.nets[net.id] = nil
|
||||
end
|
||||
|
||||
function Simulation.net_from_netc(sim, netc)
|
||||
return sim.nets[netc.id] or error("no net for id "..netc.id)
|
||||
end
|
||||
|
||||
function Simulation.gate_from_gatec(sim, gatec)
|
||||
return sim.gates[gatec.objref] or error("no gate for objref "..gatec.objref)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user