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

Commits on Jul 23, 2016

  1. Copy the full SHA
    ffe01dc View commit details
  2. Copy the full SHA
    5c122bd View commit details
  3. Copy the full SHA
    78baabe View commit details
  4. Copy the full SHA
    977b974 View commit details
  5. Copy the full SHA
    5e5446b View commit details

Commits on Jul 24, 2016

  1. Copy the full SHA
    04bfcbb View commit details
  2. [Truffle] rb_str_cat2

    chrisseaton committed Jul 24, 2016
    Copy the full SHA
    be417a3 View commit details
  3. [Truffle] rb_exc_raise

    chrisseaton committed Jul 24, 2016
    Copy the full SHA
    4bfb847 View commit details
27 changes: 24 additions & 3 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@ extern "C" {
#define xfree free
#define ALLOC_N(type, n) malloc(sizeof(type) * n)

typedef void* ID;
typedef void* VALUE;
typedef void *ID;
typedef void *VALUE;

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

@@ -159,8 +159,12 @@ VALUE get_rb_mKernel(void);
#define rb_mKernel get_rb_mKernel()

VALUE get_rb_eRuntimeError(void);
VALUE get_rb_eStandardError(void);
VALUE get_rb_eNoMemError(void);

#define rb_eRuntimeError get_rb_eRuntimeError()
#define rb_eStandardError get_rb_eStandardError()
#define rb_eNoMemError get_rb_eNoMemError()

// Conversions

@@ -209,7 +213,8 @@ VALUE rb_intern_str(VALUE string);
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_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);
#define StringValue(value) rb_string_value(&(value))
#define SafeStringValue StringValue
@@ -268,6 +273,7 @@ int rb_respond_to(VALUE object, ID name);

#define rb_funcall(object, name, ...) truffle_invoke(RUBY_CEXT, "rb_funcall", object, name, __VA_ARGS__)

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

// Instance variables
@@ -290,11 +296,14 @@ void rb_define_global_const(const char *name, VALUE value);

// Exceptions

NORETURN(void rb_exc_raise(VALUE exception));
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);

void rb_set_errinfo(VALUE error);

// Defining classes, modules and methods

VALUE rb_define_class(const char *name, VALUE superclass);
@@ -360,9 +369,21 @@ VALUE rb_complex_set_imag(VALUE complex, VALUE imag);
// GC

void rb_gc_register_address(VALUE *address);
#define rb_global_variable(address) ;
VALUE rb_gc_enable();
VALUE rb_gc_disable();

// Threads

typedef void *rb_nativethread_id_t;
typedef void *rb_nativethread_lock_t;

rb_nativethread_id_t rb_nativethread_self();
int rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock);
int rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock);
int rb_nativethread_lock_lock(rb_nativethread_lock_t *lock);
int rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock);

#if defined(__cplusplus)
}
#endif
1 change: 1 addition & 0 deletions lib/ruby/truffle/cext/ruby/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../ruby.h"
1 change: 1 addition & 0 deletions lib/ruby/truffle/cext/ruby/io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../ruby.h"
1 change: 1 addition & 0 deletions lib/ruby/truffle/cext/ruby/thread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../ruby.h"
1 change: 1 addition & 0 deletions lib/ruby/truffle/cext/ruby/thread_native.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../ruby.h"
60 changes: 57 additions & 3 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@
* copyright (C) Yukihiro Matsumoto, licensed under the 2-clause BSD licence
* as described in the file BSDL included with JRuby+Truffle.
*/


#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>

@@ -78,6 +79,14 @@ VALUE get_rb_eRuntimeError() {
return (VALUE) truffle_read(RUBY_CEXT, "rb_eRuntimeError");
}

VALUE get_rb_eStandardError(void) {
return (VALUE) truffle_read(RUBY_CEXT, "rb_eStandardError");
}

VALUE get_rb_eNoMemError(void) {
return (VALUE) truffle_read(RUBY_CEXT, "rb_eNoMemError");
}

// Conversions

VALUE CHR2FIX(char ch) {
@@ -202,8 +211,14 @@ VALUE rb_intern_str(VALUE string) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_intern_str", string);
}

