Skip to content

Commit

Permalink
Showing 5 changed files with 37 additions and 12 deletions.
12 changes: 9 additions & 3 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ extern "C" {

#define JRUBY_TRUFFLE 1

#include <truffle.h>

#define xmalloc malloc
#define xfree free
#define ALLOC_N(type, n) malloc(sizeof(type) * n)
@@ -40,8 +42,8 @@ VALUE get_rb_eException(void);
#define Qfalse get_Qfalse()
#define Qtrue get_Qtrue()
#define Qnil get_Qnil()
#define rb_cProc get_rb_cProc();
#define rb_eException get_rb_eException();
#define rb_cProc get_rb_cProc()
#define rb_eException get_rb_eException()

VALUE get_rb_cObject(void);
VALUE get_rb_cArray(void);
@@ -129,13 +131,17 @@ VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE value);

const char* rb_class2name(VALUE module);

// Proc

VALUE rb_proc_new(void *function, VALUE value);

// Utilities

int rb_scan_args(int argc, VALUE *argv, const char *format, ...);

// Calls

VALUE rb_funcall(VALUE object, ID name, int argc, ...);
#define rb_funcall(object, name, argc, ...) truffle_invoke(object, "__send__", name, ##__VA_ARGS__)

This comment has been minimized.

Copy link
@nirvdrum

nirvdrum Jun 3, 2016

Contributor

Should that be ##__VAR_ARGS__?

This comment has been minimized.

Copy link
@eregon

This comment has been minimized.

Copy link
@nirvdrum

nirvdrum Jun 5, 2016

Contributor

Interesting. Thanks.


// Instance variables

3 changes: 0 additions & 3 deletions spec/ruby/optional/capi/ext/jruby_truffle.h
Original file line number Diff line number Diff line change
@@ -413,9 +413,6 @@
#undef HAVE_RB_TYPE_P
#undef HAVE_BUILTIN_TYPE

/* Proc */
#undef HAVE_RB_PROC_NEW

/* Range */
#undef HAVE_RB_RANGE_NEW
#undef HAVE_RB_RANGE_VALUES
7 changes: 7 additions & 0 deletions spec/truffle/tags/optional/capi/proc_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fails:C-API Proc function rb_proc_new returns a Proc instance correctly described in #inspect without source location
fails:C-API Proc function rb_proc_new returns a Proc instance with #source_location == nil
fails:C-API when calling Proc.new from a C function returns the Proc passed by the Ruby code calling the C function
fails:C-API when calling Proc.new from a C function returns the Proc passed to the Ruby method when the C function calls other Ruby methods before calling Proc.new
fails:C-API when calling Proc.new from a C function raises an ArgumentError when the C function calls a Ruby method and that method calls a C function that calls Proc.new
fails:C-API when calling Proc.new from a C function returns the most recent Proc passed when the Ruby method called the C function
fails:C-API when calling Proc.new from a C function returns the Proc passed from the original Ruby call to the C function
17 changes: 11 additions & 6 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -40,6 +40,11 @@ VALUE get_rb_cHash() {
return (VALUE) truffle_read(RUBY_CEXT, "rb_cHash");
}

VALUE get_rb_cProc() {
return (VALUE) truffle_read(RUBY_CEXT, "rb_cProc");
}


VALUE get_rb_mKernel() {
return (VALUE) truffle_read(RUBY_CEXT, "rb_mKernel");
}
@@ -228,16 +233,16 @@ const char* rb_class2name(VALUE module) {
return RSTRING_PTR(truffle_invoke(module, "name"));
}

// Utilities
// Proc

int rb_scan_args(int argc, VALUE *argv, const char *format, ...) {
return truffle_invoke_i(RUBY_CEXT, "rb_scan_args", argc, argv, format /*, where to get args? */);
VALUE rb_proc_new(void *function, VALUE value) {
return truffle_invoke(RUBY_CEXT, "rb_proc_new", truffle_address_to_function(function), value);
}

// Calls
// Utilities

VALUE rb_funcall(VALUE object, ID name, int argc, ...) {
return truffle_invoke(object, name /*, where to get args? */);
int rb_scan_args(int argc, VALUE *argv, const char *format, ...) {
return truffle_invoke_i(RUBY_CEXT, "rb_scan_args", argc, argv, format /*, where to get args? */);
}

// Instance variables
10 changes: 10 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -38,6 +38,10 @@ def rb_cHash
Hash
end

def rb_cProc
Proc
end

def rb_mKernel
::Kernel
end
@@ -98,6 +102,12 @@ def rb_hash_new
{}
end

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

def rb_scan_args
raise 'not implemented'
end

0 comments on commit e89a2bf

Please sign in to comment.