Skip to content

Commit

Permalink
[Truffle] Completed String#force_encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 20, 2015
1 parent d390326 commit 84562e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/string/force_encoding_tags.txt

This file was deleted.

Expand Up @@ -1191,12 +1191,15 @@ public boolean endWith(RubyString string, RubyString b) {
@CoreMethod(names = "force_encoding", required = 1)
public abstract static class ForceEncodingNode extends CoreMethodNode {

@Child private ToStrNode toStrNode;

public ForceEncodingNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public ForceEncodingNode(ForceEncodingNode prev) {
super(prev);
toStrNode = prev.toStrNode;
}

@TruffleBoundary
Expand All @@ -1212,6 +1215,16 @@ public RubyString forceEncoding(RubyString string, RubyEncoding encoding) {
return string;
}

@Specialization(guards = { "!isRubyString(arguments[1])", "!isRubyEncoding(arguments[1])" })
public RubyString forceEncoding(VirtualFrame frame, RubyString string, Object encoding) {
if (toStrNode == null) {
CompilerDirectives.transferToInterpreter();
toStrNode = insert(ToStrNodeFactory.create(getContext(), getSourceSection(), null));
}

return forceEncoding(string, toStrNode.executeRubyString(frame, encoding));
}

}

@CoreMethod(names = "getbyte", required = 1)
Expand Down

0 comments on commit 84562e1

Please sign in to comment.