Place repl specific stuff of GenerationState into a separate entity
Add even more hacks to tell if the line has useful result to display
This commit is contained in:
@@ -311,11 +311,12 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
public void gen(KtElement expr, Type type) {
|
||||
StackValue value = Type.VOID_TYPE.equals(type) ? genStatement(expr) : gen(expr);
|
||||
// for repl store the result of the last line into special field
|
||||
if (value.type != Type.VOID_TYPE && state.getShouldGenerateScriptResultValue()) {
|
||||
if (value.type != Type.VOID_TYPE && state.getReplSpecific().getShouldGenerateScriptResultValue()) {
|
||||
ScriptContext context = getScriptContext();
|
||||
if (expr == context.getLastStatement()) {
|
||||
StackValue.Field resultValue = StackValue.field(context.getResultFieldInfo(), StackValue.LOCAL_0);
|
||||
resultValue.store(value, v);
|
||||
state.getReplSpecific().setHasResult(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ScriptCodegen extends MemberCodegen<KtScript> {
|
||||
|
||||
ClassBuilder builder = state.getFactory().newVisitor(JvmDeclarationOriginKt.OtherOrigin(declaration, scriptDescriptor),
|
||||
classType, declaration.getContainingFile());
|
||||
List<ScriptDescriptor> earlierScripts = state.getEarlierScriptsForReplInterpreter();
|
||||
List<ScriptDescriptor> earlierScripts = state.getReplSpecific().getEarlierScriptsForReplInterpreter();
|
||||
ScriptContext scriptContext = parentContext.intoScript(
|
||||
scriptDescriptor,
|
||||
earlierScripts == null ? Collections.<ScriptDescriptor>emptyList() : earlierScripts,
|
||||
@@ -115,7 +115,7 @@ public class ScriptCodegen extends MemberCodegen<KtScript> {
|
||||
) {
|
||||
JvmMethodSignature jvmSignature = typeMapper.mapScriptSignature(scriptDescriptor, context.getEarlierScripts());
|
||||
|
||||
if (state.getShouldGenerateScriptResultValue()) {
|
||||
if (state.getReplSpecific().getShouldGenerateScriptResultValue()) {
|
||||
FieldInfo resultFieldInfo = context.getResultFieldInfo();
|
||||
classBuilder.newField(
|
||||
JvmDeclarationOrigin.NO_ORIGIN,
|
||||
|
||||
@@ -67,9 +67,9 @@ public class ScriptContext extends ClassContext {
|
||||
|
||||
@NotNull
|
||||
public FieldInfo getResultFieldInfo() {
|
||||
assert getState().getShouldGenerateScriptResultValue() : "Should not be called unless 'scriptResultFieldName' is set";
|
||||
assert getState().getReplSpecific().getShouldGenerateScriptResultValue() : "Should not be called unless 'scriptResultFieldName' is set";
|
||||
GenerationState state = getState();
|
||||
String scriptResultFieldName = state.getScriptResultFieldName();
|
||||
String scriptResultFieldName = state.getReplSpecific().getScriptResultFieldName();
|
||||
assert scriptResultFieldName != null;
|
||||
return FieldInfo.createForHiddenField(state.getTypeMapper().mapClass(scriptDescriptor), AsmTypes.OBJECT_TYPE, scriptResultFieldName);
|
||||
}
|
||||
|
||||
@@ -598,7 +598,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
CodegenContext parent = getContext(descriptor.getContainingDeclaration(), state, sourceFile);
|
||||
|
||||
if (descriptor instanceof ScriptDescriptor) {
|
||||
List<ScriptDescriptor> earlierScripts = state.getEarlierScriptsForReplInterpreter();
|
||||
List<ScriptDescriptor> earlierScripts = state.getReplSpecific().getEarlierScriptsForReplInterpreter();
|
||||
return parent.intoScript((ScriptDescriptor) descriptor,
|
||||
earlierScripts == null ? Collections.emptyList() : earlierScripts,
|
||||
(ClassDescriptor) descriptor, state.getTypeMapper());
|
||||
|
||||
@@ -100,15 +100,22 @@ public class GenerationState @JvmOverloads constructor(
|
||||
public val samWrapperClasses: SamWrapperClasses = SamWrapperClasses(this)
|
||||
public val inlineCycleReporter: InlineCycleReporter = InlineCycleReporter(diagnostics)
|
||||
public val mappingsClassesForWhenByEnum: MappingsClassesForWhenByEnum = MappingsClassesForWhenByEnum(this)
|
||||
public var earlierScriptsForReplInterpreter: List<ScriptDescriptor>? = null
|
||||
public var scriptResultFieldName: String? = null
|
||||
public val shouldGenerateScriptResultValue: Boolean get() = scriptResultFieldName != null
|
||||
public val reflectionTypes: ReflectionTypes = ReflectionTypes(module)
|
||||
public val jvmRuntimeTypes: JvmRuntimeTypes = JvmRuntimeTypes()
|
||||
public val factory: ClassFileFactory
|
||||
private val interceptedBuilderFactory: ClassBuilderFactory
|
||||
private var used = false
|
||||
|
||||
public val replSpecific = ForRepl()
|
||||
|
||||
//TODO: should be refactored out
|
||||
public class ForRepl {
|
||||
public var earlierScriptsForReplInterpreter: List<ScriptDescriptor>? = null
|
||||
public var scriptResultFieldName: String? = null
|
||||
public val shouldGenerateScriptResultValue: Boolean get() = scriptResultFieldName != null
|
||||
public var hasResult: Boolean = false
|
||||
}
|
||||
|
||||
public val isCallAssertionsEnabled: Boolean = !disableCallAssertions
|
||||
@JvmName("isCallAssertionsEnabled") get
|
||||
|
||||
|
||||
@@ -352,7 +352,7 @@ public class ReplInterpreter {
|
||||
|
||||
earlierLines.add(new EarlierLine(line, scriptDescriptor, scriptClass, scriptInstance, scriptClassType));
|
||||
|
||||
return LineResult.successful(rv, false);
|
||||
return LineResult.successful(rv, !state.getReplSpecific().getHasResult());
|
||||
}
|
||||
catch (Throwable e) {
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
@@ -431,7 +431,7 @@ public class ReplInterpreter {
|
||||
ScriptDescriptor earlierDescriptor = pair.first;
|
||||
earlierScriptDescriptors.add(earlierDescriptor);
|
||||
}
|
||||
state.setEarlierScriptsForReplInterpreter(earlierScriptDescriptors);
|
||||
state.getReplSpecific().setEarlierScriptsForReplInterpreter(earlierScriptDescriptors);
|
||||
}
|
||||
|
||||
public static void compileScript(
|
||||
@@ -440,7 +440,7 @@ public class ReplInterpreter {
|
||||
@NotNull GenerationState state,
|
||||
@NotNull CompilationErrorHandler errorHandler
|
||||
) {
|
||||
state.setScriptResultFieldName(SCRIPT_RESULT_FIELD_NAME);
|
||||
state.getReplSpecific().setScriptResultFieldName(SCRIPT_RESULT_FIELD_NAME);
|
||||
registerEarlierScripts(state, earlierScripts);
|
||||
|
||||
state.beforeCompile();
|
||||
|
||||
Reference in New Issue
Block a user