void rb_str_cat(VALUE string, const char *to_concat, long length) {
VALUE 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);
return string;
}

VALUE rb_str_cat2(VALUE string, const char *to_concat) {
truffle_invoke(string, "concat", rb_str_new_cstr(to_concat));
return string;
}

VALUE rb_str_to_str(VALUE string) {
@@ -407,9 +422,15 @@ void rb_define_global_const(const char *name, VALUE value) {

// Raising exceptions

void rb_exc_raise(VALUE exception) {
truffle_invoke(RUBY_CEXT, "rb_exc_raise", exception);
abort();
}

void rb_raise(VALUE exception, const char *format, ...) {
fprintf(stderr, "rb_raise not implemented\n");
truffle_invoke(RUBY_CEXT, "rb_raise", format /*, where to get args? */);
exit(1); // To make the compiler happy
abort();
}

VALUE rb_protect(VALUE (*function)(VALUE), VALUE data, int *status) {
@@ -420,10 +441,17 @@ VALUE rb_protect(VALUE (*function)(VALUE), VALUE data, int *status) {
void rb_jump_tag(int status) {
if (status) {
// TODO CS 23-Jul-16
fprintf(stderr, "rb_jump_tag not implemented\n");
abort();
}
}

void rb_set_errinfo(VALUE error) {
// TODO CS 23-Jul-16
fprintf(stderr, "rb_set_errinfo not implemented\n");
abort();
}

// Defining classes, modules and methods

VALUE rb_define_class(const char *name, VALUE superclass) {
@@ -584,3 +612,29 @@ VALUE rb_gc_enable() {
VALUE rb_gc_disable() {
return truffle_invoke(RUBY_CEXT, "rb_gc_disable");
}

// Threads

rb_nativethread_id_t rb_nativethread_self() {
return truffle_invoke(RUBY_CEXT, "rb_nativethread_self");
}

int rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock) {
*lock = truffle_invoke(RUBY_CEXT, "rb_nativethread_lock_initialize");
return 0;
}

int rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock) {
*lock = NULL;
return 0;
}

int rb_nativethread_lock_lock(rb_nativethread_lock_t *lock) {
truffle_invoke(lock, "lock");
return 0;
}

int rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock) {
truffle_invoke(lock, "unlock");
return 0;
}
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.CreateCast;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
@@ -19,13 +20,16 @@
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import org.jruby.truffle.builtins.CoreClass;
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.builtins.CoreMethodNode;
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;
@@ -189,6 +193,23 @@ public DynamicObject toRubyString(DynamicObject string) {

}

@CoreMethod(names = "rb_block_given_p", isModuleFunction = true, needsCallerFrame = true)
public abstract static class BlockGivenNode extends CoreMethodArrayArgumentsNode {

@Specialization
public boolean blockGiven(MaterializedFrame callerFrame,
@Cached("createBinaryProfile()") ConditionProfile blockProfile) {
return blockProfile.profile(RubyArguments.getBlock(callerFrame) != null);
}

@TruffleBoundary
@Specialization
public boolean blockGiven(NotProvided noCallerFrame) {
return RubyArguments.getBlock(Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, false)) != null;
}

}

@CoreMethod(names = "get_block", isModuleFunction = true)
public abstract static class GetBlockNode extends CoreMethodArrayArgumentsNode {

22 changes: 21 additions & 1 deletion truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -144,7 +144,15 @@ def rb_mKernel
end

def rb_eRuntimeError
raise 'not implemented'
RuntimeError
end

def rb_eStandardError
StandardError
end

def rb_eNoMemError
NoMemError
end

def rb_fix2int(value)
@@ -254,6 +262,10 @@ def rb_yield(value)
block.call(value)
end

def rb_exc_raise(exception)
raise exception
end

def rb_raise(object, name)
raise 'not implemented'
end
@@ -407,6 +419,14 @@ def rb_gc_disable
GC.disable
end

def rb_nativethread_self
Thread.current
end

def rb_nativethread_lock_initialize
Mutex.new
end

end

Truffle::Interop.export(:ruby_cext, Truffle::CExt)