add compile, literal definitions
This commit is contained in:
parent
7fa57cf474
commit
70e8c7e959
15
CoreWords.tl
15
CoreWords.tl
|
@ -162,14 +162,18 @@ local function exitCompileMode(e: Environment)
|
|||
end
|
||||
|
||||
local function compile(env: Environment)
|
||||
|
||||
local stack = env.activeDataStack
|
||||
local f = stack:pop() as function(Environment)
|
||||
table.insert(env.currentDefinition, f)
|
||||
end
|
||||
local function literal(env: Environment)
|
||||
local stack = env.activeDataStack
|
||||
local val = stack:pop()
|
||||
local fun = function(e: Environment)
|
||||
|
||||
|
||||
local s = e.activeDataStack
|
||||
s:push(val)
|
||||
end
|
||||
table.insert(env.currentDefinition, fun)
|
||||
end
|
||||
|
||||
local function postpone(env: Environment)
|
||||
|
@ -197,8 +201,11 @@ defineWord(CoreWords, "TUCK", tuck, false)
|
|||
defineWord(CoreWords, "ROLL", roll, false)
|
||||
defineWord(CoreWords, "'", getExecutionToken, false)
|
||||
defineWord(CoreWords, "EXECUTE", execute, false)
|
||||
defineWord(CoreWords, "[", exitCompileMode, false)
|
||||
defineWord(CoreWords, "[", exitCompileMode, true)
|
||||
defineWord(CoreWords, "]", enterCompileMode, false)
|
||||
defineWord(CoreWords, "COMPILE,", compile, true)
|
||||
defineWord(CoreWords, "LITERAL", literal, true)
|
||||
|
||||
|
||||
CoreWords:define("+", addInfo)
|
||||
CoreWords:define("-", subInfo)
|
||||
|
|
|
@ -46,6 +46,8 @@ local type DataStructures = record
|
|||
recognizers: {function(Environment)}
|
||||
instructionPointer: Pointer
|
||||
running: boolean
|
||||
|
||||
currentDefinition: {function(Environment)}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue