Add ' and EXECUTE
This commit is contained in:
parent
ecdf648d96
commit
804c2a1cca
19
CoreWords.tl
19
CoreWords.tl
|
@ -134,7 +134,24 @@ local function roll(state: State)
|
|||
error("u is not a number")
|
||||
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 addInfo = WordInfo:new(add, false)
|
||||
|
@ -154,6 +171,8 @@ local nipInfo = WordInfo:new(nip, false)
|
|||
|
||||
defineWord(CoreWords, "TUCK", tuck, false)
|
||||
defineWord(CoreWords, "ROLL", roll, false)
|
||||
defineWord(CoreWords, "'", getExecutionToken, false)
|
||||
defineWord(CoreWords, "EXECUTE", execute, false)
|
||||
|
||||
CoreWords:define("+", addInfo)
|
||||
CoreWords:define("-", subInfo)
|
||||
|
|
Loading…
Reference in New Issue