Skip to content

Commit 2cea1b9

Browse files
committed
Simplify to a single constructor for TranslatorEnvironment
1 parent 4b5d805 commit 2cea1b9

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,9 @@ private RubyNode openModule(SourceIndexLength sourceSection, RubyNode defineOrGe
944944
returnId = environment.getParseEnvironment().allocateReturnID();
945945
}
946946

947-
final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(context, environment, environment.getParseEnvironment(),
948-
returnId, true, true, true, sharedMethodInfo, name, 0, null);
947+
final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(environment, environment.getParseEnvironment(),
948+
returnId, true, true, true,
949+
sharedMethodInfo, name, 0, null, TranslatorEnvironment.newFrameDescriptor(context));
949950

950951
final BodyTranslator moduleTranslator = new BodyTranslator(currentNode, context, this, newEnvironment, source, parserContext, false);
951952

@@ -1304,7 +1305,9 @@ protected RubyNode translateMethodDefinition(SourceIndexLength sourceSection, Ru
13041305
alwaysClone);
13051306

13061307
final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
1307-
context, environment, environment.getParseEnvironment(), environment.getParseEnvironment().allocateReturnID(), true, true, false, sharedMethodInfo, methodName, 0, null);
1308+
environment, environment.getParseEnvironment(), environment.getParseEnvironment().allocateReturnID(),
1309+
true, true, false, sharedMethodInfo, methodName,
1310+
0, null, TranslatorEnvironment.newFrameDescriptor(context));
13081311

13091312
// ownScopeForAssignments is the same for the defined method as the current one.
13101313

@@ -1757,8 +1760,9 @@ private RubyNode translateBlockLikeNode(IterParseNode node, boolean isLambda) {
17571760
final ReturnID returnID = isLambda ? parseEnvironment.allocateReturnID() : environment.getReturnID();
17581761

17591762
final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
1760-
context, environment, parseEnvironment, returnID, hasOwnScope, false,
1761-
false, sharedMethodInfo, environment.getNamedMethodName(), blockDepth, parseEnvironment.allocateBreakID());
1763+
environment, parseEnvironment, returnID, hasOwnScope, false, false,
1764+
sharedMethodInfo, environment.getNamedMethodName(), blockDepth, parseEnvironment.allocateBreakID(),
1765+
TranslatorEnvironment.newFrameDescriptor(context));
17621766
final MethodTranslator methodCompiler = new MethodTranslator(currentNode, context, this, newEnvironment, true, source, parserContext, argsNode);
17631767

17641768
if (isProc) {

src/main/java/org/truffleruby/parser/TranslatorDriver.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ public RubyRootNode parse(RubySource rubySource, ParserContext parserContext, St
205205

206206
final boolean topLevel = parserContext.isTopLevel();
207207
final boolean isModuleBody = topLevel;
208-
final TranslatorEnvironment environment = new TranslatorEnvironment(context, parentEnvironment,
209-
parseEnvironment, parseEnvironment.allocateReturnID(), ownScopeForAssignments, false, isModuleBody, sharedMethodInfo, sharedMethodInfo.getName(), 0, null);
208+
final TranslatorEnvironment environment = new TranslatorEnvironment(parentEnvironment, parseEnvironment,
209+
parseEnvironment.allocateReturnID(), ownScopeForAssignments, false, isModuleBody,
210+
sharedMethodInfo, sharedMethodInfo.getName(), 0, null, TranslatorEnvironment.newFrameDescriptor(context));
210211

211212
// Declare arguments as local variables in the top-level environment - we'll put the values there in a prelude
212213

@@ -356,8 +357,9 @@ private TranslatorEnvironment environmentForFrameDescriptor(RubyContext context,
356357
null,
357358
false);
358359
// TODO(CS): how do we know if the frame is a block or not?
359-
return new TranslatorEnvironment(null, parseEnvironment,
360-
parseEnvironment.allocateReturnID(), true, true, false, sharedMethodInfo, sharedMethodInfo.getName(), 0, null, frameDescriptor);
360+
return new TranslatorEnvironment(null, parseEnvironment, parseEnvironment.allocateReturnID(),
361+
true, true, false,
362+
sharedMethodInfo, sharedMethodInfo.getName(), 0, null, frameDescriptor);
361363
}
362364

363365
private TranslatorEnvironment environmentForFrame(RubyContext context, MaterializedFrame frame) {
@@ -376,8 +378,9 @@ private TranslatorEnvironment environmentForFrame(RubyContext context, Materiali
376378
false);
377379
final MaterializedFrame parent = RubyArguments.getDeclarationFrame(frame);
378380
// TODO(CS): how do we know if the frame is a block or not?
379-
return new TranslatorEnvironment(environmentForFrame(context, parent), parseEnvironment,
380-
parseEnvironment.allocateReturnID(), true, true, false, sharedMethodInfo, sharedMethodInfo.getName(), 0, null, frame.getFrameDescriptor());
381+
return new TranslatorEnvironment(environmentForFrame(context, parent), parseEnvironment, parseEnvironment.allocateReturnID(),
382+
true, true, false,
383+
sharedMethodInfo, sharedMethodInfo.getName(), 0, null, frame.getFrameDescriptor());
381384
}
382385
}
383386

src/main/java/org/truffleruby/parser/TranslatorEnvironment.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ public TranslatorEnvironment(TranslatorEnvironment parent, ParseEnvironment pars
6666
this.breakID = breakID;
6767
}
6868

69-
public TranslatorEnvironment(RubyContext context, TranslatorEnvironment parent, ParseEnvironment parseEnvironment,
70-
ReturnID returnID, boolean ownScopeForAssignments, boolean neverAssignInParentScope,
71-
boolean isModuleBody, SharedMethodInfo sharedMethodInfo, String namedMethodName, int blockDepth, BreakID breakID) {
72-
this(parent, parseEnvironment, returnID, ownScopeForAssignments, neverAssignInParentScope, isModuleBody, sharedMethodInfo, namedMethodName, blockDepth,
73-
breakID, new FrameDescriptor(context.getCoreLibrary().getNil()));
69+
public static FrameDescriptor newFrameDescriptor(RubyContext context) {
70+
return new FrameDescriptor(context.getCoreLibrary().getNil());
7471
}
7572

7673
public boolean isDynamicConstantLookup() {

0 commit comments

Comments
 (0)