Initial
This commit is contained in:
commit
d4d0fba880
7 changed files with 129 additions and 0 deletions
65
mainc.lua
Normal file
65
mainc.lua
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
local result = ""
|
||||
|
||||
local function compile_and_run(source)
|
||||
source = string.format([[
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
%s
|
||||
}
|
||||
]],source)
|
||||
print(source.."\n")
|
||||
local file = io.open("main.c","w")
|
||||
file:write(source)
|
||||
file:close()
|
||||
os.execute("gcc main.c")
|
||||
os.execute("./a.out")
|
||||
end
|
||||
|
||||
local instructions = {
|
||||
["add (%d+) (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["sub (%d+) (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["mul (%d+) (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["shl (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["shr (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["bor (%d+) (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["band (%d+) (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["li (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["li (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end,
|
||||
["li (%d+) (%d+)"] = function(l,d,a,b)
|
||||
|
||||
end
|
||||
}
|
||||
|
||||
local source = {string.format("int32_t registers = {%s}",string.rep("0",0,","))}
|
||||
|
||||
local input = io.open("main.funny")
|
||||
local index = 1
|
||||
for line in input:read("a"):gmatch("[^\n\r]") do
|
||||
table.insert(string.format("instruction%i:",index)) -- add the goto label for the line
|
||||
instruction = instruction + 1
|
||||
local target
|
||||
for pattern,callback in pairs(instructions) do
|
||||
line:match(pattern)
|
||||
end
|
||||
end
|
||||
compile_and_run(table.concat(source,"\n"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue