|
100 | 100 | import org.truffleruby.language.literal.ObjectLiteralNode;
|
101 | 101 | import org.truffleruby.language.literal.StringLiteralNode;
|
102 | 102 | import org.truffleruby.language.literal.TruffleInternalModuleLiteralNode;
|
103 |
| -import org.truffleruby.language.locals.FindDeclarationVariableNodes; |
| 103 | +import org.truffleruby.language.locals.FindDeclarationVariableNodes.FrameSlotAndDepth; |
104 | 104 | import org.truffleruby.language.locals.FlipFlopNodeGen;
|
105 | 105 | import org.truffleruby.language.locals.InitFlipFlopSlotNode;
|
106 | 106 | import org.truffleruby.language.locals.ReadLocalNode;
|
@@ -499,8 +499,7 @@ private RubyNode translateBlockAndLambda(Nodes.Node node, Nodes.BlockParametersN
|
499 | 499 | source,
|
500 | 500 | parameters,
|
501 | 501 | arity,
|
502 |
| - currentCallMethodName, |
503 |
| - this); |
| 502 | + currentCallMethodName); |
504 | 503 |
|
505 | 504 | methodCompiler.frameOnStackMarkerSlotStack = frameOnStackMarkerSlotStack;
|
506 | 505 |
|
@@ -1201,7 +1200,7 @@ public RubyNode visitFlipFlopNode(Nodes.FlipFlopNode node) {
|
1201 | 1200 | final RubyNode begin = node.left.accept(this);
|
1202 | 1201 | final RubyNode end = node.right.accept(this);
|
1203 | 1202 |
|
1204 |
| - final FindDeclarationVariableNodes.FrameSlotAndDepth slotAndDepth = createFlipFlopState(0); |
| 1203 | + final var slotAndDepth = createFlipFlopState(); |
1205 | 1204 | final RubyNode rubyNode = FlipFlopNodeGen.create(begin, end, node.isExcludeEnd(), slotAndDepth.depth,
|
1206 | 1205 | slotAndDepth.slot);
|
1207 | 1206 |
|
@@ -2014,10 +2013,13 @@ protected RubyNode defaultVisit(Nodes.Node node) {
|
2014 | 2013 | throw new Error("Unknown node: " + node);
|
2015 | 2014 | }
|
2016 | 2015 |
|
2017 |
| - protected FindDeclarationVariableNodes.FrameSlotAndDepth createFlipFlopState(int depth) { |
2018 |
| - final int frameSlot = environment.declareLocalTemp("flipflop"); |
2019 |
| - environment.getFlipFlopStates().add(frameSlot); |
2020 |
| - return new FindDeclarationVariableNodes.FrameSlotAndDepth(frameSlot, depth); |
| 2016 | + /** Declare variable in the nearest non-block outer lexical scope - either method, class or top-level */ |
| 2017 | + protected FrameSlotAndDepth createFlipFlopState() { |
| 2018 | + final var target = environment.getSurroundingMethodEnvironment(); |
| 2019 | + final int frameSlot = target.declareLocalTemp("flipflop"); |
| 2020 | + target.getFlipFlopStates().add(frameSlot); |
| 2021 | + |
| 2022 | + return new FrameSlotAndDepth(frameSlot, environment.getBlockDepth()); |
2021 | 2023 | }
|
2022 | 2024 |
|
2023 | 2025 | /** Translate a list of nodes, e.g. break/return operands, into an array producing node. It returns ArrayLiteralNode
|
|
0 commit comments