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

Commits on Jul 23, 2016

  1. Copy the full SHA
    fec1f5a View commit details
  2. Copy the full SHA
    c6c9b3f View commit details
  3. Copy the full SHA
    49d6ff1 View commit details
  4. [Truffle] RB_TYPE_P

    chrisseaton committed Jul 23, 2016
    Copy the full SHA
    9a9dbc5 View commit details
  5. Copy the full SHA
    9bd2147 View commit details
Showing with 161 additions and 2 deletions.
  1. +18 −2 lib/ruby/truffle/cext/ruby.h
  2. +45 −0 truffle/src/main/c/cext/ruby.c
  3. +98 −0 truffle/src/main/ruby/core/truffle/cext.rb
20 changes: 18 additions & 2 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ extern "C" {

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
@@ -124,6 +125,15 @@ struct rb_data_type_struct {
VALUE flags;
};

int rb_type(VALUE value);
#define TYPE(value) rb_type((VALUE) (value))
bool RB_TYPE_P(VALUE value, int type);

void rb_check_type(VALUE value, int type);
#define Check_Type(v,t) rb_check_type((VALUE)(v), (t))

VALUE rb_obj_is_kind_of(VALUE object, VALUE ruby_class);

// Constants

VALUE get_Qfalse(void);
@@ -198,7 +208,10 @@ VALUE rb_str_new(const char *string, long length);
VALUE rb_str_new_cstr(const char *string);
#define rb_str_new2 rb_str_new_cstr
void rb_str_cat(VALUE string, const char *to_concat, long length);

VALUE rb_str_to_str(VALUE string);
#define StringValue(value) rb_string_value(&(value))
#define SafeStringValue StringValue
VALUE rb_string_value(VALUE *value_pointer);
VALUE rb_str_buf_new(long capacity);

// Symbol
@@ -268,10 +281,13 @@ VALUE rb_const_set(VALUE module, ID name, VALUE value);
VALUE rb_define_const(VALUE module, const char *name, VALUE value);
void rb_define_global_const(const char *name, VALUE value);

// Raising exceptions
// Exceptions

NORETURN(void rb_raise(VALUE exception, const char *format, ...));

VALUE rb_protect(VALUE (*function)(VALUE), VALUE data, int *status);
void rb_jump_tag(int status);

// Defining classes, modules and methods

VALUE rb_define_class(const char *name, VALUE superclass);
45 changes: 45 additions & 0 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -18,6 +18,24 @@

#define RUBY_CEXT truffle_import_cached("ruby_cext")

// Types

int rb_type(VALUE value) {
return truffle_invoke_i(RUBY_CEXT, "rb_type", value);
}

bool RB_TYPE_P(VALUE value, int type) {
return truffle_invoke_i(RUBY_CEXT, "RB_TYPE_P", value, type);
}

void rb_check_type(VALUE value, int type) {
truffle_invoke(RUBY_CEXT, "rb_check_type", value);
}

VALUE rb_obj_is_kind_of(VALUE object, VALUE ruby_class) {
return truffle_invoke(object, "kind_of?", ruby_class);
}

// Constants

VALUE get_Qfalse() {
@@ -185,6 +203,21 @@ void rb_str_cat(VALUE string, const char *to_concat, long length) {
truffle_invoke(RUBY_CEXT, "rb_str_cat", string, rb_str_new_cstr(to_concat), length);
}

VALUE rb_str_to_str(VALUE string) {
return (VALUE) truffle_invoke(string, "to_str");
}

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

if (!RB_TYPE_P(value, T_STRING)) {
value = rb_str_to_str(value);
*value_pointer = value;
}

return value;
}

VALUE rb_str_buf_new(long capacity) {
return rb_str_new_cstr("");
}
@@ -354,6 +387,18 @@ void rb_raise(VALUE exception, const char *format, ...) {
exit(1); // To make the compiler happy
}

VALUE rb_protect(VALUE (*function)(VALUE), VALUE data, int *status) {
// TODO CS 23-Jul-16
return function(data);
}

void rb_jump_tag(int status) {
if (status) {
// TODO CS 23-Jul-16
abort();
}
}

// Defining classes, modules and methods

VALUE rb_define_class(const char *name, VALUE superclass) {
98 changes: 98 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -7,12 +7,110 @@
# GNU Lesser General Public License version 2.1

module Truffle::CExt

T_NONE = 0x00

T_OBJECT = 0x01
T_CLASS = 0x02
T_MODULE = 0x03
T_FLOAT = 0x04
T_STRING = 0x05
T_REGEXP = 0x06
T_ARRAY = 0x07
T_HASH = 0x08
T_STRUCT = 0x09
T_BIGNUM = 0x0a
T_FILE = 0x0b
T_DATA = 0x0c
T_MATCH = 0x0d
T_COMPLEX = 0x0e
T_RATIONAL = 0x0f

T_NIL = 0x11
T_TRUE = 0x12
T_FALSE = 0x13
T_SYMBOL = 0x14
T_FIXNUM = 0x15
T_UNDEF = 0x16

T_IMEMO = 0x1a
T_NODE = 0x1b
T_ICLASS = 0x1c
T_ZOMBIE = 0x1d

T_MASK = 0x1f

module_function

def supported?
Interop.mime_type_supported?('application/x-sulong-library')
end

def rb_type(value)
# TODO CS 23-Jul-16 we could do with making this a kind of specialising case
# that puts never seen cases behind a transfer

case value
when Module
T_MODULE
when Class
T_CLASS
when Float
T_FLOAT
when String
T_STRING
when Regexp
T_REGEXP
when Array
T_ARRAY
when Hash
T_HASH
when Struct
T_STRUCT
when Bignum
T_BIGNUM
when File
T_FILE
when Complex
T_COMPLEX
when Rational
T_RATIONAL

when NilClass
T_NIL
when TrueClass
T_TRUE
when FalseClass
T_FALSE
when Symbol
T_SYMBOL
when Fixnum
T_FIXNUM

when Object
T_OBJECT

else
raise 'unknown type'
end
end

def RB_TYPE_P(value, type)
case type
when T_STRING
value.is_a?(String)
else
raise 'unknown type'
end
end

def rb_check_type(value, type)
# TODO CS 23-Jul-16 there's more to this method than this...
if rb_type(value) != type
raise 'unexpected type'
end
end

def Qfalse
false
end