Skip to content

Commit

Permalink
[Truffle] Encoding::EncodingMap keys need to be uppercase.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 25, 2015
1 parent 5ff64f4 commit e7d2524
Showing 1 changed file with 10 additions and 2 deletions.
Expand Up @@ -509,19 +509,25 @@ public boolean isDummy(RubyEncoding encoding) {
@CoreMethod(names = "encoding_map", onSingleton = true)
public abstract static class EncodingMapNode extends CoreMethodNode {

@Child private CallDispatchHeadNode upcaseNode;
@Child private CallDispatchHeadNode toSymNode;
@Child private CallDispatchHeadNode newLookupTableNode;
@Child private CallDispatchHeadNode lookupTableWriteNode;
@Child private CallDispatchHeadNode newTupleNode;

public EncodingMapNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
upcaseNode = DispatchHeadNodeFactory.createMethodCall(context);
toSymNode = DispatchHeadNodeFactory.createMethodCall(context);
newLookupTableNode = DispatchHeadNodeFactory.createMethodCall(context);
lookupTableWriteNode = DispatchHeadNodeFactory.createMethodCall(context);
newTupleNode = DispatchHeadNodeFactory.createMethodCall(context);
}

public EncodingMapNode(EncodingMapNode prev) {
super(prev);
upcaseNode = prev.upcaseNode;
toSymNode = prev.toSymNode;
newLookupTableNode = prev.newLookupTableNode;
lookupTableWriteNode = prev.lookupTableWriteNode;
newTupleNode = prev.newTupleNode;
Expand All @@ -533,7 +539,8 @@ public Object encodingMap(VirtualFrame frame) {

final RubyEncoding[] encodings = RubyEncoding.cloneEncodingList();
for (int i = 0; i < encodings.length; i++) {
final RubySymbol key = getContext().newSymbol(encodings[i].getName());
final Object upcased = upcaseNode.call(frame, getContext().makeString(encodings[i].getName()), "upcase", null);
final Object key = toSymNode.call(frame, upcased, "to_sym", null);
final Object value = newTupleNode.call(frame, getContext().getCoreLibrary().getTupleClass(), "create", null, nil(), i);

lookupTableWriteNode.call(frame, ret, "[]=", null, key, value);
Expand All @@ -544,7 +551,8 @@ public Object encodingMap(VirtualFrame frame) {
final CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<EncodingDB.Entry> e =
((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<EncodingDB.Entry>)i.next());

final RubySymbol key = getContext().newSymbol(new ByteList(e.bytes, e.p, e.end - e.p));
final Object upcased = upcaseNode.call(frame, getContext().makeString(new ByteList(e.bytes, e.p, e.end - e.p)), "upcase", null);
final Object key = toSymNode.call(frame, upcased, "to_sym", null);
final RubyString alias = getContext().makeString(new ByteList(e.bytes, e.p, e.end - e.p));
final int index = e.value.getIndex();

Expand Down

0 comments on commit e7d2524

Please sign in to comment.