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

Commits on Jul 24, 2016

  1. [Truffle] PRI values.

    chrisseaton committed Jul 24, 2016
    Copy the full SHA
    b49c512 View commit details
  2. Copy the full SHA
    a41a24e View commit details
  3. Copy the full SHA
    4749417 View commit details
  4. Copy the full SHA
    e40708f View commit details
  5. Copy the full SHA
    9d7da8d View commit details
  6. Copy the full SHA
    6bfec07 View commit details
  7. [Truffle] Use MRI's RB_GC_GUARD, as I can't figure out how to make ou…

    …rs work without warnings.
    chrisseaton committed Jul 24, 2016
    Copy the full SHA
    4e5d6a0 View commit details
  8. Copy the full SHA
    0e8d452 View commit details
24 changes: 24 additions & 0 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -191,6 +191,7 @@ VALUE LONG2FIX(long value);

int rb_fix2int(VALUE value);
unsigned long rb_fix2uint(VALUE value);
int rb_long2int(long value);

ID SYM2ID(VALUE value);
VALUE ID2SYM(ID value);
@@ -209,6 +210,17 @@ double RFLOAT_VALUE(VALUE value);

// String

#define PRI_VALUE_PREFIX "l"
#define PRI_LONG_PREFIX "l"
#define PRI_64_PREFIX PRI_LONG_PREFIX
#define RUBY_PRI_VALUE_MARK "\v"
#define PRIdVALUE PRI_VALUE_PREFIX"d"
#define PRIoVALUE PRI_VALUE_PREFIX"o"
#define PRIuVALUE PRI_VALUE_PREFIX"u"
#define PRIxVALUE PRI_VALUE_PREFIX"x"
#define PRIXVALUE PRI_VALUE_PREFIX"X"
#define PRIsVALUE PRI_VALUE_PREFIX"i" RUBY_PRI_VALUE_MARK

char *RSTRING_PTR(VALUE string);
int rb_str_len(VALUE string);
#define RSTRING_LEN(str) rb_str_len(str)
@@ -257,12 +269,17 @@ VALUE rb_ary_dup(VALUE array);
VALUE rb_hash_new(void);
VALUE rb_hash_aref(VALUE hash, VALUE key);
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE value);
VALUE rb_hash_lookup(VALUE hash, VALUE key);
VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE default_value);

// Class

const char* rb_class2name(VALUE module);

VALUE rb_class_real(VALUE ruby_class);

VALUE rb_class_of(VALUE object);
VALUE rb_obj_class(VALUE object);
#define CLASS_OF(object) rb_class_of((VALUE) (object))

VALUE rb_obj_alloc(VALUE ruby_class);
@@ -288,6 +305,10 @@ VALUE rb_funcallv_public(VALUE object, ID name, int args_count, const VALUE *arg
#define rb_funcall2 rb_funcallv
#define rb_funcall3 rb_funcallv_public

#define RUBY_BLOCK_CALL_FUNC_TAKES_BLOCKARG 1
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg) VALUE yielded_arg, VALUE callback_arg, int args_count, const VALUE *args, VALUE block_arg
typedef VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg));

int rb_block_given_p();
VALUE rb_yield(VALUE value);

@@ -388,6 +409,9 @@ VALUE rb_complex_set_imag(VALUE complex, VALUE imag);

// GC

#define RB_GC_GUARD(v) \
(*__extension__ ({volatile VALUE *rb_gc_guarded_ptr = &(v); rb_gc_guarded_ptr;}))

void rb_gc_register_address(VALUE *address);
#define rb_global_variable(address) ;
VALUE rb_gc_enable();
22 changes: 21 additions & 1 deletion truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*
* This file contains code that is based on the Ruby API headers,
* This file contains code that is based on the Ruby API headers and implementation,
* copyright (C) Yukihiro Matsumoto, licensed under the 2-clause BSD licence
* as described in the file BSDL included with JRuby+Truffle.
*/
@@ -156,6 +156,10 @@ unsigned long rb_fix2uint(VALUE value) {
return truffle_invoke_l(RUBY_CEXT, "rb_fix2uint", value);
}

int rb_long2int(long value) {
return truffle_invoke_l(RUBY_CEXT, "rb_long2int", value);
}

ID SYM2ID(VALUE value) {
return (ID) value;
}
@@ -353,12 +357,28 @@ VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE value) {
return value;
}

VALUE rb_hash_lookup(VALUE hash, VALUE key) {
return truffle_read(hash, key);
}

VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE default_value) {
return (VALUE) truffle_invoke(hash, "fetch", key, default_value);
}

// Class

const char* rb_class2name(VALUE module) {
return RSTRING_PTR(truffle_invoke(module, "name"));
}

VALUE rb_class_real(VALUE ruby_class) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_class_real", ruby_class);
}

VALUE rb_obj_class(VALUE object) {
return rb_class_real(rb_class_of(object));
}

VALUE rb_class_of(VALUE object) {
return truffle_invoke(object, "class");
}
Original file line number Diff line number Diff line change
@@ -655,6 +655,21 @@ public DynamicObject rangeError(DynamicObject range, Node currentNode) {
Layouts.INT_RANGE.getEnd(range)), currentNode);
}

@TruffleBoundary
public DynamicObject rangeErrorConvertToInt(long value, Node currentNode) {
final String direction;

if (value < Integer.MIN_VALUE) {
direction = "small";
} else if (value > Integer.MAX_VALUE) {
direction = "big";
} else {
throw new IllegalArgumentException();
}

return rangeError(String.format("integer %d too %s to convert to `int'", value, direction), currentNode);
}

@TruffleBoundary
public DynamicObject rangeError(String message, Node currentNode) {
return ExceptionOperations.createRubyException(
Original file line number Diff line number Diff line change
@@ -28,13 +28,15 @@
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.builtins.CoreMethodNode;
import org.jruby.truffle.core.CoreLibrary;
import org.jruby.truffle.core.cast.NameToJavaStringNodeGen;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyConstant;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.constants.GetConstantNode;
import org.jruby.truffle.language.constants.LookupConstantNode;
import org.jruby.truffle.language.control.RaiseException;

@CoreClass("Truffle::CExt")
public class CExtNodes {
@@ -168,6 +170,30 @@ public int long2fix(int num) {

}

@CoreMethod(names = "rb_long2int", isModuleFunction = true, required = 1)
public abstract static class Long2Int extends CoreMethodArrayArgumentsNode {

@Specialization
public int long2fix(int num) {
return num;
}

@Specialization(guards = "fitsIntoInteger(num)")
public int long2fixInRange(long num) {
return (int) num;
}

@Specialization(guards = "!fitsIntoInteger(num)")
public int long2fixOutOfRange(long num) {
throw new RaiseException(coreExceptions().rangeErrorConvertToInt(num, this));
}

protected boolean fitsIntoInteger(long num) {
return CoreLibrary.fitsIntoInteger(num);
}

}

@CoreMethod(names = "CExtString", isModuleFunction = true, required = 1)
public abstract static class CExtStringNode extends CoreMethodArrayArgumentsNode {

4 changes: 4 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -255,6 +255,10 @@ def rb_hash_new
{}
end

def rb_class_real(ruby_class)
raise 'not implemented'
end

def rb_proc_new(function, value)
proc { |*args|
Truffle::Interop.execute(function, *args)