From 804c2a1cca2a607a6186cb255f30edcbfc34e137 Mon Sep 17 00:00:00 2001 From: Starfflame Date: Thu, 13 May 2021 06:09:05 -0500 Subject: [PATCH] Add ' and EXECUTE --- CoreWords.tl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CoreWords.tl b/CoreWords.tl index b0a1c04..82b106c 100644 --- a/CoreWords.tl +++ b/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)