add net and wire struct; move net update into its file

This commit is contained in:
Redo0 2021-05-25 15:13:03 -05:00
parent 8561940777
commit d151ab688c
5 changed files with 38 additions and 15 deletions

View File

@ -2,12 +2,6 @@
local ffi = FFI or require("ffi")
Simulation = Simulation or {}
ffi.cdef([[
struct Net {
};
]])
function Simulation.compile(sim)
-- assemble a list of all nets
local all_nets = {}

View File

@ -1,6 +1,19 @@
Group = {}
FFI.cdef[[
struct Port;
struct Net {
bool state;
bool fxstate;
int updatetick;
int internal_ref;
int state_num;
int num_in_ports_update;
struct Port* in_ports_update[1];
};
]]
function Group.new(self, sim)
local o = {
state = false,
@ -10,6 +23,8 @@ function Group.new(self, sim)
out_ports = {},
in_ports = {},
state_num = 0,
nwires = 0,
nout_ports = 0,
nin_ports = 0,
@ -154,3 +169,15 @@ end
function Group.getsim(group)
return group.sim
end
function Group.update(group)
local newstate = false
for j, port in pairs(group.out_ports) do
newstate = newstate or Port.getstate(port)
if newstate then
break
end
end
Group.setstate(group, newstate)
end

View File

@ -17,6 +17,7 @@ Port = {}
FFI.cdef[[
struct Gate;
struct Net;
struct Port {
bool state;
char type;

View File

@ -266,15 +266,7 @@ end
function Simulation.tick(self)
for k, group in pairs(self.groupqueue) do
local newstate = false
for j, port in pairs(group.out_ports) do
newstate = newstate or Port.getstate(port)
if newstate then
break
end
end
Group.setstate(group, newstate)
Group.update(group)
end
self.groupqueue = {}

View File

@ -1,6 +1,15 @@
Wire = {}
FFI.cdef[[
struct Wire {
int objref;
int layer;
struct Net* group;
int bounds[6];
};
]]
function Wire.new(self, objref, layer, bounds, sim)
local o = {
objref = objref,