add support for string literals on data stack

This commit is contained in:
Starfflame 2021-07-12 20:33:19 -05:00
parent ac10418230
commit ecd663320a
2 changed files with 13 additions and 1 deletions

View File

@ -11,7 +11,7 @@ function CoreHelpers.defineWord(dict: Dictionary, str: string, func: function(En
end end
function CoreHelpers.standardInputRefill(): string function CoreHelpers.standardInputRefill(): string
io.write("\n") io.write("\nok> ")
local input = io.read().."\n" local input = io.read().."\n"
return input return input
end end

View File

@ -327,6 +327,17 @@ local function forthRepeat(e: Environment)
patchBranch(e) patchBranch(e)
end end
local function stringLiteral(e: Environment)
local str: string | nil = ""
local chr: string | nil = ""
if not e.activeInputStream:curr() then e.activeDataStack:push("") end
while(not (chr == "\"") and chr ~= nil) do
str = str..(chr as string)
chr = e.activeInputStream:next()
end
e.activeInputStream:next()
e.activeDataStack:push(str as string)
end
local CoreWords = Dictionary:new() local CoreWords = Dictionary:new()
local addInfo = WordInfo:new(add, false) local addInfo = WordInfo:new(add, false)
@ -373,6 +384,7 @@ defineWord(CoreWords,"=", cmpe, false)
defineWord(CoreWords,">=", cmpgte, false) defineWord(CoreWords,">=", cmpgte, false)
defineWord(CoreWords,">", cmpgt, false) defineWord(CoreWords,">", cmpgt, false)
defineWord(CoreWords,"<>", cmpne, false) defineWord(CoreWords,"<>", cmpne, false)
defineWord(CoreWords,"S\"", stringLiteral, false)
CoreWords:define("+", addInfo) CoreWords:define("+", addInfo)