diff options
Diffstat (limited to 'src/Builtins.kt')
-rw-r--r-- | src/Builtins.kt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Builtins.kt b/src/Builtins.kt new file mode 100644 index 0000000..484ea3a --- /dev/null +++ b/src/Builtins.kt @@ -0,0 +1,18 @@ +package moe.nea.lisp + +object Builtins { + val builtinSource = Builtins::class.java.getResourceAsStream("/builtins.lisp")!!.bufferedReader().readText() + val builtinProgram = LispParser.parse("builtins.lisp", builtinSource) + fun loadBuiltins( + lispExecutionContext: LispExecutionContext, + consumer: (String, LispData) -> Unit, + ) { + val stackFrame = lispExecutionContext.genBindings() + stackFrame.setValueLocal("export", LispData.externalRawCall { context, callsite, stackFrame, args -> + val (name) = args + consumer((name as LispAst.Reference).label, context.resolveValue(stackFrame, name)) + return@externalRawCall LispData.LispNil + }) + lispExecutionContext.executeProgram(stackFrame, builtinProgram) + } +}
\ No newline at end of file |