Add instructions

This commit is contained in:
Maple Redleaf
2025-11-21 12:37:58 -06:00
parent f88581ad47
commit 5aab11ddcd
4 changed files with 36 additions and 1 deletions

18
bcinterpreter.lua Normal file
View File

@@ -0,0 +1,18 @@
require("varreg")
require("instructions")
require("util")
local program = {
{
"PRINTV",
"hello",
},
{
"PRINTV",
"world",
},
}
for _, instruction in ipairs(program) do
InstructionTable[string.lower(instruction[1])](Slice(instruction, 2))
end

8
instructions.lua Normal file
View File

@@ -0,0 +1,8 @@
InstructionTable = {
-- Print explicitly stated constants
printv = function(args)
for _, arg in ipairs(args) do
print(arg)
end
end,
}

View File

@@ -1 +0,0 @@
require("varreg.lua")

10
util.lua Normal file
View File

@@ -0,0 +1,10 @@
function Slice(tbl, first, last)
local sliced = {}
first = first or 1
last = last or #tbl
for i = first, last do
sliced[#sliced + 1] = tbl[i]
end
return sliced
end