Drop currently unused REPL part of the API
This commit is contained in:
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package kotlin.script.experimental.repl
|
|
||||||
|
|
||||||
import kotlin.script.experimental.api.*
|
|
||||||
|
|
||||||
interface ReplSnippetChecker {
|
|
||||||
|
|
||||||
suspend operator fun invoke(
|
|
||||||
snippet: ReplSnippetSource,
|
|
||||||
state: ReplStageState<*>,
|
|
||||||
compilationConfiguration: ScriptCompilationConfiguration
|
|
||||||
): ResultWithDiagnostics<Unit>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ReplSnippetCompiler {
|
|
||||||
|
|
||||||
suspend operator fun invoke(
|
|
||||||
snippet: ReplSnippetSource,
|
|
||||||
state: ReplStageState<*>,
|
|
||||||
compilationConfiguration: ScriptCompilationConfiguration
|
|
||||||
): ResultWithDiagnostics<CompiledReplSnippet<*>>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CompiledReplSnippet<ScriptBase : Any> : CompiledScript<ScriptBase>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package kotlin.script.experimental.repl
|
|
||||||
|
|
||||||
import kotlin.script.experimental.api.SourceCode
|
|
||||||
|
|
||||||
interface ReplSnippetSource : SourceCode, ReplSnippetId
|
|
||||||
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package kotlin.script.experimental.repl
|
|
||||||
|
|
||||||
import kotlin.script.experimental.api.EvaluationResult
|
|
||||||
import kotlin.script.experimental.api.ResultWithDiagnostics
|
|
||||||
import kotlin.script.experimental.util.PropertiesCollection
|
|
||||||
|
|
||||||
interface ReplEvaluationEnvironmentKeys
|
|
||||||
|
|
||||||
class ReplEvaluationEnvironment(baseEvaluationEnvironments: Iterable<ReplEvaluationEnvironment>, body: Builder.() -> Unit) :
|
|
||||||
PropertiesCollection(Builder(baseEvaluationEnvironments).apply(body).data) {
|
|
||||||
|
|
||||||
constructor(body: Builder.() -> Unit = {}) : this(emptyList(), body)
|
|
||||||
constructor(
|
|
||||||
vararg baseEvaluationEnvironments: ReplEvaluationEnvironment, body: Builder.() -> Unit = {}
|
|
||||||
) : this(baseEvaluationEnvironments.asIterable(), body)
|
|
||||||
|
|
||||||
class Builder internal constructor(baseEvaluationEnvironments: Iterable<ReplEvaluationEnvironment>) :
|
|
||||||
ReplEvaluationEnvironmentKeys,
|
|
||||||
PropertiesCollection.Builder(baseEvaluationEnvironments)
|
|
||||||
|
|
||||||
companion object : ReplEvaluationEnvironmentKeys
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ReplSnippetEvaluator {
|
|
||||||
|
|
||||||
suspend operator fun invoke(
|
|
||||||
compiledSnippet: CompiledReplSnippet<*>,
|
|
||||||
replEvaluationEnvironment: ReplEvaluationEnvironment
|
|
||||||
): ResultWithDiagnostics<EvaluationResult>
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package kotlin.script.experimental.repl
|
|
||||||
|
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
|
||||||
import kotlin.concurrent.read
|
|
||||||
import kotlin.concurrent.write
|
|
||||||
|
|
||||||
const val REPL_CODE_LINE_FIRST_NO = 1
|
|
||||||
const val REPL_CODE_LINE_FIRST_GEN = 1
|
|
||||||
|
|
||||||
interface ReplSnippetId : Comparable<ReplSnippetId> {
|
|
||||||
val no: Int
|
|
||||||
val generation: Int
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ReplHistoryRecord<out T>(val id: ReplSnippetId, val item: T)
|
|
||||||
|
|
||||||
interface IReplStageHistory<T> : List<ReplHistoryRecord<T>> {
|
|
||||||
|
|
||||||
fun peek(): ReplHistoryRecord<T>? = lock.read { lastOrNull() }
|
|
||||||
|
|
||||||
fun push(id: ReplSnippetId, item: T)
|
|
||||||
|
|
||||||
fun pop(): ReplHistoryRecord<T>?
|
|
||||||
|
|
||||||
fun verifiedPop(id: ReplSnippetId): ReplHistoryRecord<T>? = lock.write {
|
|
||||||
if (lastOrNull()?.id == id) pop()
|
|
||||||
else null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun reset(): Iterable<ReplSnippetId>
|
|
||||||
|
|
||||||
fun resetTo(id: ReplSnippetId): Iterable<ReplSnippetId>
|
|
||||||
|
|
||||||
val lock: ReentrantReadWriteLock
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ReplStageState<T> {
|
|
||||||
val history: IReplStageHistory<T>
|
|
||||||
|
|
||||||
val lock: ReentrantReadWriteLock
|
|
||||||
|
|
||||||
val currentGeneration: Int
|
|
||||||
|
|
||||||
fun getNextLineNo(): Int =
|
|
||||||
history.peek()?.id?.no?.let { it + 1 } ?: REPL_CODE_LINE_FIRST_NO // TODO: it should be more robust downstream (e.g. use atomic)
|
|
||||||
|
|
||||||
fun <StateT : ReplStageState<*>> asState(target: Class<out StateT>): StateT =
|
|
||||||
if (target.isAssignableFrom(this::class.java)) this as StateT
|
|
||||||
else throw IllegalArgumentException("$this is not an expected instance of IReplStageState")
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package kotlin.script.experimental.repl
|
|
||||||
|
|
||||||
import kotlinx.coroutines.experimental.CoroutineScope
|
|
||||||
import kotlinx.coroutines.experimental.runBlocking
|
|
||||||
import kotlin.script.experimental.api.EvaluationResult
|
|
||||||
import kotlin.script.experimental.api.ResultWithDiagnostics
|
|
||||||
import kotlin.script.experimental.api.ScriptCompilationConfiguration
|
|
||||||
import kotlin.script.experimental.util.PropertiesCollection
|
|
||||||
|
|
||||||
interface ReplCommandProcessor {
|
|
||||||
suspend operator fun invoke(
|
|
||||||
command: String,
|
|
||||||
state: ReplStageState<*>
|
|
||||||
): ResultWithDiagnostics<EvaluationResult>
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ReplCommand(val commandName: String, val processor: ReplCommandProcessor)
|
|
||||||
|
|
||||||
interface ReplHostEnvironmentKeys
|
|
||||||
|
|
||||||
class ReplHostEnvironment(baseReplHostEnvironments: Iterable<ReplHostEnvironment>, body: Builder.() -> Unit) :
|
|
||||||
PropertiesCollection(Builder(baseReplHostEnvironments).apply(body).data) {
|
|
||||||
|
|
||||||
constructor(body: Builder.() -> Unit = {}) : this(emptyList(), body)
|
|
||||||
constructor(
|
|
||||||
vararg baseReplHostEnvironments: ReplHostEnvironment, body: Builder.() -> Unit = {}
|
|
||||||
) : this(baseReplHostEnvironments.asIterable(), body)
|
|
||||||
|
|
||||||
class Builder internal constructor(baseReplHostEnvironments: Iterable<ReplHostEnvironment>) :
|
|
||||||
ReplHostEnvironmentKeys,
|
|
||||||
PropertiesCollection.Builder(baseReplHostEnvironments)
|
|
||||||
|
|
||||||
companion object : ReplHostEnvironmentKeys
|
|
||||||
}
|
|
||||||
|
|
||||||
val ReplHostEnvironmentKeys.replCommands by PropertiesCollection.key<List<ReplCommand>>()
|
|
||||||
|
|
||||||
abstract class ReplHost(
|
|
||||||
val environment: ReplHostEnvironment,
|
|
||||||
val checker: ReplSnippetChecker,
|
|
||||||
val compiler: ReplSnippetCompiler,
|
|
||||||
val evaluator: ReplSnippetEvaluator
|
|
||||||
) {
|
|
||||||
open fun <T> runInCoroutineContext(block: suspend CoroutineScope.() -> T): T = runBlocking { block() }
|
|
||||||
|
|
||||||
abstract fun eval(
|
|
||||||
snippet: ReplSnippetSource,
|
|
||||||
state: ReplStageState<*>,
|
|
||||||
scriptCompilationConfiguration: ScriptCompilationConfiguration,
|
|
||||||
replEvaluationEnvironment: ReplEvaluationEnvironment
|
|
||||||
): ResultWithDiagnostics<EvaluationResult>
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user