diff --git a/CoreWords.tl b/CoreWords.tl index 5c84b14..11178dd 100644 --- a/CoreWords.tl +++ b/CoreWords.tl @@ -83,7 +83,6 @@ end local function skipWhitespace(state: State) local chr = state.activeInputStream:readCurrentCharacter() while (isWhitespace(state, chr)) do - print("SKIPPING WHITESPACE") chr = state.activeInputStream:advanceOffset() end end @@ -91,14 +90,10 @@ end local function parseToken(state: State): string local chr = state.activeInputStream:readCurrentCharacter() local token = "" - print("paresToken called") while(not isWhitespace(state, chr)) do - print("parsing....", chr) token = token..chr chr = state.activeInputStream:advanceOffset() - print(chr) end - print("parsed", token) return token end diff --git a/Dictionary.tl b/Dictionary.tl deleted file mode 100644 index 69ed71d..0000000 --- a/Dictionary.tl +++ /dev/null @@ -1,18 +0,0 @@ -local WordInfo = require("WordInfo") - - -local type Dictionary = record - contents: {string: WordInfo} -end - -function Dictionary:define(word: string, info: WordInfo) - self.contents[word] = info -end -local dict_mt = {__index = Dictionary} -function Dictionary:new(): Dictionary - return setmetatable({contents = {}} as Dictionary, dict_mt) -end - - - -return Dictionary diff --git a/ForthInterpreter.tl b/ForthInterpreter.tl index bab51cc..1ddc98b 100644 --- a/ForthInterpreter.tl +++ b/ForthInterpreter.tl @@ -25,23 +25,20 @@ local skipWhitespace = (CoreWords:lookup("skipWhitespace") as WordInfo).func local parseToken = (CoreWords:lookup("parseToken") as WordInfo).func while(true) do - print("NEW LOOP") skipWhitespace(machineState) local token: string = parseToken(machineState) if isNumber(machineState, token) then machineState.activeDataStack:push(tonumber(token)) - print("ok") else for i, dictionary in ipairs(machineState.dictionaries) do local wordinfo = dictionary:lookup(token) if wordinfo then (wordinfo as WordInfo).func(machineState) - print("ok") - goto ok + goto continue end end print(string.format('%q ?', token)) - ::ok:: + ::continue:: end end diff --git a/Stack.tl b/Stack.tl deleted file mode 100644 index 3849f45..0000000 --- a/Stack.tl +++ /dev/null @@ -1,28 +0,0 @@ - -local type Stack = record - contents: {any} - top: number - push: function(Stack, any) - pop: function(Stack) - new: function(Stack): Stack -end -function Stack:push(val: any) - self.top = self.top + 1 - table.insert(self.contents,val) -end -function Stack:pop(): any - self.top = self.top -1 - if self.top < 0 then - error("Stack underflow") - end - return table.remove(self.contents) -end -local stack_mt = {__index = Stack} -function Stack:new(): Stack - return setmetatable({contents = {}, top = 0} as Stack, stack_mt) -end - - --- operations - -return Stack diff --git a/State.tl b/State.tl deleted file mode 100644 index 458978c..0000000 --- a/State.tl +++ /dev/null @@ -1,37 +0,0 @@ -local Stack = require("Stack") -local InputStream = require("InputStream") -local Dictionary = require("Dictionary") - -local type State = record - dataStacks: {Stack} - compilerStack: Stack - activeDataStack: Stack - interrupts: {function(State)} - activeInputStream: InputStream - dictionaries: {Dictionary} -end - -local state_mt = {__index = State} -function State:new(): State - return setmetatable( - { - dataStacks = {}, - compilerStack = Stack:new() - } as State, - state_mt) -end - -function State:addDataStack(data: Stack) - table.insert(self.dataStacks, data) -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 - - -return State diff --git a/WordInfo.tl b/WordInfo.tl deleted file mode 100644 index 10b550b..0000000 --- a/WordInfo.tl +++ /dev/null @@ -1,14 +0,0 @@ -local State = require("State") - -local type WordInfo = record - func: function(State) - immediate: boolean -end -local wordi_mt = {__index = WordInfo} -function WordInfo:new(funct: function(State), imm: boolean): WordInfo - return setmetatable({func = funct, immediate = imm} as WordInfo, wordi_mt) -end - -return WordInfo - -