forth-stuff/State.tl

41 lines
737 B
Plaintext
Raw Normal View History

2021-05-11 06:55:13 +00:00
local Stack = require("Stack")
2021-05-01 00:58:13 +00:00
2021-05-10 06:23:32 +00:00
2021-05-11 06:55:13 +00:00
local type State = record
2021-05-10 06:23:32 +00:00
dataStacks: {Stack}
compilerStack: Stack
activeDataStack: Stack
interrupts: {function(State)}
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
function State:changeActiveDataStack(stackIndex: number)
assert(stackIndex <= #self.dataStacks and stackIndex > 0)
self.activeDataStack = self.dataStacks[stackIndex]
end
2021-05-10 06:23:32 +00:00
2021-05-11 06:55:13 +00:00
return State