Enable disposing environment when code execution is done

This commit is contained in:
2020-03-14 12:52:04 +01:00
parent c7f251cbce
commit cc2d69e259
8 changed files with 64 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ interface Environment {
fun printScopes()
fun setVariable(name: String, value: Value)
fun getVariable(name: String): Value
fun dispose()
fun getRootModule(): Module
}

View File

@@ -7,6 +7,7 @@ import org.pf4j.ExtensionPoint
abstract class ModuleProvider(val path: String) : ExtensionPoint {
open fun onModuleLoad(environment: Environment) {}
open fun beforeModuleDisposal(environment: Environment) {}
open fun dependencies(): List<String> = emptyList()
abstract fun provideModule(interpreter: Interpreter): Module
}

View File

@@ -1,6 +1,9 @@
package io.smnp.ext
import io.smnp.environment.Environment
interface ModuleRegistry {
fun requestModuleProviderForPath(path: String): ModuleProvider?
fun registeredModules(): List<String>
fun disposeModules(environment: Environment)
}

View File

@@ -18,6 +18,9 @@ class CallStack {
fun top() = items.top()
val size: Int
get() = items.size
fun pretty() {
items.asReversed().forEachIndexed { index, item -> println("[${items.size - index - 1}] $item") }
}

View File

@@ -19,6 +19,9 @@ data class CallStackFrame(
fun popScope() = scopes.pop()
val scopesCount: Int
get() = scopes.size
fun setVariable(name: String, value: Value) {
val scope = scopes.lastOrNull { it.containsKey(name) } ?: scopes.top()
scope[name] = value