Skip to content

Commit ca88b70

Browse files
committed
No need to store RubyContext in FormatRootNode
1 parent abd7b10 commit ca88b70

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

src/main/java/org/truffleruby/core/format/FormatRootNode.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import java.util.List;
1313

14-
import org.truffleruby.RubyContext;
14+
import org.truffleruby.RubyLanguage;
1515
import org.truffleruby.core.rope.CodeRange;
1616
import org.truffleruby.extra.ffi.Pointer;
1717
import org.truffleruby.language.RubyBaseRootNode;
@@ -27,16 +27,20 @@
2727
/** The node at the root of a pack expression. */
2828
public class FormatRootNode extends RubyBaseRootNode implements InternalRootNode {
2929

30-
private final RubyContext context;
30+
private final RubyLanguage language;
3131
private final FormatEncoding encoding;
3232

3333
@Child private FormatNode child;
3434

3535
@CompilationFinal private int expectedLength = 0;
3636

37-
public FormatRootNode(RubyContext context, SourceSection sourceSection, FormatEncoding encoding, FormatNode child) {
38-
super(context.getLanguageSlow(), FormatFrameDescriptor.FRAME_DESCRIPTOR, sourceSection);
39-
this.context = context;
37+
public FormatRootNode(
38+
RubyLanguage language,
39+
SourceSection sourceSection,
40+
FormatEncoding encoding,
41+
FormatNode child) {
42+
super(language, FormatFrameDescriptor.FRAME_DESCRIPTOR, sourceSection);
43+
this.language = language;
4044
this.encoding = encoding;
4145
this.child = child;
4246
}
@@ -139,8 +143,4 @@ public String getName() {
139143
public String toString() {
140144
return getName();
141145
}
142-
143-
public RubyContext getContext() {
144-
return context;
145-
}
146146
}

src/main/java/org/truffleruby/core/format/pack/PackCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public RootCallTarget compile(String format) {
4444

4545
return Truffle.getRuntime().createCallTarget(
4646
new FormatRootNode(
47-
context,
47+
context.getLanguageSlow(),
4848
currentNode.getEncapsulatingSourceSection(),
4949
builder.getEncoding(),
5050
builder.getNode()));

src/main/java/org/truffleruby/core/format/printf/PrintfCompiler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.List;
1313

1414
import com.oracle.truffle.api.nodes.Node;
15-
import org.truffleruby.RubyContext;
15+
import org.truffleruby.RubyLanguage;
1616
import org.truffleruby.core.format.FormatEncoding;
1717
import org.truffleruby.core.format.FormatRootNode;
1818
import org.truffleruby.core.rope.Rope;
@@ -22,22 +22,22 @@
2222

2323
public class PrintfCompiler {
2424

25-
private final RubyContext context;
25+
private final RubyLanguage language;
2626
private final Node currentNode;
2727

28-
public PrintfCompiler(RubyContext context, Node currentNode) {
29-
this.context = context;
28+
public PrintfCompiler(RubyLanguage language, Node currentNode) {
29+
this.language = language;
3030
this.currentNode = currentNode;
3131
}
3232

3333
public RootCallTarget compile(Rope format, Object[] arguments, boolean isDebug) {
3434
final PrintfSimpleParser parser = new PrintfSimpleParser(bytesToChars(format.getBytes()), arguments, isDebug);
3535
final List<SprintfConfig> configs = parser.parse();
36-
final PrintfSimpleTreeBuilder builder = new PrintfSimpleTreeBuilder(context, configs);
36+
final PrintfSimpleTreeBuilder builder = new PrintfSimpleTreeBuilder(language, configs);
3737

3838
return Truffle.getRuntime().createCallTarget(
3939
new FormatRootNode(
40-
context,
40+
language,
4141
currentNode.getEncapsulatingSourceSection(),
4242
FormatEncoding.find(format.getEncoding()),
4343
builder.getNode()));

src/main/java/org/truffleruby/core/format/printf/PrintfSimpleTreeBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import com.oracle.truffle.api.CompilerDirectives;
1616
import org.jcodings.specific.USASCIIEncoding;
17-
import org.truffleruby.RubyContext;
17+
import org.truffleruby.RubyLanguage;
1818
import org.truffleruby.core.format.FormatNode;
1919
import org.truffleruby.core.format.LiteralFormatNode;
2020
import org.truffleruby.core.format.SharedTreeBuilder;
@@ -40,16 +40,16 @@
4040

4141
public class PrintfSimpleTreeBuilder {
4242

43-
private final RubyContext context;
43+
private final RubyLanguage language;
4444
private final List<FormatNode> sequence = new ArrayList<>();
4545
private final List<SprintfConfig> configs;
4646

4747
public static final int DEFAULT = -1;
4848

4949
private static final byte[] EMPTY_BYTES = RopeConstants.EMPTY_BYTES;
5050

51-
public PrintfSimpleTreeBuilder(RubyContext context, List<SprintfConfig> configs) {
52-
this.context = context;
51+
public PrintfSimpleTreeBuilder(RubyLanguage language, List<SprintfConfig> configs) {
52+
this.language = language;
5353
this.configs = configs;
5454
}
5555

@@ -62,7 +62,7 @@ private void buildTree() {
6262
final FormatNode valueNode;
6363

6464
if (config.getNamesBytes() != null) {
65-
final RubySymbol key = context.getLanguageSlow().getSymbol(RopeOperations.create(
65+
final RubySymbol key = language.getSymbol(RopeOperations.create(
6666
config.getNamesBytes(),
6767
USASCIIEncoding.INSTANCE,
6868
CodeRange.CR_7BIT));

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ private RubyString finishFormat(int formatLength, BytesResult result) {
18381838
protected RootCallTarget compileFormat(Object format, Object[] arguments, boolean isDebug,
18391839
RubyStringLibrary libFormat) {
18401840
try {
1841-
return new PrintfCompiler(getContext(), this)
1841+
return new PrintfCompiler(getLanguage(), this)
18421842
.compile(libFormat.getRope(format), arguments, isDebug);
18431843
} catch (InvalidFormatException e) {
18441844
throw new RaiseException(getContext(), coreExceptions().argumentError(e.getMessage(), this));

0 commit comments

Comments
 (0)