DPC compiler

A compiler for a computer (Dual Photon Computer) in a game named The Powder Toy
 avatar
unknown
lua
8 months ago
1.3 kB
15
No Index
--USER INPUT HERE. Write the name of the file you want to compile here. It should be in the same folder as this script (dunno if it should but better do it)
io.input("program.txt")


for i=0, sim.partCount() do
	if ((sim.partProperty(i, 0) == 132) and (sim.partProperty(i, 2) == 6969)) then
		qrtzIndex = i
		goto particleFound
	end
end

print("ERROR: No memory found")
do return end --Terminates the script

::particleFound::

local memoryXPos, memoryYPos = sim.partPosition(qrtzIndex)
qrtzIndex, _ = nil
memoryYPos = memoryYPos - 1

local operationTable = {
	opand = 1,
	opor = 2,
	opxor = 3,
	opnot = 4,
	subcolor = 5,
	rshift = 8,
	bshift = 9,
	random = 10,
	setvar1 = 12,
	setvar2 = 13,
	outputvar = 14,
	outputsignal = 15,
	null = 31
}

inputLine = io.read("*line")
line = 1

repeat
	operation = string.find(inputLine, " ")
	if operation == nil then
		print("ERROR: Invalid operation at line: "..line..". Terminating script...")
		do return end
	end
	operation = operationTable[string.lower(string.sub(inputLine, 1, operation - 1))]
	address = bit.lshift(string.sub(inputLine, string.find(inputLine, " ") + 1), 5)
	sim.partProperty(sim.partID(memoryXPos, memoryYPos), 2, operation + address)
	memoryXPos = memoryXPos + 1
	inputLine = io.read("*line")
	line = line + 1
until inputLine == nil

print("Successfully compiled")
Editor is loading...
Leave a Comment