diff --git a/.gitignore b/.gitignore index e985a99..422d884 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .envrc *.nix +*.lua +!*tlconfig.lua diff --git a/ForthDictionary.tl b/ForthDictionary.tl index f6d0c09..2352ebb 100644 --- a/ForthDictionary.tl +++ b/ForthDictionary.tl @@ -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 diff --git a/ForthState.tl b/ForthState.tl index 2534d33..5d06a1c 100644 --- a/ForthState.tl +++ b/ForthState.tl @@ -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()