fix errors

This commit is contained in:
Redo 2022-11-04 13:14:05 -06:00
parent cdbf3ed089
commit 0ac3f3e495
4 changed files with 20 additions and 28 deletions

View File

@ -2,33 +2,15 @@
local ffi = FFI or require("ffi") local ffi = FFI or require("ffi")
Simulation = Simulation or {} Simulation = Simulation or {}
ffi.cdef[[
struct Net {
int in_queue;
int num_out_ports_on;
int state;
int update_tick;
struct Gate* gates_update[0];
};
struct OutPort {
struct Net* net;
int state;
};
struct Gate {
int in_queue;
struct OutPort out_ports[0];
};
]]
function Simulation.compile_code(sim, text) function Simulation.compile_code(sim, text)
-- todo: compile some kind of DSL into machine code -- todo: compile some kind of DSL into machine code
return code, size return code, size
end end
local net_program_code = Simulation.compile_code( [[ --local net_program_code = Simulation.compile_code( [[
--
]] ) --]] )
function Simulation.compile(sim) function Simulation.compile(sim)
sim.compilation = { sim.compilation = {

View File

@ -15,7 +15,7 @@ function GateDefinition.new(objref, name, description, init, logic, input, code,
description = collapseescape(description) description = collapseescape(description)
code = collapseescape(code) code = collapseescape(code)
local compiled_size, compiled_code = Simulation.compile_code(nil, code) --local compiled_size, compiled_code = Simulation.compile_code(nil, code)
local def = { local def = {
objref = objref, objref = objref,
@ -66,7 +66,7 @@ function GateDefinition.new(objref, name, description, init, logic, input, code,
def.num_out_ports = def.num_out_ports + 1 def.num_out_ports = def.num_out_ports + 1
elseif portd.type==PortTypes.input then elseif portd.type==PortTypes.input then
def.num_in_ports = def.num_in_ports + 1 def.num_in_ports = def.num_in_ports + 1
else error("invalid port type: "..name.." port "..i..) end else error("invalid port type: "..name.." port "..i) end
end end
return def return def

View File

@ -1,6 +1,16 @@
local ffi = FFI local ffi = FFI
ffi.cdef[[
struct Net {
int in_queue;
int num_out_ports_on;
int state;
int update_tick;
struct Gate* gates_update[0];
};
]]
Group = {} Group = {}
function Group.new() function Group.new()

View File

@ -76,11 +76,11 @@ function network_update()
local logic = data[i+5] local logic = data[i+5]
local input = data[i+6] local input = data[i+6]
local global = data[i+7] local global = data[i+7]
local code = data[i+8] --local code = data[i+8]
local numports = tonumber(data[i+9]) local numports = tonumber(data[i+8])
local ports = {} local ports = {}
for a = i+10, numports*5+i+9, 5 do for a = i+9, numports*5+i+8, 5 do
local portd = { local portd = {
type = tonumber(data[a]), type = tonumber(data[a]),
position = vectotable(data[a+1]), position = vectotable(data[a+1]),
@ -93,10 +93,10 @@ function network_update()
if not portd.direction then print(line) end if not portd.direction then print(line) end
end end
local definition = GateDefinition.new(objref, name, desc, init, logic, input, global, ports, code) local definition = GateDefinition.new(objref, name, desc, init, logic, input, global, ports)
Simulation.addgatedefinition(sim, definition) Simulation.addgatedefinition(sim, definition)
i = i + 9 + numports*5 i = i + 8 + numports*5
elseif data[i] == "SL" then elseif data[i] == "SL" then
local wire = Simulation.getwirebyref(sim, tonumber(data[i+1])) local wire = Simulation.getwirebyref(sim, tonumber(data[i+1]))
if wire ~= nil then if wire ~= nil then