Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] All Encoding.{default_interal, default_internal=} specs now…
… pass.
  • Loading branch information
nirvdrum committed Feb 6, 2015
1 parent 0a7f712 commit 53665ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
13 changes: 0 additions & 13 deletions spec/truffle/tags/core/encoding/default_internal_tags.txt

This file was deleted.

Expand Up @@ -13,6 +13,7 @@
import com.oracle.truffle.api.dsl.CreateCast;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jcodings.Encoding;
Expand All @@ -23,6 +24,7 @@
import org.jcodings.util.Hash;
import org.jruby.runtime.encoding.EncodingService;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.coerce.ToStrNode;
import org.jruby.truffle.nodes.coerce.ToStrNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
Expand Down Expand Up @@ -199,6 +201,8 @@ public RubyEncoding defaultExternal(RubyEncoding encoding) {
@CoreMethod(names = "default_internal=", onSingleton = true, required = 1)
public abstract static class SetDefaultInternalNode extends CoreMethodNode {

@Child private ToStrNode toStrNode;

public SetDefaultInternalNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
Expand All @@ -208,7 +212,7 @@ public SetDefaultInternalNode(SetDefaultInternalNode prev) {
}

@Specialization
public RubyEncoding defaultExternal(RubyEncoding encoding) {
public RubyEncoding defaultInternal(RubyEncoding encoding) {
notDesignedForCompilation();

getContext().getRuntime().setDefaultInternalEncoding(encoding.getEncoding());
Expand All @@ -217,14 +221,29 @@ public RubyEncoding defaultExternal(RubyEncoding encoding) {
}

@Specialization
public RubyNilClass defaultExternal(RubyNilClass encoding) {
public RubyNilClass defaultInternal(RubyNilClass encoding) {
notDesignedForCompilation();

getContext().getRuntime().setDefaultInternalEncoding(ASCIIEncoding.INSTANCE);
getContext().getRuntime().setDefaultInternalEncoding(null);

return encoding;
}

@Specialization
public RubyString defaultInternal(VirtualFrame frame, Object encoding) {

This comment has been minimized.

Copy link
@eregon

eregon Feb 6, 2015

Member

This needs to be guarded against nil and Encoding, no? One easy way since there is only Object arguments is to use @Fallback.
Ideally the UndefinedPlaceholder missing guards detector could also check for these if no contains is present (but there might be a few cases where it's on purpose without contains).

This comment has been minimized.

Copy link
@nirvdrum

nirvdrum Feb 6, 2015

Author Contributor

You're right. I'll fix that. Thanks.

notDesignedForCompilation();

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

final RubyString encodingName = toStrNode.executeRubyString(frame, encoding);
getContext().getRuntime().setDefaultInternalEncoding(RubyEncoding.getEncoding(encodingName.toString()).getEncoding());

return encodingName;
}

}

@CoreMethod(names = "find", onSingleton = true, required = 1)
Expand Down

0 comments on commit 53665ec

Please sign in to comment.