forth-stuff/ForthState.tl

46 lines
744 B
Plaintext
Raw Normal View History

2021-05-10 06:23:32 +00:00
local ForthStack = require("ForthStack")
2021-05-01 00:58:13 +00:00
2021-05-10 06:23:32 +00:00
local ForthState = {}
global type State = record
dataStacks: {Stack}
compilerStack: Stack
2021-05-01 00:58:13 +00:00
-- dictionaries: {string:any}
2021-05-10 06:23:32 +00:00
end
local state_mt = {__index = State}
function State:new(): State
return setmetatable(
{
dataStacks = {},
compilerStack = Stack:new()
} as State,
state_mt)
end
function State:addDataStack(data: Stack)
table.insert(self.dataStacks, data)
end
2021-05-01 00:58:13 +00:00
2021-05-10 06:23:32 +00:00
function State:changeCompilerStack(compilerStack: Stack)
self.compilerStack = compilerStack
2021-05-01 00:58:13 +00:00
end
2021-05-10 06:23:32 +00:00
local state = State:new()
local stck = Stack:new()
stck:push(1)
stck:push(2)
stck:push(8)
state:addDataStack(stck)
ForthStack.add(state.dataStacks[1])
print(ForthStack.dot(state.dataStacks[1]))
return ForthState