forth-stuff/State.tl

38 lines
844 B
Plaintext
Raw Normal View History

2021-05-11 06:55:13 +00:00
local Stack = require("Stack")
2021-05-12 08:32:25 +00:00
local InputStream = require("InputStream")
local Dictionary = require("Dictionary")
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-12 08:32:25 +00:00
activeInputStream: InputStream
dictionaries: {Dictionary}
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