From 39f1849edcaa9005814525cd13f76a5daaa15ae0 Mon Sep 17 00:00:00 2001 From: nea Date: Mon, 21 Aug 2023 19:41:29 +0200 Subject: Foreign objects --- TestOutput.xml | 4 ++-- src/CoreBindings.kt | 2 ++ src/LispData.kt | 2 +- src/LispExecutionContext.kt | 1 - test/res/scratch.lisp | 11 +++++++++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/TestOutput.xml b/TestOutput.xml index 87243da..cf84e29 100644 --- a/TestOutput.xml +++ b/TestOutput.xml @@ -1,4 +1,4 @@ - thing.string is LispData.LispHash -> thing.map.asIterable().joinToString(", ", "{", "}") { it.key + ": " + it.value } is LispData.LispNumber -> thing.value.toString() + is LispData.ForeignObject<*> -> "" is LispData.LispInterpretedCallable -> ""} ${thing.argNames} ${thing.body.toSource()}>" } } @@ -225,6 +226,7 @@ object CoreBindings { LispData.LispNil -> LispData.Atom("nil") is LispData.LispHash -> LispData.Atom("hash") is LispData.LispNode -> LispData.Atom("ast") + is LispData.ForeignObject<*> -> LispData.Atom("foreign") is LispData.LispNumber -> LispData.Atom("number") is LispData.LispString -> LispData.Atom("string") } diff --git a/src/LispData.kt b/src/LispData.kt index ea3af32..61c2b76 100644 --- a/src/LispData.kt +++ b/src/LispData.kt @@ -8,6 +8,7 @@ sealed class LispData { data class LispNumber(val value: Double) : LispData() data class LispNode(val node: LispAst.LispNode) : LispData() data class LispHash(val map: Map) : LispData() + data class ForeignObject(val obj: T) : LispData() class LispList(val elements: List) : LispData() sealed class LispExecutable() : LispData() { abstract fun execute( @@ -56,7 +57,6 @@ sealed class LispData { } } - companion object { fun externalRawCall( name: String, diff --git a/src/LispExecutionContext.kt b/src/LispExecutionContext.kt index 306e111..0a1dc41 100644 --- a/src/LispExecutionContext.kt +++ b/src/LispExecutionContext.kt @@ -36,7 +36,6 @@ class LispExecutionContext() { return testSuite } - fun registerModule(moduleName: String, program: LispAst.Program) { if (moduleName in unloadedModules || moduleName in modules) { error("Cannot register already registered module $moduleName") diff --git a/test/res/scratch.lisp b/test/res/scratch.lisp index 3fc6ed7..95595b7 100644 --- a/test/res/scratch.lisp +++ b/test/res/scratch.lisp @@ -6,14 +6,21 @@ (debuglog "a" a) (debuglog "..." ...))) (testlog :test :work :whatever) -(def helloworld (pure "hello world")) +(def helloworld + (pure "hello world")) (debuglog helloworld (helloworld)) (debuglog "+" (+ 1.2 15)) (debuglog "-" (- 1 3)) (debuglog "*" (* 10 10)) (debuglog "/" (/ 1 3 2)) (debuglog "============") -(defun testsomething (c) (debuglog (if! c (seq (debuglog "left evaluated") (return "truthy value")) "falsey value"))) +(defun testsomething (c) + (debuglog + (if! c + (seq + (debuglog "left evaluated") + (return "truthy value")) + "falsey value"))) (testsomething true) (testsomething false) (noop) -- cgit