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: e2d3abd9538e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bd21747d1412
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 6, 2015

  1. [Truffle] Fixed Encoding::TranscodingMap to have the correct key valu…

    …es, rather than a placeholder.
    nirvdrum committed Apr 6, 2015
    Copy the full SHA
    c37119d View commit details
  2. Copy the full SHA
    9b00410 View commit details
  3. Copy the full SHA
    bd21747 View commit details
Original file line number Diff line number Diff line change
@@ -110,13 +110,15 @@ public abstract static class TranscodingMapNode extends CoreMethodNode {
@Child private CallDispatchHeadNode toSymNode;
@Child private CallDispatchHeadNode newLookupTableNode;
@Child private CallDispatchHeadNode lookupTableWriteNode;
@Child private CallDispatchHeadNode newTranscodingNode;

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

public TranscodingMapNode(TranscodingMapNode prev) {
@@ -125,6 +127,7 @@ public TranscodingMapNode(TranscodingMapNode prev) {
toSymNode = prev.toSymNode;
newLookupTableNode = prev.newLookupTableNode;
lookupTableWriteNode = prev.lookupTableWriteNode;
newTranscodingNode = prev.newTranscodingNode;
}

@Specialization
@@ -145,7 +148,8 @@ public Object transcodingMap(VirtualFrame frame) {

final Object upcasedLookupTableKey = upcaseNode.call(frame, getContext().makeString(new ByteList(e.getDestination())), "upcase", null);
final Object lookupTableKey = toSymNode.call(frame, upcasedLookupTableKey, "to_sym", null);
lookupTableWriteNode.call(frame, value, "[]=", null, lookupTableKey, true);
final Object lookupTableValue = newTranscodingNode.call(frame, getContext().getCoreLibrary().getTranscodingClass(), "create", null, key, lookupTableKey);
lookupTableWriteNode.call(frame, value, "[]=", null, lookupTableKey, lookupTableValue);
}

lookupTableWriteNode.call(frame, ret, "[]=", null, key, value);
@@ -155,25 +159,4 @@ public Object transcodingMap(VirtualFrame frame) {
}
}

@RubiniusOnly
@CoreMethod(names = "transcoding_path_lookup", onSingleton = true, required = 2)
public abstract static class TranscodingPathLookupNode extends CoreMethodNode {

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

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

@Specialization
public boolean transcodingPathLookup(RubyString sourceEncodingName, RubyString destinationEncodingName) {
final TranscoderDB.Entry entry = TranscoderDB.getEntry(sourceEncodingName.getByteList().getUnsafeBytes(),
destinationEncodingName.getByteList().getUnsafeBytes());

return entry.getTranscoder() != null;
}
}

}
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ public class CoreLibrary {
private final RubyClass systemStackErrorClass;
private final RubyClass threadClass;
private final RubyClass timeClass;
private final RubyClass transcodingClass;
private final RubyClass trueClass;
private final RubyClass tupleClass;
private final RubyClass typeErrorClass;
@@ -310,6 +311,7 @@ public CoreLibrary(RubyContext context) {
byteArrayClass = defineClass(rubiniusModule, objectClass, "ByteArray");
lookupTableClass = defineClass(rubiniusModule, hashClass, "LookupTable");
stringDataClass = defineClass(rubiniusModule, objectClass, "StringData");
transcodingClass = defineClass(encodingClass, objectClass, "Transcoding");
tupleClass = defineClass(rubiniusModule, arrayClass, "Tuple");

// Include the core modules
@@ -1194,6 +1196,10 @@ public RubyClass getStringDataClass() {
return stringDataClass;
}

public RubyClass getTranscodingClass() {
return transcodingClass;
}

public RubyClass getTupleClass() {
return tupleClass;
}
21 changes: 21 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/encoding.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
class Encoding
# There's a fun bootstrapping issue here. Encoding::Converter.transcoding_map needs access to the Encoding::Transcoding
# class. However, this shim runs before Encoding::Transcoding is defined. Since the class body is short, we reproduce
# it here along with a convenient factory method.
class Transcoding
attr_accessor :source
attr_accessor :target

def inspect
"#<#{super} #{source} to #{target}"
end

def self.create(source, target)
ret = new

ret.source = source
ret.target = target

ret
end
end

TranscodingMap = Encoding::Converter.transcoding_map
EncodingMap = Encoding.encoding_map
EncodingList = Encoding.list
9 changes: 8 additions & 1 deletion truffle/src/main/ruby/core/rubinius/api/shims/lookuptable.rb
Original file line number Diff line number Diff line change
@@ -13,7 +13,14 @@ class LookupTable < Hash
alias_method :lookup_orig, :[]

def [](key)
lookup_orig(key.to_sym)
lookup_orig(key_to_sym(key))
end

private

# Taken from Rubinius LookupTable.
def key_to_sym(key)
key.kind_of?(String) ? key.to_sym : key
end
end
end