Skip to content

Commit

Permalink
[Truffle] Stub implementation of String#encode(String, Hash).
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Feb 23, 2015
1 parent 150c794 commit cf522e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions spec/truffle/tags/core/string/encode_tags.txt
Expand Up @@ -80,3 +80,4 @@ fails:String#encode! when passed no options returns self for a ASCII-only String
fails:String#encode! when passed options returns self for ASCII-only String when Encoding.default_internal is nil
fails:String#encode! when passed to encoding returns self
fails:String#encode! when passed to, from returns self
fails:String#encode raises ArgumentError if the value of the :xml option is not :text or :attr
Expand Up @@ -808,7 +808,7 @@ public boolean empty(RubyString string) {
}
}

@CoreMethod(names = "encode", required = 1)
@CoreMethod(names = "encode", required = 1, optional = 1)
public abstract static class EncodeNode extends CoreMethodNode {

@Child private ToStrNode toStrNode;
Expand All @@ -822,7 +822,7 @@ public EncodeNode(EncodeNode prev) {
}

@Specialization
public RubyString encode(RubyString string, RubyString encoding) {
public RubyString encode(RubyString string, RubyString encoding, @SuppressWarnings("unused") UndefinedPlaceholder options) {
notDesignedForCompilation();

final org.jruby.RubyString jrubyString = getContext().toJRuby(string);
Expand All @@ -833,7 +833,15 @@ public RubyString encode(RubyString string, RubyString encoding) {
}

@Specialization
public RubyString encode(RubyString string, RubyEncoding encoding) {
public RubyString encode(RubyString string, RubyString encoding, @SuppressWarnings("unused") RubyHash options) {
notDesignedForCompilation();

// TODO (nirvdrum 20-Feb-15) We need to do something with the options hash. I'm stubbing this out just to get the jUnit mspec formatter running.
return encode(string, encoding, UndefinedPlaceholder.INSTANCE);
}

@Specialization
public RubyString encode(RubyString string, RubyEncoding encoding, @SuppressWarnings("unused") UndefinedPlaceholder options) {
notDesignedForCompilation();

final org.jruby.RubyString jrubyString = getContext().toJRuby(string);
Expand All @@ -844,15 +852,15 @@ public RubyString encode(RubyString string, RubyEncoding encoding) {
}

@Specialization(guards = { "!isRubyString(arguments[1])", "!isRubyEncoding(arguments[1])" })
public RubyString encode(VirtualFrame frame, RubyString string, Object encoding) {
public RubyString encode(VirtualFrame frame, RubyString string, Object encoding, UndefinedPlaceholder options) {
notDesignedForCompilation();

if (toStrNode == null) {
CompilerDirectives.transferToInterpreter();
toStrNode = insert(ToStrNodeFactory.create(getContext(), getSourceSection(), null));
}

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

Expand Down

0 comments on commit cf522e4

Please sign in to comment.