New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Truffle] Including RegexpOptions in RubyRegexp #2631
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
fails:Encoding.aliases has a 'locale' key and its value equals to the name of the encoding finded by the locale charmap | ||
fails:Encoding.aliases only contains valid aliased encodings |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
fails:Encoding.default_external with command line options is not changed by the -U option | ||
fails:Encoding.default_external with command line options returns the encoding specified by '-E external' | ||
fails:Encoding.default_external with command line options returns the encoding specified by '-E external:' | ||
fails:Encoding.default_external= sets the default external encoding | ||
fails:Encoding.default_external= can accept a name of an encoding as a String | ||
fails:Encoding.default_external= calls #to_s on arguments that are neither Strings nor Encodings | ||
fails:Encoding.default_external= raises a TypeError unless the argument is an Encoding or convertible to a String | ||
fails:Encoding.default_external= raises an ArgumentError if the argument is nil |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
fails:Encoding.locale_charmap returns a String | ||
fails:Encoding.locale_charmap returns a value based on the LC_ALL environment variable | ||
fails:Encoding.locale_charmap is unaffected by assigning to ENV['LC_ALL'] in the same process |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
fails:Regexp.union returns a Regexp with US-ASCII encoding if all arguments are ASCII-only | ||
fails:Regexp.union raises ArgumentError if the arguments include conflicting fixed encoding Regexps | ||
fails:Regexp.union returns a Regexp with the encoding of a String containing non-ASCII-compatible characters and another ASCII-only String |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,16 +24,21 @@ | |
import org.jcodings.specific.UTF8Encoding; | ||
import org.jcodings.util.CaseInsensitiveBytesHash; | ||
import org.jcodings.util.Hash; | ||
import org.jruby.Ruby; | ||
import org.jruby.RubyObject; | ||
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.control.RaiseException; | ||
import org.jruby.truffle.runtime.core.RubyArray; | ||
import org.jruby.truffle.runtime.core.RubyEncoding; | ||
import org.jruby.truffle.runtime.core.RubyHash; | ||
import org.jruby.truffle.runtime.core.RubyNilClass; | ||
import org.jruby.truffle.runtime.core.RubyRegexp; | ||
import org.jruby.truffle.runtime.core.RubyString; | ||
import org.jruby.truffle.runtime.core.RubySymbol; | ||
import org.jruby.truffle.runtime.hash.HashOperations; | ||
import org.jruby.truffle.runtime.hash.KeyValue; | ||
import org.jruby.util.ByteList; | ||
|
@@ -142,6 +147,98 @@ public Object isCompatible(RubyEncoding first, RubyEncoding second) { | |
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
@Specialization | ||
public Object isCompatible(RubyString first, RubyRegexp second) { | ||
notDesignedForCompilation(); | ||
|
||
Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getByteList().getEncoding(), second.getRegex().getEncoding()); | ||
|
||
if (compatibleEncodingProfile.profile(compatibleEncoding != null)) { | ||
return RubyEncoding.getEncoding(compatibleEncoding); | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
@Specialization | ||
public Object isCompatible(RubyRegexp first, RubyString second) { | ||
notDesignedForCompilation(); | ||
|
||
Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getRegex().getEncoding(), second.getByteList().getEncoding()); | ||
|
||
if (compatibleEncodingProfile.profile(compatibleEncoding != null)) { | ||
return RubyEncoding.getEncoding(compatibleEncoding); | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
@Specialization | ||
public Object isCompatible(RubyRegexp first, RubyRegexp second) { | ||
notDesignedForCompilation(); | ||
|
||
Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getRegex().getEncoding(), second.getRegex().getEncoding()); | ||
|
||
if (compatibleEncodingProfile.profile(compatibleEncoding != null)) { | ||
return RubyEncoding.getEncoding(compatibleEncoding); | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
@Specialization | ||
public Object isCompatible(RubyRegexp first, RubySymbol second) { | ||
notDesignedForCompilation(); | ||
|
||
Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getRegex().getEncoding(), second.getByteList().getEncoding()); | ||
|
||
if (compatibleEncodingProfile.profile(compatibleEncoding != null)) { | ||
return RubyEncoding.getEncoding(compatibleEncoding); | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
@Specialization | ||
public Object isCompatible(RubySymbol first, RubyRegexp second) { | ||
notDesignedForCompilation(); | ||
|
||
Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getByteList().getEncoding(), second.getRegex().getEncoding()); | ||
|
||
if (compatibleEncodingProfile.profile(compatibleEncoding != null)) { | ||
return RubyEncoding.getEncoding(compatibleEncoding); | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
@Specialization | ||
public Object isCompatible(RubyString first, RubySymbol second) { | ||
notDesignedForCompilation(); | ||
|
||
Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first, second); | ||
|
||
if (compatibleEncodingProfile.profile(compatibleEncoding != null)) { | ||
return RubyEncoding.getEncoding(compatibleEncoding); | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
@Specialization | ||
public Object isCompatible(RubySymbol first, RubySymbol second) { | ||
notDesignedForCompilation(); | ||
|
||
Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first, second); | ||
|
||
if (compatibleEncodingProfile.profile(compatibleEncoding != null)) { | ||
return RubyEncoding.getEncoding(compatibleEncoding); | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
} | ||
|
||
@CoreMethod(names = "default_external", onSingleton = true) | ||
|
@@ -217,6 +314,21 @@ public RubyEncoding defaultExternal(RubyEncoding encoding) { | |
return encoding; | ||
} | ||
|
||
@Specialization | ||
public RubyEncoding defaultExternal(RubyString encodingString) { | ||
notDesignedForCompilation(); | ||
|
||
final RubyEncoding rubyEncoding = RubyEncoding.getEncoding(encodingString.toString()); | ||
getContext().getRuntime().setDefaultExternalEncoding(rubyEncoding.getEncoding()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sets the default external encoding on the JRuby runtime. I'm not sure if we re-use that same value in Truffle. But since it passes the specs I won't worry too much. |
||
|
||
return rubyEncoding; | ||
} | ||
|
||
@Specialization | ||
public RubyEncoding defaultExternal(RubyNilClass nil) { | ||
throw new RaiseException(getContext().getCoreLibrary().argumentError("default external can not be nil", this)); | ||
} | ||
|
||
} | ||
|
||
@CoreMethod(names = "default_internal=", onSingleton = true, required = 1) | ||
|
@@ -361,6 +473,26 @@ public RubyArray list() { | |
} | ||
} | ||
|
||
|
||
@CoreMethod(names = "locale_charmap", onSingleton = true) | ||
public abstract static class LocaleCharacterMapNode extends CoreMethodNode { | ||
|
||
public LocaleCharacterMapNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public LocaleCharacterMapNode(LocaleCharacterMapNode prev) { | ||
super(prev); | ||
} | ||
|
||
@Specialization | ||
public RubyString localeCharacterMap() { | ||
notDesignedForCompilation(); | ||
final ByteList name = new ByteList(getContext().getRuntime().getEncodingService().getLocaleEncoding().getName()); | ||
return getContext().makeString(name); | ||
} | ||
} | ||
|
||
@CoreMethod(names = "dummy?") | ||
public abstract static class DummyNode extends CoreMethodNode { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we factor this out into a helper method that takes two
ByteList
objects?