summaryrefslogtreecommitdiff
path: root/src/CoreBindings.kt
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-10 02:26:42 +0200
committernea <nea@nea.moe>2023-08-10 02:26:42 +0200
commitf345fadd492ea5bb09e515d007be438fc08c9b93 (patch)
tree2b2b99dc7e75387ba16cdb43d107bcedf84d4938 /src/CoreBindings.kt
parente4661bf1fecf5a214a020a56b9658dc49565e162 (diff)
downloadnealisp-f345fadd492ea5bb09e515d007be438fc08c9b93.tar.gz
nealisp-f345fadd492ea5bb09e515d007be438fc08c9b93.tar.bz2
nealisp-f345fadd492ea5bb09e515d007be438fc08c9b93.zip
Add imports
Diffstat (limited to 'src/CoreBindings.kt')
-rw-r--r--src/CoreBindings.kt14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/CoreBindings.kt b/src/CoreBindings.kt
index f139e2e..b344dc7 100644
--- a/src/CoreBindings.kt
+++ b/src/CoreBindings.kt
@@ -172,6 +172,19 @@ object CoreBindings {
?: return@externalCall reportError("Unexpected argument $b, expected number")).value
})
}
+ val import = LispData.externalRawCall { context, callsite, stackFrame, args ->
+ if (args.size != 1) {
+ return@externalRawCall context.reportError("import needs at least one argument", callsite)
+ }
+ // TODO: aliased / namespaced imports
+ val moduleName = when (val moduleObject = context.resolveValue(stackFrame, args[0])) {
+ is LispData.Atom -> moduleObject.label
+ is LispData.LispString -> moduleObject.string
+ else -> return@externalRawCall context.reportError("import needs a string or atom as argument", callsite)
+ }
+ context.importModule(moduleName, stackFrame, callsite)
+ return@externalRawCall LispData.LispNil
+ }
fun offerArithmeticTo(bindings: StackFrame) {
bindings.setValueLocal("+", add)
@@ -188,6 +201,7 @@ object CoreBindings {
bindings.setValueLocal("lambda", lambda)
bindings.setValueLocal("defun", defun)
bindings.setValueLocal("seq", seq)
+ bindings.setValueLocal("import", import)
bindings.setValueLocal("debuglog", debuglog)
offerArithmeticTo(bindings)
}