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

Commits on Jul 24, 2016

  1. Copy the full SHA
    324e588 View commit details
  2. [Truffle] rb_Integer

    chrisseaton committed Jul 24, 2016
    Copy the full SHA
    e9b5bf5 View commit details
  3. [Truffle] rb_string_value_ptr, StringValuePtr and stubbed rb_string_v…

    …alue_cstr, StringValueCStr
    chrisseaton committed Jul 24, 2016
    Copy the full SHA
    fb21cf3 View commit details
  4. Copy the full SHA
    66f7ae4 View commit details
Showing with 58 additions and 6 deletions.
  1. +28 −5 lib/ruby/truffle/cext/ruby.h
  2. +26 −1 truffle/src/main/c/cext/ruby.c
  3. +4 −0 truffle/src/main/ruby/core/truffle/cext.rb
33 changes: 28 additions & 5 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -26,14 +26,26 @@ extern "C" {
#include <string.h>
#include <math.h>

#include <truffle.h>

// Support

#define RUBY_CEXT truffle_import_cached("ruby_cext")

// Configuration

#define JRUBY_TRUFFLE 1

#define SIZEOF_INT 32
#define SIZEOF_LONG 64

#include <truffle.h>
#define HAVE_SYS_TIME_H

#define RUBY_CEXT truffle_import_cached("ruby_cext")
// Macros

#define NORETURN(X) __attribute__((__noreturn__)) X

// Basics

#define xmalloc malloc
#define xfree free
@@ -42,8 +54,6 @@ extern "C" {
typedef void *ID;
typedef void *VALUE;

#define NORETURN(X) __attribute__((__noreturn__)) X

// Types

enum ruby_value_type {
@@ -196,12 +206,18 @@ int rb_long2int(long value);
ID SYM2ID(VALUE value);
VALUE ID2SYM(ID value);

#define NUM2TIMET(value) NUM2LONG(value)

// Type checks

int NIL_P(VALUE value);
int FIXNUM_P(VALUE value);
int RTEST(VALUE value);

// Integer

VALUE rb_Integer(VALUE value);

// Float

VALUE rb_float_new(double value);
@@ -232,9 +248,13 @@ VALUE rb_str_new_cstr(const char *string);
VALUE rb_str_cat(VALUE string, const char *to_concat, long length);
VALUE rb_str_cat2(VALUE string, const char *to_concat);
VALUE rb_str_to_str(VALUE string);
VALUE rb_string_value(volatile VALUE *value_pointer);
#define StringValue(value) rb_string_value(&(value))
#define SafeStringValue StringValue
VALUE rb_string_value(VALUE *value_pointer);
char *rb_string_value_ptr(volatile VALUE* value_pointer);
char *rb_string_value_cstr(volatile VALUE* value_pointer);
#define StringValuePtr(string) rb_string_value_ptr(&(string))
#define StringValueCStr(string) rb_string_value_cstr(&(string))
VALUE rb_str_buf_new(long capacity);
VALUE rb_sprintf(const char *format, ...);
VALUE rb_vsprintf(const char *format, va_list args);
@@ -317,6 +337,9 @@ VALUE rb_yield(VALUE value);
VALUE rb_iv_get(VALUE object, const char *name);
VALUE rb_iv_set(VALUE object, const char *name, VALUE value);

VALUE rb_ivar_get(VALUE object, ID name);
VALUE rb_ivar_set(VALUE object, ID name, VALUE value);

VALUE rb_ivar_lookup(VALUE object, const char *name, VALUE default_value);
VALUE rb_attr_get(VALUE object, const char *name);

27 changes: 26 additions & 1 deletion truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -182,6 +182,12 @@ int RTEST(VALUE value) {
return truffle_invoke_b(RUBY_CEXT, "RTEST", value);
}

// Integer

VALUE rb_Integer(VALUE value) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_Integer", value);
}

// Float

VALUE rb_float_new(double value) {
@@ -240,7 +246,7 @@ VALUE rb_str_to_str(VALUE string) {
return (VALUE) truffle_invoke(string, "to_str");
}

VALUE rb_string_value(VALUE *value_pointer) {
VALUE rb_string_value(volatile VALUE *value_pointer) {
VALUE value = *value_pointer;

if (!RB_TYPE_P(value, T_STRING)) {
@@ -251,6 +257,16 @@ VALUE rb_string_value(VALUE *value_pointer) {
return value;
}

char *rb_string_value_ptr(volatile VALUE* value_pointer) {
VALUE string = rb_string_value(value_pointer);
return RSTRING_PTR(string);
}

char *rb_string_value_cstr(volatile VALUE* value_pointer) {
fprintf(stderr, "rb_string_value_cstr not implemented\n");
abort();
}

VALUE rb_str_buf_new(long capacity) {
return rb_str_new_cstr("");
}
@@ -448,6 +464,15 @@ VALUE rb_iv_set(VALUE object, const char *name, VALUE value) {
return value;
}

VALUE rb_ivar_get(VALUE object, ID name) {
return truffle_read(object, name);
}

VALUE rb_ivar_set(VALUE object, ID name, VALUE value) {
truffle_write(object, name, value);
return value;
}

VALUE rb_ivar_lookup(VALUE object, const char *name, VALUE default_value) {
return truffle_invoke(RUBY_CEXT, "rb_ivar_lookup", name, default_value);
}
4 changes: 4 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -203,6 +203,10 @@ def rb_float_new(value)
value.to_f
end

def rb_Integer(value)
Integer(value)
end

def rb_Float(value)
Float(value)
end