summaryrefslogtreecommitdiff
path: root/src/StackFrame.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/StackFrame.kt')
-rw-r--r--src/StackFrame.kt32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/StackFrame.kt b/src/StackFrame.kt
new file mode 100644
index 0000000..66d74b2
--- /dev/null
+++ b/src/StackFrame.kt
@@ -0,0 +1,32 @@
+package moe.nea.lisp
+
+class StackFrame(val parent: StackFrame?) {
+
+ val variables = mutableMapOf<String, LispData>()
+
+ interface MetaKey<T>
+
+ private val meta: MutableMap<MetaKey<*>, Any> = mutableMapOf()
+
+ fun <T : Any> getMeta(key: MetaKey<T>): T? {
+ return meta[key] as? T
+ }
+
+ fun <T : Any> setMeta(key: MetaKey<T>, value: T) {
+ meta[key] = value
+ }
+
+ fun resolveReference(label: String): LispData? =
+ variables[label] ?: parent?.resolveReference(label)
+
+ fun setValueLocal(label: String, value: LispData): LispData {
+ variables[label] = value
+ return value
+ }
+
+ fun fork(): StackFrame {
+ return StackFrame(this)
+ }
+
+
+}