Add some things for Dictionaries; expand the definition of ForthState

This commit is contained in:
Starfflame 2021-05-10 20:43:33 -05:00
parent 29952c7355
commit 41276fde68
3 changed files with 22 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.envrc
*.nix
*.lua
!*tlconfig.lua

View File

@ -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

View File

@ -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()