diff --git a/CoreWords.tl b/CoreWords.tl new file mode 100644 index 0000000..3d5e870 --- /dev/null +++ b/CoreWords.tl @@ -0,0 +1,6 @@ +local Dict = require("Dictionary") +local Stack = require("Stack") + + + + diff --git a/ForthDictionary.tl b/Dictionary.tl similarity index 62% rename from ForthDictionary.tl rename to Dictionary.tl index 8f48fa3..bbd74c2 100644 --- a/ForthDictionary.tl +++ b/Dictionary.tl @@ -1,10 +1,8 @@ -local state = require("ForthState") -local wordinfo = require("ForthWordInfo") -local ForthDictionary = {} +local State = require("State") +local WordInfo = require("WordInfo") - -global type Dictionary = record +local type Dictionary = record contents: {string: WordInfo} end @@ -18,4 +16,4 @@ end -return ForthDictionary +return Dictionary diff --git a/ForthStack.tl b/Stack.tl similarity index 53% rename from ForthStack.tl rename to Stack.tl index d9c2a95..3849f45 100644 --- a/ForthStack.tl +++ b/Stack.tl @@ -1,8 +1,5 @@ -local ForthStack = {} - - -global type Stack = record +local type Stack = record contents: {any} top: number push: function(Stack, any) @@ -27,25 +24,5 @@ end -- operations -function ForthStack.add(stack: Stack) - local a: any =stack:pop() - local b: any=stack:pop() - if a is number and b is number then - local c=a+b - stack:push(c) - else - error("invalid operands for add operation!") - end -end -function ForthStack.dot(s: Stack) - print(s:pop()) -end -local s = Stack:new() -s:push(1) -s:push(4) -ForthStack.add(s) -print(ForthStack.dot(s)) - - -return ForthStack +return Stack diff --git a/ForthState.tl b/State.tl similarity index 68% rename from ForthState.tl rename to State.tl index 5d06a1c..2631dec 100644 --- a/ForthState.tl +++ b/State.tl @@ -1,10 +1,9 @@ -local ForthStack = require("ForthStack") +local Stack = require("Stack") -local ForthState = {} -global type State = record +local type State = record dataStacks: {Stack} compilerStack: Stack activeDataStack: Stack @@ -34,17 +33,8 @@ function State:changeActiveDataStack(stackIndex: number) self.activeDataStack = self.dataStacks[stackIndex] end -local state = State:new() - -local stck = Stack:new() -stck:push(1) -stck:push(2) -stck:push(8) -state:addDataStack(stck) -ForthStack.add(state.dataStacks[1]) -print(ForthStack.dot(state.dataStacks[1])) -return ForthState +return State diff --git a/ForthWordInfo.tl b/WordInfo.tl similarity index 61% rename from ForthWordInfo.tl rename to WordInfo.tl index e28d39f..a287395 100644 --- a/ForthWordInfo.tl +++ b/WordInfo.tl @@ -1,9 +1,6 @@ -local state = require("ForthState") +local State = require("State") -local ForthWordInfo = {} - - -global type WordInfo = record +local type WordInfo = record func: function(State) immediate: boolean end @@ -12,9 +9,6 @@ function WordInfo:new(funct: State, imm: boolean): WordInfo return setmetatable({func = funct, immediate = imm} as WordInfo, wordi_mt) end - -local s = State:new() -print(s) -return ForthWordInfo +return WordInfo