Add some things for Dictionaries; expand the definition of ForthState
This commit is contained in:
parent
29952c7355
commit
41276fde68
|
@ -1,2 +1,4 @@
|
|||
.envrc
|
||||
*.nix
|
||||
*.lua
|
||||
!*tlconfig.lua
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
local state = require("ForthState")
|
||||
local ForthDictionary = {}
|
||||
|
||||
|
||||
global type ForthDictionary = record
|
||||
global type Dictionary = record
|
||||
contents: {string: function(State)}
|
||||
end
|
||||
|
||||
|
||||
function Dictionary:define(word: string, instructions: function(State))
|
||||
self.contents[word] = instructions
|
||||
end
|
||||
local dict_mt = {__index = Dictionary}
|
||||
function Dictionary:new(): Dictionary
|
||||
return setmetatable({contents = {}} as Dictionary, dict_mt)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return ForthDictionary
|
||||
|
|
|
@ -7,7 +7,8 @@ local ForthState = {}
|
|||
global type State = record
|
||||
dataStacks: {Stack}
|
||||
compilerStack: Stack
|
||||
|
||||
activeDataStack: Stack
|
||||
interrupts: {function(State)}
|
||||
-- dictionaries: {string:any}
|
||||
end
|
||||
|
||||
|
@ -28,6 +29,10 @@ end
|
|||
function State:changeCompilerStack(compilerStack: Stack)
|
||||
self.compilerStack = compilerStack
|
||||
end
|
||||
function State:changeActiveDataStack(stackIndex: number)
|
||||
assert(stackIndex <= #self.dataStacks and stackIndex > 0)
|
||||
self.activeDataStack = self.dataStacks[stackIndex]
|
||||
end
|
||||
|
||||
local state = State:new()
|
||||
|
||||
|
|
Loading…
Reference in New Issue