Enable disposing environment when code execution is done
This commit is contained in:
@@ -19,6 +19,7 @@ interface Environment {
|
||||
fun printScopes()
|
||||
fun setVariable(name: String, value: Value)
|
||||
fun getVariable(name: String): Value
|
||||
fun dispose()
|
||||
|
||||
fun getRootModule(): Module
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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") }
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user