add compile, literal definitions

This commit is contained in:
Starfflame 2021-05-25 03:07:03 -05:00
parent 7fa57cf474
commit 70e8c7e959
2 changed files with 13 additions and 4 deletions

View File

@ -162,14 +162,18 @@ local function exitCompileMode(e: Environment)
end end
local function compile(env: Environment) local function compile(env: Environment)
local stack = env.activeDataStack
local f = stack:pop() as function(Environment)
table.insert(env.currentDefinition, f)
end end
local function literal(env: Environment) local function literal(env: Environment)
local stack = env.activeDataStack local stack = env.activeDataStack
local val = stack:pop()
local fun = function(e: Environment) local fun = function(e: Environment)
local s = e.activeDataStack
s:push(val)
end end
table.insert(env.currentDefinition, fun)
end end
local function postpone(env: Environment) local function postpone(env: Environment)
@ -197,8 +201,11 @@ defineWord(CoreWords, "TUCK", tuck, false)
defineWord(CoreWords, "ROLL", roll, false) defineWord(CoreWords, "ROLL", roll, false)
defineWord(CoreWords, "'", getExecutionToken, false) defineWord(CoreWords, "'", getExecutionToken, false)
defineWord(CoreWords, "EXECUTE", execute, false) defineWord(CoreWords, "EXECUTE", execute, false)
defineWord(CoreWords, "[", exitCompileMode, false) defineWord(CoreWords, "[", exitCompileMode, true)
defineWord(CoreWords, "]", enterCompileMode, false) defineWord(CoreWords, "]", enterCompileMode, false)
defineWord(CoreWords, "COMPILE,", compile, true)
defineWord(CoreWords, "LITERAL", literal, true)
CoreWords:define("+", addInfo) CoreWords:define("+", addInfo)
CoreWords:define("-", subInfo) CoreWords:define("-", subInfo)

View File

@ -46,6 +46,8 @@ local type DataStructures = record
recognizers: {function(Environment)} recognizers: {function(Environment)}
instructionPointer: Pointer instructionPointer: Pointer
running: boolean running: boolean
currentDefinition: {function(Environment)}
end end
end end