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