Pass earlier scripts as array, removes 255-lines repl limitation
fixes #KT-10060
This commit is contained in:
@@ -158,7 +158,7 @@ public class ScriptCodegen extends MemberCodegen<KtScript> {
|
||||
|
||||
iv.load(0, classType);
|
||||
|
||||
int valueParamStart = context.getEarlierScripts().size() + 1;
|
||||
int valueParamStart = context.getEarlierScripts().isEmpty() ? 1 : 2; // this + array of earlier scripts if not empty
|
||||
|
||||
List<ValueParameterDescriptor> valueParameters = scriptDescriptor.getUnsubstitutedPrimaryConstructor().getValueParameters();
|
||||
for (ValueParameterDescriptor superclassParam: ctorDesc.getValueParameters()) {
|
||||
@@ -185,18 +185,20 @@ public class ScriptCodegen extends MemberCodegen<KtScript> {
|
||||
FrameMap frameMap = new FrameMap();
|
||||
frameMap.enterTemp(OBJECT_TYPE);
|
||||
|
||||
for (ScriptDescriptor importedScript : context.getEarlierScripts()) {
|
||||
frameMap.enter(importedScript, OBJECT_TYPE);
|
||||
}
|
||||
|
||||
int offset = 1;
|
||||
if (!context.getEarlierScripts().isEmpty()) {
|
||||
int scriptsParamIndex = frameMap.enterTemp(AsmUtil.getArrayType(OBJECT_TYPE));
|
||||
|
||||
for (ScriptDescriptor earlierScript : context.getEarlierScripts()) {
|
||||
Type earlierClassType = typeMapper.mapClass(earlierScript);
|
||||
iv.load(0, classType);
|
||||
iv.load(offset, earlierClassType);
|
||||
offset += earlierClassType.getSize();
|
||||
iv.putfield(classType.getInternalName(), context.getScriptFieldName(earlierScript), earlierClassType.getDescriptor());
|
||||
int earlierScriptIndex = 0;
|
||||
for (ScriptDescriptor earlierScript : context.getEarlierScripts()) {
|
||||
Type earlierClassType = typeMapper.mapClass(earlierScript);
|
||||
iv.load(0, classType);
|
||||
iv.load(scriptsParamIndex, earlierClassType);
|
||||
iv.aconst(earlierScriptIndex++);
|
||||
iv.aload(OBJECT_TYPE);
|
||||
iv.checkcast(earlierClassType);
|
||||
iv.putfield(classType.getInternalName(), context.getScriptFieldName(earlierScript), earlierClassType.getDescriptor());
|
||||
}
|
||||
}
|
||||
|
||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, methodContext, state, this);
|
||||
|
||||
@@ -1477,8 +1477,8 @@ public class KotlinTypeMapper {
|
||||
|
||||
sw.writeParametersStart();
|
||||
|
||||
for (ScriptDescriptor importedScript : importedScripts) {
|
||||
writeParameter(sw, importedScript.getDefaultType(), /* callableDescriptor = */ null);
|
||||
if (importedScripts.size() > 0) {
|
||||
writeParameter(sw, DescriptorUtilsKt.getModule(script).getBuiltIns().getArray().getDefaultType(), null);
|
||||
}
|
||||
|
||||
for (ValueParameterDescriptor valueParameter : script.getUnsubstitutedPrimaryConstructor().getValueParameters()) {
|
||||
|
||||
+8
-4
@@ -74,10 +74,14 @@ open class GenericReplEvaluator(val baseClasspath: Iterable<File>,
|
||||
val useScriptArgs = currentScriptArgs?.scriptArgs
|
||||
val useScriptArgsTypes = currentScriptArgs?.scriptArgsTypes?.map { it.java }
|
||||
|
||||
val constructorParams: Array<Class<*>> = (historyActor.effectiveHistory.map { it.klass.java } +
|
||||
(useScriptArgs?.mapIndexed { i, it -> useScriptArgsTypes?.getOrNull(i) ?: it?.javaClass ?: Any::class.java } ?: emptyList())
|
||||
).toTypedArray()
|
||||
val constructorArgs: Array<Any?> = (historyActor.effectiveHistory.map { it.instance } + useScriptArgs.orEmpty()).toTypedArray()
|
||||
val hasHistory = historyActor.effectiveHistory.isNotEmpty()
|
||||
|
||||
val constructorParams: Array<Class<*>> = (if (hasHistory) arrayOf<Class<*>>(Array<Any>::class.java) else emptyArray<Class<*>>()) +
|
||||
(useScriptArgs?.mapIndexed { i, it -> useScriptArgsTypes?.getOrNull(i) ?: it?.javaClass ?: Any::class.java } ?: emptyList())
|
||||
|
||||
val constructorArgs: Array<out Any?> = if (hasHistory) arrayOf(historyActor.effectiveHistory.map { it.instance }.takeIf { it.isNotEmpty() }?.toTypedArray(),
|
||||
*(useScriptArgs.orEmpty()))
|
||||
else useScriptArgs.orEmpty()
|
||||
|
||||
// TODO: try/catch ?
|
||||
val scriptInstanceConstructor = scriptClass.getConstructor(*constructorParams)
|
||||
|
||||
@@ -51,7 +51,7 @@ class ReplInterpreter(
|
||||
hasErrors = false
|
||||
}
|
||||
|
||||
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
||||
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
|
||||
val msg = messageRenderer.render(severity, message, location)
|
||||
with (replConfiguration.writer) {
|
||||
when (severity) {
|
||||
|
||||
@@ -146,15 +146,14 @@ class GenericReplTest : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
// #KT-10060, TODO: fix and uncomment/rename
|
||||
// @Test
|
||||
fun ignored_test256Evals() {
|
||||
@Test
|
||||
fun test256Evals() {
|
||||
TestRepl().use { repl ->
|
||||
val state = repl.createState()
|
||||
|
||||
repl.compileAndEval(state, ReplCodeLine(0, 0, "val x0 = 0"))
|
||||
|
||||
val evals = 255
|
||||
val evals = 256
|
||||
for (i in 1..evals) {
|
||||
repl.compileAndEval(state, ReplCodeLine(i, 0, "val x$i = x${i-1} + 1"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user