blob: 6ca60e96d59432edf540bd5a7e16ecdab60e5f36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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 ->
args.forEach { name ->
consumer((name as LispAst.Reference).label, context.resolveValue(stackFrame, name))
}
return@externalRawCall LispData.LispNil
})
lispExecutionContext.executeProgram(stackFrame, builtinProgram)
}
}
|