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:
Ilya Chernikov
2021-01-07 18:15:05 +01:00
parent 83da5f61fd
commit bac6a7346e
10 changed files with 89 additions and 47 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibility
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.ir.expressions.IrDelegatingConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
import org.jetbrains.kotlin.ir.util.StubGeneratorExtensions
import org.jetbrains.kotlin.psi.KtPureClassOrObject
import org.jetbrains.kotlin.resolve.scopes.MemberScope
@@ -39,4 +40,6 @@ open class GeneratorExtensions : StubGeneratorExtensions() {
open val shouldPreventDeprecatedIntegerValueTypeLiteralConversion: Boolean
get() = false
open fun getPreviousScripts(): List<IrScriptSymbol> = emptyList()
}
@@ -39,7 +39,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
fun generateScriptDeclaration(ktScript: KtScript): IrDeclaration? {
val descriptor = getOrFail(BindingContext.DECLARATION_TO_DESCRIPTOR, ktScript) as ScriptDescriptor
val existedScripts = context.symbolTable.listExistedScripts()
val previousScripts = context.extensions.getPreviousScripts()
return context.symbolTable.declareScript(descriptor).buildWithScope { irScript ->
@@ -54,7 +54,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
// TODO: since script could reference instances of previous one their receivers have to be enlisted in its scope
// Remove this code once script is no longer represented by Class
existedScripts.forEach {
previousScripts.forEach {
if (it.owner != irScript && it.descriptor !in importedScripts) {
context.symbolTable.introduceValueParameter(it.owner.thisReceiver)
}
@@ -117,7 +117,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
valueParameter to irProperty.symbol
}
irScript.earlierScripts = existedScripts
irScript.earlierScripts = previousScripts
for (d in ktScript.declarations) {
when (d) {