46 lines
744 B
Plaintext
46 lines
744 B
Plaintext
local ForthStack = require("ForthStack")
|
|
|
|
|
|
local ForthState = {}
|
|
|
|
|
|
global type State = record
|
|
dataStacks: {Stack}
|
|
compilerStack: Stack
|
|
|
|
-- dictionaries: {string:any}
|
|
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
|
|
|
|
function State:changeCompilerStack(compilerStack: Stack)
|
|
self.compilerStack = compilerStack
|
|
end
|
|
|
|
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
|