rename some variables and begin compiled sim c code
This commit is contained in:
		| @@ -3,34 +3,7 @@ local ffi = FFI or require("ffi") | ||||
| Simulation = Simulation or {} | ||||
|  | ||||
| ffi.cdef[[ | ||||
| 	struct Wire { | ||||
| 		int objref; | ||||
| 		int layer; | ||||
| 		struct Net* group; | ||||
| 		int bounds[6]; | ||||
| 	}; | ||||
| 	 | ||||
| 	struct Port { | ||||
| 		bool state; | ||||
| 		char type; | ||||
| 		struct Gate* gate; | ||||
| 		struct Net* group; | ||||
| 	}; | ||||
| 	 | ||||
| 	struct Gate { | ||||
| 		int logic_ref; | ||||
| 		bool in_queue; | ||||
| 		struct Port ports[?]; | ||||
| 	}; | ||||
| 	 | ||||
| 	struct Net { | ||||
| 		bool state; | ||||
| 		bool in_queue; | ||||
| 		int updatetick; | ||||
| 		int state_num; | ||||
| 		int num_gates_update; | ||||
| 		struct Gate* gates_update[?]; | ||||
| 	}; | ||||
| ]] | ||||
|  | ||||
| function Simulation.compile(sim) | ||||
|   | ||||
							
								
								
									
										7
									
								
								sim/compiled_sim.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								sim/compiled_sim.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
|  | ||||
| void sim_init(int num_gates, int num_nets); | ||||
| void sim_add_gate(); | ||||
| void sim_add_net(); | ||||
| void sim_tick(); | ||||
| void sim_get_net_state(int objref); | ||||
| void sim_get_port_state(int objref, int index); | ||||
| @@ -60,7 +60,7 @@ function Gate.queue(gate, delay) | ||||
| end | ||||
|  | ||||
| function Gate.gettick(gate) | ||||
| 	return GSim.currenttick | ||||
| 	return GSim.current_tick | ||||
| end | ||||
|  | ||||
| function Gate.getdefinition(gate) | ||||
|   | ||||
| @@ -5,7 +5,7 @@ function Group.new() | ||||
| 	local o = { | ||||
| 		state = false, | ||||
| 		fxstate = false, | ||||
| 		updatetick = 0, | ||||
| 		update_tick = 0, | ||||
| 		wires = {}, | ||||
| 		out_ports = {}, | ||||
| 		in_ports = {}, | ||||
| @@ -179,7 +179,7 @@ function Group.setstate(group, state) | ||||
| 		local sim = GSim | ||||
| 		 | ||||
| 		group.state = state | ||||
| 		group.updatetick = sim.currenttick | ||||
| 		group.update_tick = sim.current_tick | ||||
| 		 | ||||
| 		for k, gate in ipairs(group.gates_update) do | ||||
| 			Simulation.queuegate(sim, gate) | ||||
|   | ||||
| @@ -38,14 +38,14 @@ function Port.isrising(port) | ||||
| 	if port.group == nil then | ||||
| 		return false | ||||
| 	end | ||||
| 	return port.group.state and (port.group.updatetick == GSim.currenttick) | ||||
| 	return port.group.state and (port.group.update_tick == GSim.current_tick) | ||||
| end | ||||
|  | ||||
| function Port.isfalling(port) | ||||
| 	if port.group == nil then | ||||
| 		return false | ||||
| 	end | ||||
| 	return port.group.state == false and (port.updatetick == GSim.currenttick) | ||||
| 	return port.group.state == false and (port.group.update_tick == GSim.current_tick) | ||||
| end | ||||
|  | ||||
| function Port.getgate(port) | ||||
|   | ||||
| @@ -23,7 +23,7 @@ function Simulation.new(sim) | ||||
| 		 | ||||
| 		callbacks = nil, | ||||
| 		 | ||||
| 		currenttick = 0 | ||||
| 		current_tick = 0, | ||||
| 	} | ||||
| 	setmetatable(o, sim) | ||||
| 	sim.__index = sim | ||||
| @@ -245,7 +245,7 @@ function Simulation.queuegate(sim, gate) | ||||
| end | ||||
|  | ||||
| function Simulation.queuegatelater(sim, gate, delay) | ||||
| 	local tick = sim.currenttick + delay | ||||
| 	local tick = sim.current_tick + delay | ||||
| 	if sim.tickqueue[tick] == nil then | ||||
| 		sim.tickqueue[tick] = {} | ||||
| 	end | ||||
| @@ -322,11 +322,11 @@ function Simulation.tick(sim) | ||||
| 		sim.inputqueue_nonempty = false | ||||
| 	end | ||||
| 	 | ||||
| 	if sim.tickqueue[sim.currenttick] ~= nil then | ||||
| 		for i, gate in pairs(sim.tickqueue[sim.currenttick]) do | ||||
| 	if sim.tickqueue[sim.current_tick] ~= nil then | ||||
| 		for i, gate in pairs(sim.tickqueue[sim.current_tick]) do | ||||
| 			Simulation.queuegate(sim, gate) | ||||
| 		end | ||||
| 		sim.tickqueue[sim.currenttick] = nil | ||||
| 		sim.tickqueue[sim.current_tick] = nil | ||||
| 	end | ||||
| 	 | ||||
| 	for k, gate in ipairs(sim.gatequeue) do | ||||
| @@ -335,7 +335,7 @@ function Simulation.tick(sim) | ||||
| 	end | ||||
| 	sim.gatequeue = {} | ||||
| 	 | ||||
| 	sim.currenttick = sim.currenttick + 1 | ||||
| 	sim.current_tick = sim.current_tick + 1 | ||||
| end | ||||
|  | ||||
| function Simulation.sendfxupdate(sim) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Redo0
					Redo0