summaryrefslogtreecommitdiff
path: root/src/LispData.kt
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-09 17:05:46 +0200
committernea <nea@nea.moe>2023-08-09 17:05:46 +0200
commitf3600dacea3e38cd541bf57076f8a7141987e10b (patch)
treec22645458e388a39a8d3a1e77cb261b4b69c1db2 /src/LispData.kt
parentb530d6360308ac1f68cf2508fa5bd4a085a8bec0 (diff)
downloadnealisp-f3600dacea3e38cd541bf57076f8a7141987e10b.tar.gz
nealisp-f3600dacea3e38cd541bf57076f8a7141987e10b.tar.bz2
nealisp-f3600dacea3e38cd541bf57076f8a7141987e10b.zip
Add addition
Diffstat (limited to 'src/LispData.kt')
-rw-r--r--src/LispData.kt32
1 files changed, 7 insertions, 25 deletions
diff --git a/src/LispData.kt b/src/LispData.kt
index 1f13ad3..11a2451 100644
--- a/src/LispData.kt
+++ b/src/LispData.kt
@@ -2,17 +2,11 @@ package moe.nea.lisp
sealed class LispData {
- fun <T : Any> lispCastObject(lClass: LispClass<T>): LispObject<T>? {
- if (this !is LispObject<*>) return null
- if (this.handler != lClass) return null
- return this as LispObject<T>
- }
-
object LispNil : LispData()
data class Atom(val label: String) : LispData()
+ data class LispString(val string: String) : LispData()
+ data class LispNumber(val value: Double) : LispData()
data class LispNode(val node: LispAst.LispNode) : LispData()
- data class LispNumber(val number: Double) : LispData()
- data class LispObject<T : Any>(val data: T, val handler: LispClass<T>) : LispData()
sealed class LispExecutable() : LispData() {
abstract fun execute(
executionContext: LispExecutionContext,
@@ -22,9 +16,7 @@ sealed class LispData {
): LispData
}
-
- abstract class JavaExecutable : LispExecutable() {
- }
+ abstract class JavaExecutable : LispExecutable()
data class LispInterpretedCallable(
val declarationStackFrame: StackFrame,
@@ -39,7 +31,10 @@ sealed class LispData {
args: List<LispAst.LispNode>
): LispData {
if (argNames.size != args.size) {
- TODO("ERROR")
+ return executionContext.reportError(
+ "Expected ${argNames.size} arguments, got ${args.size} instead",
+ callsite
+ )
}
val invocationFrame = declarationStackFrame.fork()
@@ -50,21 +45,8 @@ sealed class LispData {
}
}
- interface LispClass<T : Any> {
- fun access(obj: T, name: String): LispData
- fun instantiate(obj: T) = LispObject(obj, this)
- }
-
- object LispStringClass : LispClass<String> {
- override fun access(obj: String, name: String): LispData {
- return LispNil
- }
- }
companion object {
- fun string(value: String): LispObject<String> =
- LispStringClass.instantiate(value)
-
fun externalRawCall(callable: (context: LispExecutionContext, callsite: LispAst.LispNode, stackFrame: StackFrame, args: List<LispAst.LispNode>) -> LispData): LispExecutable {
return object : JavaExecutable() {
override fun execute(