Implement "legacy" REPL wrappers on top of the "new" scripting infrastructure

This commit is contained in:
Ilya Chernikov
2019-04-30 15:43:33 +02:00
parent 010ae5326d
commit 46915df56f
18 changed files with 631 additions and 127 deletions
@@ -249,4 +249,10 @@ interface CompiledScript<out ScriptBase : Any> {
*/
val otherScripts: List<CompiledScript<*>>
get() = emptyList()
/**
* The name and the type of the script's result field, if any
*/
val resultField: Pair<String, KotlinType>?
get() = null
}
@@ -50,6 +50,13 @@ val ScriptEvaluationConfigurationKeys.providedProperties by PropertiesCollection
*/
val ScriptEvaluationConfigurationKeys.constructorArgs by PropertiesCollection.key<List<Any?>>()
/**
* If the script is a snippet in a REPL, this property expected to contain previous REPL snippets in historical order
* For the first snippet in a REPL an empty list should be passed explicitly
* An array of the previous snippets will be passed to the current snippet constructor
*/
val ScriptEvaluationConfigurationKeys.previousSnippets by PropertiesCollection.key<List<Any>>()
@Deprecated("use scriptsInstancesSharing flag instead", level = DeprecationLevel.ERROR)
val ScriptEvaluationConfigurationKeys.scriptsInstancesSharingMap by PropertiesCollection.key<MutableMap<KClass<*>, EvaluationResult>>()
@@ -101,6 +108,11 @@ sealed class ResultValue {
override fun toString(): String = "$name: $type = $value"
}
class UnitValue(val scriptInstance: Any) : ResultValue() {
override fun toString(): String = "Unit"
}
// TODO: obsolete it, use differently named value in the saving evaluators
object Unit : ResultValue()
}
@@ -75,6 +75,10 @@ open class PropertiesCollection(private val properties: Map<Key<*>, Any?> = empt
data[this] = v
}
fun <T> PropertiesCollection.Key<T>.put(v: T) {
data[this] = v
}
// generic for lists
operator fun <T> PropertiesCollection.Key<in List<T>>.invoke(vararg vals: T) {