[JS SCRIPT] refactor js script infrastructure
- Implement proper script compiler proxy to correctly handle script and its closed-world dependencies - Clean up zoo of JsScriptCompilers
This commit is contained in:
@@ -7,9 +7,9 @@ jvmTarget = "1.6"
|
||||
|
||||
dependencies {
|
||||
compile(project(":kotlin-scripting-common"))
|
||||
compile(project(":compiler:cli-common"))
|
||||
compile(project(":js:js.engines"))
|
||||
compile(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
compileOnly(project(":compiler:backend.js"))
|
||||
compileOnly(project(":compiler:cli-common"))
|
||||
compileOnly(project(":js:js.engines"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
+3
-4
@@ -11,9 +11,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
|
||||
class JsReplEvaluator : ReplEvaluator {
|
||||
//TODO: support println()
|
||||
private val engine = ScriptEngineNashorn()
|
||||
|
||||
override fun createState(lock: ReentrantReadWriteLock): IReplStageState<*> = JsState(lock)
|
||||
override fun createState(lock: ReentrantReadWriteLock): IReplStageState<*> = JsEvaluationState(lock, ScriptEngineNashorn())
|
||||
|
||||
override fun eval(
|
||||
state: IReplStageState<*>,
|
||||
@@ -22,7 +20,8 @@ class JsReplEvaluator : ReplEvaluator {
|
||||
invokeWrapper: InvokeWrapper?
|
||||
): ReplEvalResult {
|
||||
return try {
|
||||
val evalResult = engine.eval<Any?>(compileResult.data as String)
|
||||
val evaluationState = state.asState(JsEvaluationState::class.java)
|
||||
val evalResult = evaluationState.engine.eval<Any?>(compileResult.data as String)
|
||||
ReplEvalResult.ValueResult("result", evalResult, "Any?")
|
||||
} catch (e: Exception) {
|
||||
ReplEvalResult.Error.Runtime("Error while evaluating", e)
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
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.js.engine.ScriptEngine
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.experimental.api.CompiledScript
|
||||
@@ -14,7 +17,7 @@ import kotlin.script.experimental.api.ResultWithDiagnostics
|
||||
import kotlin.script.experimental.api.ScriptCompilationConfiguration
|
||||
import kotlin.script.experimental.api.ScriptEvaluationConfiguration
|
||||
|
||||
class JsState(override val lock: ReentrantReadWriteLock) : IReplStageState<ScriptDescriptor> {
|
||||
abstract class JsState(override val lock: ReentrantReadWriteLock) : IReplStageState<ScriptDescriptor> {
|
||||
override val history: IReplStageHistory<ScriptDescriptor>
|
||||
get() = TODO("not implemented")
|
||||
|
||||
@@ -23,7 +26,18 @@ class JsState(override val lock: ReentrantReadWriteLock) : IReplStageState<Scrip
|
||||
|
||||
}
|
||||
|
||||
class CompiledToJsScript(
|
||||
abstract class JsCompilationState(
|
||||
lock: ReentrantReadWriteLock,
|
||||
val nameTables: NameTables,
|
||||
val dependencies: List<ModuleDescriptor>) : JsState(lock)
|
||||
|
||||
class JsEvaluationState(lock: ReentrantReadWriteLock, val engine: ScriptEngine) : JsState(lock) {
|
||||
override fun dispose() {
|
||||
engine.release()
|
||||
}
|
||||
}
|
||||
|
||||
class JsCompiledScript(
|
||||
val jsCode: String,
|
||||
override val compilationConfiguration: ScriptCompilationConfiguration
|
||||
) : CompiledScript<Any> {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ class JsScriptEvaluator : ScriptEvaluator {
|
||||
scriptEvaluationConfiguration: ScriptEvaluationConfiguration
|
||||
): ResultWithDiagnostics<EvaluationResult> {
|
||||
return try {
|
||||
val evalResult = engine.eval<Any?>((compiledScript as CompiledToJsScript).jsCode)
|
||||
val evalResult = engine.eval<Any?>((compiledScript as JsCompiledScript).jsCode)
|
||||
ResultWithDiagnostics.Success(
|
||||
EvaluationResult(
|
||||
ResultValue.Value(
|
||||
|
||||
Reference in New Issue
Block a user