Skip to content
Permalink
Browse files
[Truffle] Stub implementation of String#encode(String, Hash).
  • Loading branch information
nirvdrum committed Feb 23, 2015
1 parent 150c794 commit cf522e477761f3720d30f1e7d76b6079a8f998fb
Showing with 14 additions and 5 deletions.
  1. +1 −0 spec/truffle/tags/core/string/encode_tags.txt
  2. +13 −5 truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
@@ -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
@@ -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;
@@ -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);
@@ -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);
@@ -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);
}
}

0 comments on commit cf522e4

Please sign in to comment.