Extend GeneratorExtensions with previous script, implemt it for JS REPL
also refactor JS REPL for better compatibility with the generic REPL/scripting infrastructure
This commit is contained in:
+4
-4
@@ -29,14 +29,14 @@ import kotlin.script.experimental.host.ScriptingHostConfiguration
|
||||
import kotlin.script.experimental.jvm.JsDependency
|
||||
|
||||
abstract class AbstractJsReplTest : Closeable {
|
||||
protected lateinit var compilationState: JsReplCompilationState
|
||||
protected lateinit var compilerState: JsReplCompilerState
|
||||
protected lateinit var evaluationState: JsEvaluationState
|
||||
|
||||
protected abstract fun createCompilationState(): JsReplCompilationState
|
||||
protected abstract fun createCompilationState(): JsReplCompilerState
|
||||
protected abstract fun createEvaluationState(): JsEvaluationState
|
||||
|
||||
fun compile(codeLine: ReplCodeLine): ReplCompileResult {
|
||||
return JsReplCompiler(environment).compile(compilationState, codeLine)
|
||||
return JsReplCompiler(environment).compile(compilerState, codeLine)
|
||||
}
|
||||
|
||||
fun evaluate(compileResult: ReplCompileResult.CompiledClasses): ReplEvalResult {
|
||||
@@ -45,7 +45,7 @@ abstract class AbstractJsReplTest : Closeable {
|
||||
|
||||
fun reset() {
|
||||
collector.clear()
|
||||
compilationState = createCompilationState()
|
||||
compilerState = createCompilationState()
|
||||
evaluationState = createEvaluationState()
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -31,9 +31,9 @@ class JsReplTestAgainstBinaries : AbstractJsReplTest() {
|
||||
dependencyLoader.saveNames(nameTable)
|
||||
}
|
||||
|
||||
override fun createCompilationState(): JsReplCompilationState {
|
||||
override fun createCompilationState(): JsReplCompilerState {
|
||||
val replState = ReplCodeAnalyzerBase.ResettableAnalyzerState()
|
||||
return JsReplCompilationState(ReentrantReadWriteLock(), dependencyLoader.loadNames(), dependencies, replState, createSymbolTable())
|
||||
return JsReplCompilerState(ReentrantReadWriteLock(), dependencyLoader.loadNames(), dependencies, replState, createSymbolTable())
|
||||
}
|
||||
|
||||
private fun createSymbolTable(): SymbolTable =
|
||||
|
||||
+2
-2
@@ -20,14 +20,14 @@ class JsReplTestAgainstKlib : AbstractJsReplTest() {
|
||||
|
||||
private var dependencyCode: String? = null
|
||||
|
||||
override fun createCompilationState(): JsReplCompilationState {
|
||||
override fun createCompilationState(): JsReplCompilerState {
|
||||
val nameTables = NameTables(emptyList(), mappedNames = mutableMapOf())
|
||||
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl)
|
||||
val dependencyCompiler = JsScriptDependencyCompiler(environment.configuration, nameTables, symbolTable)
|
||||
val dependencies = readLibrariesFromConfiguration(environment.configuration)
|
||||
dependencyCode = dependencyCompiler.compile(dependencies)
|
||||
|
||||
return JsReplCompilationState(
|
||||
return JsReplCompilerState(
|
||||
ReentrantReadWriteLock(),
|
||||
nameTables,
|
||||
dependencies,
|
||||
|
||||
@@ -5,10 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.scripting.repl.js
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.repl.*
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
||||
import org.jetbrains.kotlin.cli.common.repl.IReplStageHistory
|
||||
import org.jetbrains.kotlin.cli.common.repl.IReplStageState
|
||||
import org.jetbrains.kotlin.js.engine.ScriptEngineWithTypedResult
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.reflect.KClass
|
||||
@@ -17,24 +15,17 @@ import kotlin.script.experimental.api.ResultWithDiagnostics
|
||||
import kotlin.script.experimental.api.ScriptCompilationConfiguration
|
||||
import kotlin.script.experimental.api.ScriptEvaluationConfiguration
|
||||
|
||||
abstract class JsState(override val lock: ReentrantReadWriteLock) : IReplStageState<ScriptDescriptor> {
|
||||
override val history: IReplStageHistory<ScriptDescriptor>
|
||||
// NOTE: the state management machinery is not implemented here, since it is unused at the moment in the JS REPL (see JvmReplEvaluatorState for complete implementation, if needed)
|
||||
class JsEvaluationState(override val lock: ReentrantReadWriteLock, val engine: ScriptEngineWithTypedResult) : IReplStageState<Nothing> {
|
||||
override fun dispose() {
|
||||
engine.reset()
|
||||
}
|
||||
|
||||
override val history: IReplStageHistory<Nothing>
|
||||
get() = TODO("not implemented")
|
||||
|
||||
override val currentGeneration: Int
|
||||
get() = TODO("not implemented")
|
||||
|
||||
}
|
||||
|
||||
abstract class JsCompilationState(
|
||||
lock: ReentrantReadWriteLock,
|
||||
val nameTables: NameTables,
|
||||
val dependencies: List<ModuleDescriptor>) : JsState(lock)
|
||||
|
||||
class JsEvaluationState(lock: ReentrantReadWriteLock, val engine: ScriptEngineWithTypedResult) : JsState(lock) {
|
||||
override fun dispose() {
|
||||
engine.reset()
|
||||
}
|
||||
}
|
||||
|
||||
class JsCompiledScript(
|
||||
|
||||
Reference in New Issue
Block a user