Add ' and EXECUTE

This commit is contained in:
Starfflame 2021-05-13 06:09:05 -05:00
parent ecdf648d96
commit 804c2a1cca
1 changed files with 19 additions and 0 deletions

View File

@ -134,7 +134,24 @@ local function roll(state: State)
error("u is not a number") error("u is not a number")
end end
end end
local function getExecutionToken(state: State)
local stack = getActiveDataStack(state)
skipWhitespace(state)
local name: string = parseToken(state)
for _, dictionary in ipairs(state.dictionaries) do
local wordinfo = dictionary:lookup(name)
if wordinfo then
stack:push((wordinfo as WordInfo).func)
break
end
end
end
local function execute(state: State)
local stack = getActiveDataStack(state)
local func: function(State) = stack:pop() as function(State)
func(state)
end
local CoreWords = Dictionary:new() local CoreWords = Dictionary:new()
local addInfo = WordInfo:new(add, false) local addInfo = WordInfo:new(add, false)
@ -154,6 +171,8 @@ local nipInfo = WordInfo:new(nip, false)
defineWord(CoreWords, "TUCK", tuck, false) defineWord(CoreWords, "TUCK", tuck, false)
defineWord(CoreWords, "ROLL", roll, false) defineWord(CoreWords, "ROLL", roll, false)
defineWord(CoreWords, "'", getExecutionToken, false)
defineWord(CoreWords, "EXECUTE", execute, false)
CoreWords:define("+", addInfo) CoreWords:define("+", addInfo)
CoreWords:define("-", subInfo) CoreWords:define("-", subInfo)