add support for string literals on data stack
This commit is contained in:
parent
ac10418230
commit
ecd663320a
|
@ -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
|
||||||
|
|
12
CoreWords.tl
12
CoreWords.tl
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue