From 0ac3f3e495e6f51dfaa9293a4bc54aaca6f0e2c4 Mon Sep 17 00:00:00 2001 From: Redo Date: Fri, 4 Nov 2022 13:14:05 -0600 Subject: [PATCH] fix errors --- sim/compile.lua | 24 +++--------------------- sim/gatedef.lua | 4 ++-- sim/group.lua | 10 ++++++++++ sim/network.lua | 10 +++++----- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/sim/compile.lua b/sim/compile.lua index b69d83a..c8adce4 100644 --- a/sim/compile.lua +++ b/sim/compile.lua @@ -2,33 +2,15 @@ local ffi = FFI or require("ffi") 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) -- todo: compile some kind of DSL into machine code return code, size end -local net_program_code = Simulation.compile_code( [[ - -]] ) +--local net_program_code = Simulation.compile_code( [[ +-- +--]] ) function Simulation.compile(sim) sim.compilation = { diff --git a/sim/gatedef.lua b/sim/gatedef.lua index c8a9bde..e570665 100644 --- a/sim/gatedef.lua +++ b/sim/gatedef.lua @@ -15,7 +15,7 @@ function GateDefinition.new(objref, name, description, init, logic, input, code, description = collapseescape(description) 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 = { 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 elseif portd.type==PortTypes.input then 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 return def diff --git a/sim/group.lua b/sim/group.lua index 629d2d6..5d371df 100644 --- a/sim/group.lua +++ b/sim/group.lua @@ -1,6 +1,16 @@ 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 = {} function Group.new() diff --git a/sim/network.lua b/sim/network.lua index d99f819..017cf0f 100644 --- a/sim/network.lua +++ b/sim/network.lua @@ -76,11 +76,11 @@ function network_update() local logic = data[i+5] local input = data[i+6] local global = data[i+7] - local code = data[i+8] - local numports = tonumber(data[i+9]) + --local code = data[i+8] + local numports = tonumber(data[i+8]) local ports = {} - for a = i+10, numports*5+i+9, 5 do + for a = i+9, numports*5+i+8, 5 do local portd = { type = tonumber(data[a]), position = vectotable(data[a+1]), @@ -93,10 +93,10 @@ function network_update() if not portd.direction then print(line) 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) - i = i + 9 + numports*5 + i = i + 8 + numports*5 elseif data[i] == "SL" then local wire = Simulation.getwirebyref(sim, tonumber(data[i+1])) if wire ~= nil then