Skip to content

Commit

Permalink
Need to distinguish between vars and locals specifically
Browse files Browse the repository at this point in the history
Only locals are relevant for splitting decisions, access to arguments is always safe.

Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Jul 27, 2017
1 parent 298e619 commit 918c3b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/som/compiler/MethodBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public final class MethodBuilder {
private boolean throwsNonLocalReturn; // does directly or indirectly a non-local return

private boolean accessesVariablesOfOuterScope;
private boolean accessesLocalOfOuterScope;

private final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
private final LinkedHashMap<String, Local> locals = new LinkedHashMap<>();
Expand Down Expand Up @@ -215,8 +216,8 @@ public void makeCatchNonLocalReturn() {
ctx.needsToCatchNonLocalReturn = true;
}

public boolean accessesVariablesOfOuterScope() {
return accessesVariablesOfOuterScope;
public boolean accessesLocalOfOuterScope() {
return accessesLocalOfOuterScope;
}

public boolean requiresContext() {
Expand Down Expand Up @@ -421,6 +422,9 @@ protected Variable getVariable(final String varName) {
Variable outerVar = outerBuilder.getVariable(varName);
if (outerVar != null) {
accessesVariablesOfOuterScope = true;
if (outerVar instanceof Local) {
accessesLocalOfOuterScope = true;
}
}
return outerVar;
}
Expand Down Expand Up @@ -530,6 +534,7 @@ protected Local getLocal(final String varName) {
Local outerLocal = outerBuilder.getLocal(varName);
if (outerLocal != null) {
accessesVariablesOfOuterScope = true;
accessesLocalOfOuterScope = true;
}
return outerLocal;
}
Expand Down
4 changes: 2 additions & 2 deletions src/som/compiler/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,10 +1148,10 @@ private ExpressionNode primary(final MethodBuilder builder) throws ProgramDefini

if (bgenc.requiresContext() || VmSettings.TRUFFLE_DEBUGGER_ENABLED) {
return new BlockNodeWithContext(blockMethod,
bgenc.accessesVariablesOfOuterScope(), lastMethodsSourceSection);
bgenc.accessesLocalOfOuterScope(), lastMethodsSourceSection);
} else {
return new BlockNode(blockMethod,
bgenc.accessesVariablesOfOuterScope(), lastMethodsSourceSection);
bgenc.accessesLocalOfOuterScope(), lastMethodsSourceSection);
}
}
case LCurly: {
Expand Down
4 changes: 0 additions & 4 deletions src/som/interpreter/nodes/literals/BlockNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ public BlockNodeWithContext(final SInvokable blockMethod,
super(blockMethod, needsAdjustmentOnScopeChange, source);
}

public BlockNodeWithContext(final BlockNodeWithContext node) {
this(node.blockMethod, node.needsAdjustmentOnScopeChange, node.sourceSection);
}

@Override
public SBlock executeSBlock(final VirtualFrame frame) {
return new SBlock(blockMethod, frame.materialize(), blockClass);
Expand Down

0 comments on commit 918c3b2

Please sign in to comment.