Skip to content

Commit e4983d5

Browse files
committed
Fix some of the issues we have with setting the holder
This is only a partial solution, there are still cases where we do not have the correct holder. Signed-off-by: Stefan Marr <[email protected]>
1 parent f54fc9e commit e4983d5

File tree

6 files changed

+14
-3
lines changed

6 files changed

+14
-3
lines changed

src/trufflesom/compiler/MethodGenerationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class MethodGenerationContext
9090
private Internal frameOnStack;
9191
protected final LexicalScope currentScope;
9292

93-
private final List<SMethod> embeddedBlockMethods;
93+
protected final List<SMethod> embeddedBlockMethods;
9494

9595
public final StructuralProbe<SSymbol, SClass, SInvokable, Field, Variable> structuralProbe;
9696

src/trufflesom/compiler/bc/BytecodeMethodGenContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ public void addBytecodeArgument(final byte code) {
182182
bytecode.add(code);
183183
}
184184

185+
public void replaceWith(final SMethod oldBlock, final SMethod newBlock) {
186+
boolean wasInList = embeddedBlockMethods.remove(oldBlock);
187+
assert wasInList : "The block to be removed is expected to be in the list of embedded methods";
188+
embeddedBlockMethods.add(newBlock);
189+
}
190+
185191
public void patchJumpOffsetToPointToNextInstruction(final int idxOfOffset,
186192
final ParserBc parser) throws ParseError {
187193
int instructionStart = idxOfOffset - 1;

src/trufflesom/interpreter/Invokable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package trufflesom.interpreter;
22

3+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
34
import com.oracle.truffle.api.frame.FrameDescriptor;
45
import com.oracle.truffle.api.frame.VirtualFrame;
56
import com.oracle.truffle.api.nodes.RootNode;
@@ -20,7 +21,7 @@ public abstract class Invokable extends RootNode {
2021

2122
protected final ExpressionNode uninitializedBody;
2223

23-
protected SClass holder;
24+
@CompilationFinal protected SClass holder;
2425

2526
protected Invokable(final String name, final SourceSection sourceSection,
2627
final FrameDescriptor frameDescriptor,

src/trufflesom/interpreter/Method.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public Method cloneAndAdaptAfterScopeChange(final BytecodeMethodGenContext mgenc
9999
Method clone = new Method(name, sourceSection, adaptedBody, adaptedScope, uninit,
100100
getLanguage(SomLanguage.class));
101101
adaptedScope.setMethod(clone);
102+
clone.setHolder(holder);
102103
return clone;
103104
}
104105

src/trufflesom/interpreter/Primitive.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public Primitive(final String name, final SourceSection sourceSection,
2626
@Override
2727
public Node deepCopy() {
2828
assert getFrameDescriptor().getSize() == 0 : "Make sure there are no slots to be taken care off";
29-
return new Primitive(name, sourceSection, NodeUtil.cloneNode(uninitializedBody),
29+
Primitive p = new Primitive(name, sourceSection, NodeUtil.cloneNode(uninitializedBody),
3030
getFrameDescriptor(), uninitializedBody, getLanguage(SomLanguage.class));
31+
p.setHolder(holder);
32+
return p;
3133
}
3234

3335
@Override

src/trufflesom/interpreter/nodes/bc/BytecodeLoopNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ private void inlineInto(final BytecodeMethodGenContext mgenc, final int targetCo
13341334
SMethod newMethod = new SMethod(blockMethod.getSignature(), adapted,
13351335
blockMethod.getEmbeddedBlocks(), blockIvk.getSourceSection());
13361336
newMethod.setHolder(blockMethod.getHolder());
1337+
mgenc.replaceWith(blockMethod, newMethod);
13371338
mgenc.addLiteralIfAbsent(newMethod, null);
13381339
emitPUSHBLOCK(mgenc, newMethod, bytecodes[i] == PUSH_BLOCK);
13391340
break;

0 commit comments

Comments
 (0)