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