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

Commits on Jun 25, 2016

  1. Copy the full SHA
    85b7f60 View commit details
  2. Copy the full SHA
    3be4166 View commit details
  3. Copy the full SHA
    41d284b View commit details
  4. [Truffle] More complete implementation of RSTRING_PTR.

    * RSTRING_LEN returns the bytesize.
    * Implement rb_yield.
    eregon committed Jun 25, 2016
    Copy the full SHA
    7b739c8 View commit details
6 changes: 6 additions & 0 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -63,6 +63,8 @@ VALUE get_rb_eRuntimeError(void);

// Conversions

VALUE CHR2FIX(char ch);

int NUM2INT(VALUE value);
unsigned int NUM2UINT(VALUE value);
long NUM2LONG(VALUE value);
@@ -99,6 +101,8 @@ 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_buf_new(long capacity);

// Symbol

ID rb_intern(const char *string);
@@ -145,6 +149,8 @@ int rb_scan_args(int argc, VALUE *argv, const char *format, ...);

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

VALUE rb_yield(VALUE value);

// Instance variables

VALUE rb_iv_get(VALUE object, const char *name);
Binary file modified lib/ruby/truffle/cext/ruby.su
Binary file not shown.
2 changes: 0 additions & 2 deletions spec/ruby/optional/capi/ext/jruby_truffle.h
Original file line number Diff line number Diff line change
@@ -466,8 +466,6 @@
#undef HAVE_RB_STR_SPLIT
#undef HAVE_RB_STR_SUBSTR
#undef HAVE_RB_STR_TO_STR
#undef HAVE_RSTRING_LEN
#undef HAVE_RSTRING_PTR
#undef HAVE_STRINGVALUE

#undef HAVE_RB_STR_FREE
3 changes: 0 additions & 3 deletions spec/truffle/tags/optional/capi/string_tags.txt
Original file line number Diff line number Diff line change
@@ -53,10 +53,7 @@ fails:C-API String function rb_str_subseq returns a byte-indexed substring
fails:C-API String function rb_str_substr returns a substring
fails:C-API String function rb_str_to_str calls #to_str to coerce the value to a String
fails:C-API String function rb_str_to_str raises a TypeError if coercion fails
fails:C-API String function RSTRING_PTR returns a pointer to the string's contents
fails:C-API String function RSTRING_PTR allows changing the characters in the string
fails:C-API String function RSTRING_PTR reflects changes after a rb_funcall
fails:C-API String function RSTRING_PTR returns a pointer to the contents of encoded pointer-sized string
fails:C-API String function RSTRING_LEN returns the size of the string
fails:C-API String function RSTRING_LENINT returns the size of a string
fails:C-API String function StringValue does not call #to_str on a String
8 changes: 8 additions & 0 deletions spec/truffle/truffle.mspec
Original file line number Diff line number Diff line change
@@ -92,6 +92,14 @@ class MSpecScript
"^spec/ruby/library/openssl/x509/name/parse_spec.rb"
]

set :capi, [
"spec/ruby/optional/capi/array_spec.rb",
"spec/ruby/optional/capi/class_spec.rb",
"spec/ruby/optional/capi/module_spec.rb",
"spec/ruby/optional/capi/proc_spec.rb",
"spec/ruby/optional/capi/string_spec.rb",
]

set :truffle, [
"spec/truffle/specs"
]
26 changes: 22 additions & 4 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -55,6 +55,10 @@ VALUE get_rb_eRuntimeError() {

// Conversions

VALUE CHR2FIX(char ch) {
return INT2FIX((unsigned char) ch);
}

int NUM2INT(VALUE value) {
return truffle_invoke_i(RUBY_CEXT, "NUM2INT", value);
}
@@ -126,16 +130,19 @@ VALUE rb_float_new(double value) {
// String

char *RSTRING_PTR(VALUE string) {
// Needs to return a fake char* which actually calls back into Ruby when read or written
return (char*) truffle_invoke(RUBY_CEXT, "RSTRING_PTR", string);
return string;
}

int RSTRING_LEN(VALUE string) {
return truffle_get_size(string);
return truffle_invoke_i(string, "bytesize");
}

VALUE rb_str_new_cstr(const char *string) {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_str_new_cstr", truffle_read_string(string));
if (truffle_is_truffle_object((VALUE) string)) {
return (VALUE) string;
} else {
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_str_new_cstr", truffle_read_string(string));
}
}

VALUE rb_intern_str(VALUE string) {
@@ -146,6 +153,10 @@ 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_buf_new(long capacity) {
return rb_str_new_cstr("");
}

// Symbol

ID rb_intern(const char *string) {
@@ -245,6 +256,12 @@ 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? */);
}

// Calls

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

// Instance variables

VALUE rb_iv_get(VALUE object, const char *name) {
@@ -294,6 +311,7 @@ void rb_define_global_const(const char *name, VALUE value) {

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

// Defining classes, modules and methods
24 changes: 24 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/interop/CExtNodes.java
Original file line number Diff line number Diff line change
@@ -9,11 +9,17 @@
*/
package org.jruby.truffle.interop;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.CreateCast;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.builtins.CoreClass;
import org.jruby.truffle.builtins.CoreMethod;
@@ -22,6 +28,7 @@
import org.jruby.truffle.core.cast.NameToJavaStringNodeGen;
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;

@@ -141,6 +148,23 @@ public int long2fix(int num) {

}

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

@TruffleBoundary
@Specialization
public DynamicObject getBlock() {
return Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<DynamicObject>() {
@Override
public DynamicObject visitFrame(FrameInstance frameInstance) {
Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY, true);
return RubyArguments.tryGetBlock(frame);
}
});
}

}

@NodeChildren({
@NodeChild(type = RubyNode.class, value = "module"),
@NodeChild(type = RubyNode.class, value = "name")
5 changes: 5 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -111,6 +111,11 @@ def rb_scan_args
raise 'not implemented'
end

def rb_yield(value)
block = get_block
block.call(value)
end

def rb_raise(object, name)
raise 'not implemented'
end