-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into truffle-head
# Conflicts: # mx.jruby/mx_jruby.py
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
Showing
51 changed files
with
495 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
# frozen-literal-string: true | ||
|
||
# Create convenience methods for top-level java packages so we do not need to prefix | ||
# with Java::com. We undef these methods within Package in case we run into 'com.foo.com'. | ||
# Convenience methods for top-level packages without the need to prefix e.g. `Java::java.util.ArrayList`. | ||
# @note These methods are undef-ed within Java package stubs (in case of *com.foo.com*). | ||
module Kernel | ||
# Java package short-cut method. | ||
# @example | ||
# java.lang.System | ||
def java | ||
JavaUtilities.get_package_module_dot_format('java') | ||
JavaUtilities.get_package_module_dot_format('java') # stub | ||
end | ||
|
||
# Java package short-cut method. | ||
# @example | ||
# javax.swing.SwingUtilities | ||
def javax | ||
JavaUtilities.get_package_module_dot_format('javax') | ||
JavaUtilities.get_package_module_dot_format('javax') # stub | ||
end | ||
|
||
# Java package short-cut method. | ||
# @example | ||
# javafx.application.Platform | ||
def javafx | ||
JavaUtilities.get_package_module_dot_format('javafx') | ||
JavaUtilities.get_package_module_dot_format('javafx') # stub | ||
end | ||
|
||
# Java package short-cut method. | ||
# @example | ||
# com.google.common.base.Strings | ||
def com | ||
JavaUtilities.get_package_module_dot_format('com') | ||
JavaUtilities.get_package_module_dot_format('com') # stub | ||
end | ||
|
||
# Java package short-cut method. | ||
# @example | ||
# org.json.JSONArray | ||
def org | ||
JavaUtilities.get_package_module_dot_format('org') | ||
JavaUtilities.get_package_module_dot_format('org') # stub | ||
end | ||
end | ||
end if false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
``` | ||
$ git clone https://github.com/lucasocon/openweather.git | ||
RUBYOPT='-I samples/truffle/interop/weather/openweather/lib -I samples/truffle/interop/weather' graalvm/bin/js samples/truffle/interop/weather/weather.js | ||
``` | ||
|
||
The demo hangs after printing the temperature, as some Ruby service threads | ||
get stuck and aren't shutting down properly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Interop.eval('application/x-ruby', 'require "weather"'); | ||
|
||
temperature_in_city = Interop.import('temperature_in_city') | ||
|
||
console.log('Temperature in New York now: ' + temperature_in_city.call('New York') + '℃'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'openweather2' | ||
|
||
Openweather2.configure do |config| | ||
# This is the endpoint and API key from the tests in the Openweather2 gem | ||
config.endpoint = 'http://api.openweathermap.org/data/2.5/weather' | ||
config.apikey = 'dd7073d18e3085d0300b6678615d904d' | ||
end | ||
|
||
def temperature_in_city(name) | ||
name = Truffle::Interop.from_java_string(name) | ||
weather = Openweather2.get_weather(city: name, units: 'metric') | ||
weather.temperature | ||
end | ||
|
||
Truffle::Interop.export_method :temperature_in_city |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
# code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
# redistribute it and/or modify it under the terms of the: | ||
# | ||
# Eclipse Public License version 1.0 | ||
# GNU General Public License version 2 | ||
# GNU Lesser General Public License version 2.1 | ||
|
||
example "Encoding::US_ASCII.ascii_compatible?", true | ||
example "Encoding::UTF_16BE.ascii_compatible?", false | ||
|
||
example "Encoding::ISO_2022_JP.dummy?", true | ||
example "Encoding::UTF_8.dummy?", false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ flag : SPACE | |
| PLUS | ||
| MINUS | ||
| STAR | ||
| NUMBER DOLLAR ; | ||
| HASH | ||
| argumentIndex=NUMBER DOLLAR ; | ||
|
||
literal : LITERAL ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
truffle/src/main/java/org/jruby/truffle/core/encoding/EncodingManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (c) 2014, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.core.encoding; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import org.jcodings.Encoding; | ||
import org.jcodings.EncodingDB; | ||
import org.jcodings.specific.ISO8859_16Encoding; | ||
import org.jcodings.specific.USASCIIEncoding; | ||
import org.jruby.truffle.Layouts; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.rope.Rope; | ||
import org.jruby.truffle.core.string.StringOperations; | ||
import org.jruby.util.ByteList; | ||
import org.jruby.util.encoding.ISO_8859_16; | ||
|
||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.charset.UnsupportedCharsetException; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
public class EncodingManager { | ||
|
||
private final DynamicObject[] ENCODING_LIST_BY_ENCODING_LIST_INDEX = new DynamicObject[EncodingDB.getEncodings().size()]; | ||
private final DynamicObject[] ENCODING_LIST_BY_ENCODING_INDEX = new DynamicObject[EncodingDB.getEncodings().size()]; | ||
private final Map<String, DynamicObject> LOOKUP = new HashMap<>(); | ||
|
||
private final RubyContext context; | ||
|
||
public EncodingManager(RubyContext context) { | ||
this.context = context; | ||
} | ||
|
||
@TruffleBoundary | ||
public static DynamicObject newRubyEncoding(RubyContext context, DynamicObject encodingClass, Encoding encoding, byte[] name, int p, int end, boolean dummy) { | ||
// TODO (nirvdrum 21-Jun-16): We probably don't need to create a ByteList and two Ropes. Without any guarantees on the code range of the encoding name, however, we must be conservative. | ||
final Rope rope = StringOperations.ropeFromByteList(new ByteList(name, p, end, USASCIIEncoding.INSTANCE, false)); | ||
final Rope cachedRope = context.getRopeTable().getRope(rope.getBytes(), rope.getEncoding(), rope.getCodeRange()); | ||
final DynamicObject string = context.getFrozenStrings().getFrozenString(cachedRope); | ||
|
||
return Layouts.ENCODING.createEncoding(Layouts.CLASS.getInstanceFactory(encodingClass), encoding, string, dummy); | ||
} | ||
|
||
public DynamicObject[] getUnsafeEncodingList() { | ||
return ENCODING_LIST_BY_ENCODING_LIST_INDEX; | ||
} | ||
|
||
public DynamicObject getRubyEncoding(Encoding encoding) { | ||
DynamicObject rubyEncoding = ENCODING_LIST_BY_ENCODING_INDEX[encoding.getIndex()]; | ||
|
||
if (rubyEncoding == null) { | ||
// Bounded by the number of encodings | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
|
||
rubyEncoding = LOOKUP.get(new String(encoding.getName(), StandardCharsets.UTF_8).toLowerCase(Locale.ENGLISH)); | ||
ENCODING_LIST_BY_ENCODING_INDEX[encoding.getIndex()] = rubyEncoding; | ||
} | ||
|
||
return rubyEncoding; | ||
} | ||
|
||
@TruffleBoundary | ||
public DynamicObject getRubyEncoding(String name) { | ||
return LOOKUP.get(name.toLowerCase(Locale.ENGLISH)); | ||
} | ||
|
||
@TruffleBoundary | ||
public DynamicObject getRubyEncoding(int encodingListIndex) { | ||
return ENCODING_LIST_BY_ENCODING_LIST_INDEX[encodingListIndex]; | ||
} | ||
|
||
@TruffleBoundary | ||
public void defineEncoding(DynamicObject encodingClass, EncodingDB.Entry encodingEntry, byte[] name, int p, int end) { | ||
final DynamicObject rubyEncoding = newRubyEncoding(context, encodingClass, null, name, p, end, encodingEntry.isDummy()); | ||
|
||
ENCODING_LIST_BY_ENCODING_LIST_INDEX[encodingEntry.getIndex()] = rubyEncoding; | ||
LOOKUP.put(Layouts.ENCODING.getName(rubyEncoding).toString().toLowerCase(Locale.ENGLISH), rubyEncoding); | ||
} | ||
|
||
@TruffleBoundary | ||
public void defineAlias(int encodingListIndex, String name) { | ||
final DynamicObject rubyEncoding = getRubyEncoding(encodingListIndex); | ||
|
||
LOOKUP.put(name.toLowerCase(Locale.ENGLISH), rubyEncoding); | ||
} | ||
|
||
@TruffleBoundary | ||
public Encoding getLocaleEncoding() { | ||
return context.getJRubyRuntime().getEncodingService().getLocaleEncoding(); | ||
} | ||
|
||
@TruffleBoundary | ||
public static Charset charsetForEncoding(Encoding encoding) { | ||
final String encodingName = encoding.toString(); | ||
|
||
if (encodingName.equals("ASCII-8BIT")) { | ||
return Charset.forName("ISO-8859-1"); | ||
} | ||
|
||
if (encoding == ISO8859_16Encoding.INSTANCE) { | ||
return ISO_8859_16.INSTANCE; | ||
} | ||
|
||
try { | ||
return Charset.forName(encodingName); | ||
} catch (UnsupportedCharsetException uce) { | ||
throw new UnsupportedOperationException("no java.nio.charset.Charset found for encoding `" + encoding.toString() + "'", uce); | ||
} | ||
} | ||
|
||
} |
158 changes: 69 additions & 89 deletions
158
truffle/src/main/java/org/jruby/truffle/core/encoding/EncodingNodes.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...le/src/main/java/org/jruby/truffle/core/format/read/array/ReadArgumentIndexValueNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.core.format.read.array; | ||
|
||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.NodeChildren; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.format.FormatNode; | ||
import org.jruby.truffle.core.format.read.SourceNode; | ||
|
||
@NodeChildren({ | ||
@NodeChild(value = "source", type = SourceNode.class), | ||
}) | ||
public abstract class ReadArgumentIndexValueNode extends FormatNode { | ||
|
||
private final int index; | ||
|
||
public ReadArgumentIndexValueNode(RubyContext context, int index) { | ||
super(context); | ||
this.index = index - 1; | ||
} | ||
|
||
@Specialization | ||
public Object read(VirtualFrame frame, Object[] source) { | ||
return source[this.index]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters