Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 238637a76163
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cfebc7948c6f
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Dec 9, 2014

  1. Copy the full SHA
    6495e26 View commit details
  2. 4
    Copy the full SHA
    b0446ed View commit details
  3. 11
    Copy the full SHA
    a5816e5 View commit details
  4. Copy the full SHA
    cfebc79 View commit details
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.dsl.Specialization;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jcodings.specific.UTF8Encoding;
import org.jcodings.transcode.TranscoderDB;
import org.jcodings.util.CaseInsensitiveBytesHash;
import org.jcodings.util.Hash;
import org.jruby.runtime.encoding.EncodingService;
@@ -188,9 +188,59 @@ public RubyArray find() {

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), array, array.length);
}
}

@CoreMethod(names = "list", onSingleton = true)
public abstract static class ListNode extends CoreMethodNode {

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

public ListNode(ListNode prev) {
super(prev);
}

@Specialization
public RubyArray list() {
notDesignedForCompilation();

final EncodingService service = getContext().getRuntime().getEncodingService();

final Object[] array = new Object[service.getEncodings().size()];
int n = 0;

Hash.HashEntryIterator i;

i = service.getEncodings().entryIterator();

while (i.hasNext()) {
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<EncodingDB.Entry> e =
((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<EncodingDB.Entry>)i.next());
array[n++] = RubyEncoding.getEncoding(getContext(), e.value.getEncoding());
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), array, array.length);
}
}

@CoreMethod(names = "to_s")
public abstract static class ToSNode extends CoreMethodNode {

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

public ToSNode(ToSNode prev) {
super(prev);
}

@CompilerDirectives.SlowPath
@Specialization
public RubyString toS(RubyEncoding encoding) {
return getContext().makeString(encoding.getName());
}

}

}
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -226,6 +226,10 @@ public RubyString makeString(char string) {
return makeString(Character.toString(string));
}

public RubyString makeString(ByteList bytes) {
return RubyString.fromByteList(coreLibrary.getStringClass(), bytes);
}

public IRubyObject toJRuby(Object object) {
RubyNode.notDesignedForCompilation();

Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import org.jcodings.Encoding;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.util.ByteList;

import java.util.HashMap;
import java.util.Map;
@@ -24,6 +25,7 @@ public class RubyEncoding extends RubyBasicObject {
private static Map<Encoding, RubyEncoding> map = new HashMap<>();

private final Encoding encoding;
private final ByteList name;

/**
* The class from which we create the object that is {@code Encoding}. A subclass of
@@ -61,10 +63,15 @@ public static RubyEncoding getEncoding(RubyContext context, String name) {
private RubyEncoding(RubyClass encodingClass, Encoding encoding) {
super(encodingClass);
this.encoding = encoding;
this.name = new ByteList(encoding.getName());
}

public Encoding getEncoding() {
return encoding;
}

public ByteList getName() {
return name;
}

}
Original file line number Diff line number Diff line change
@@ -50,6 +50,10 @@ public static RubyString fromJavaString(RubyClass stringClass, String string) {
return new RubyString(stringClass, new ByteList(org.jruby.RubyEncoding.encodeUTF8(string), UTF8Encoding.INSTANCE, false));
}

public static RubyString fromByteList(RubyClass stringClass, ByteList bytes) {
return new RubyString(stringClass, bytes);
}

public void set(ByteList bytes) {
this.bytes = bytes;
}
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/encoding/list_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
fails:Encoding.list returns an Array
fails:Encoding.list returns an Array of Encoding objects
fails:Encoding.list returns each encoding only once
fails:Encoding.list includes the default external encoding
fails:Encoding.list does not include any alias names
fails:Encoding.list includes all aliased encodings
fails:Encoding.list includes dummy encodings
fails:Encoding.list updates the list when #find is used to load a new encoding
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/encoding/to_s_tags.txt

This file was deleted.