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

Commits on Sep 4, 2016

  1. Copy the full SHA
    2db00bf View commit details
  2. Copy the full SHA
    ef8161c View commit details
  3. [Truffle] When checking for previously defined classes and modules in…

    … cexts, don't use inheritance.
    chrisseaton committed Sep 4, 2016
    Copy the full SHA
    126cae9 View commit details
  4. Copy the full SHA
    7e987a6 View commit details
  5. 2
    Copy the full SHA
    9edb5f9 View commit details
  6. Copy the full SHA
    d8b3a9d View commit details
  7. [Truffle] Fix ULONG2NUM

    chrisseaton committed Sep 4, 2016
    Copy the full SHA
    96df75c View commit details
  8. Copy the full SHA
    2dff605 View commit details
  9. [Truffle] Fix rb_attr

    chrisseaton committed Sep 4, 2016
    2
    Copy the full SHA
    21cbec5 View commit details

Commits on Sep 5, 2016

  1. Copy the full SHA
    d9136b7 View commit details
  2. Copy the full SHA
    e3dddb4 View commit details
  3. Copy the full SHA
    e957794 View commit details
2 changes: 1 addition & 1 deletion lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -518,7 +518,7 @@ void rb_undef(VALUE module, ID name);

void rb_attr(VALUE ruby_class, ID name, int read, int write, int ex);

typedef VALUE (*rb_alloc_func_t)(VALUE);
typedef VALUE (*rb_alloc_func_t)(VALUE ruby_class);
void rb_define_alloc_func(VALUE ruby_class, rb_alloc_func_t alloc_function);

// Mutexes
19 changes: 7 additions & 12 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -270,8 +270,7 @@ int RTEST(VALUE value) {
// Kernel

VALUE rb_require(const char *feature) {
rb_jt_error("rb_require not implemented");
abort();
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_require", rb_str_new_cstr(feature));
}

// Object
@@ -552,21 +551,20 @@ VALUE rb_hash_aref(VALUE hash, VALUE key) {
}

VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE value) {
truffle_write(hash, key, value);
return (VALUE) truffle_invoke((void *)hash, "[]=", key, value);
return value;
}

VALUE rb_hash_lookup(VALUE hash, VALUE key) {
return truffle_read(hash, key);
return (VALUE) truffle_invoke((void *)hash, "[]", key);
}

VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE default_value) {
return (VALUE) truffle_invoke((void *)hash, "fetch", key, default_value);
}

VALUE rb_hash_set_ifnone(VALUE hash, VALUE if_none) {
rb_jt_error("rb_hash_set_ifnone not implemented");
abort();
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_hash_set_ifnone", hash, if_none);
}

st_index_t rb_memhash(const void *data, long length) {
@@ -613,8 +611,7 @@ VALUE rb_class_path(VALUE ruby_class) {
}

VALUE rb_path2class(const char *string) {
rb_jt_error("rb_path2class not implemented");
abort();
return (VALUE) truffle_invoke(RUBY_CEXT, "rb_path2class", rb_str_new_cstr(string));
}

// Proc
@@ -864,13 +861,11 @@ void rb_undef(VALUE module, ID name) {
}

void rb_attr(VALUE ruby_class, ID name, int read, int write, int ex) {
rb_jt_error("rb_attr not implemented");
abort();
truffle_invoke(RUBY_CEXT, "rb_attr", ruby_class, name, read, write, ex);
}

void rb_define_alloc_func(VALUE ruby_class, rb_alloc_func_t alloc_function) {
rb_jt_error("rb_define_alloc_func not implemented");
abort();
truffle_invoke(RUBY_CEXT, "rb_define_alloc_func", ruby_class, truffle_address_to_function(alloc_function));
}

// Rational
Original file line number Diff line number Diff line change
@@ -24,13 +24,19 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
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.builtins.NonStandard;
import org.jruby.truffle.core.CoreLibrary;
import org.jruby.truffle.core.cast.NameToJavaStringNodeGen;
import org.jruby.truffle.core.module.ModuleNodes;
import org.jruby.truffle.core.module.ModuleNodesFactory;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyConstant;
import org.jruby.truffle.language.RubyNode;
@@ -176,7 +182,7 @@ public int uint2num(int num) {
public abstract static class LONG2NUMNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int long2num(int num) {
public long long2num(long num) {
return num;
}

@@ -186,7 +192,7 @@ public int long2num(int num) {
public abstract static class ULONG2NUMNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int ulong2num(int num) {
public long ulong2num(long num) {
// TODO CS 2-May-16 what to do about the fact it's unsigned?
return num;
}
@@ -197,7 +203,7 @@ public int ulong2num(int num) {
public abstract static class LONG2FIXNode extends CoreMethodArrayArgumentsNode {

@Specialization
public int long2fix(int num) {
public long long2fix(long num) {
return num;
}

@@ -319,4 +325,22 @@ public int ioHandle(DynamicObject io) {

}

@CoreMethod(names = "cext_module_function", isModuleFunction = true, required = 2)
public abstract static class CextModuleFunctionNode extends CoreMethodArrayArgumentsNode {

@Child
ModuleNodes.SetVisibilityNode setVisibilityNode;

public CextModuleFunctionNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
setVisibilityNode = ModuleNodesFactory.SetVisibilityNodeGen.create(context, sourceSection, Visibility.MODULE_FUNCTION, null, null);
}

@Specialization(guards = {"isRubyModule(module)", "isRubySymbol(name)"})
public DynamicObject cextModuleFunction(VirtualFrame frame, DynamicObject module, DynamicObject name) {
return setVisibilityNode.executeSetVisibility(frame, module, new Object[]{name});
}

}

}
57 changes: 46 additions & 11 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -167,15 +167,15 @@ def rb_mEnumerable
end

def rb_mWaitReadable
WaitReadable
IO::WaitReadable
end

def rb_mComparable
Comparable
end

def rb_mWaitWritable
WaitWritable
IO::WaitWritable
end

def rb_eException
@@ -242,6 +242,10 @@ def RTEST(value)
!nil.equal?(value) && !false.equal?(value)
end

def rb_require(feature)
require feature
end

def RB_OBJ_TAINTABLE(object)
case object
when TrueClass, FalseClass, Fixnum, Float, NilClass, Symbol
@@ -324,10 +328,19 @@ def rb_hash_new
{}
end

def rb_hash_set_ifnone(hash, value)
hash.default = value
end

def rb_class_real(ruby_class)
raise 'not implemented'
end

def rb_path2class(path)
# More than a bit of a hack
eval(path)
end

def rb_proc_new(function, value)
proc { |*args|
Truffle::Interop.execute(function, *args)
@@ -365,29 +378,29 @@ def rb_raise(object, name)
end

def rb_define_class_under(mod, name, superclass)
if mod.const_defined?(name)
klass = mod.const_get(name)
unless klass.class == Class
if mod.const_defined?(name, false)
current_class = mod.const_get(name, false)
unless current_class.class == Class
raise TypeError, "#{mod}::#{name} is not a class"
end
if superclass != klass.superclass
if superclass != current_class.superclass
raise TypeError, "superclass mismatch for class #{name}"
end
klass
else
mod.const_set(name, Class.new(superclass))
mod.const_set name, Class.new(superclass)
end
end

def rb_define_module_under(mod, name)
if mod.const_defined?(name)
val = mod.const_get(name)
if mod.const_defined?(name, false)
val = mod.const_get(name, false)
unless val.class == Module
raise TypeError, "#{mod}::#{name} is not a module"
end
val
else
mod.const_set(name, Module.new)
mod.const_set name, Module.new
end
end

@@ -410,13 +423,19 @@ def rb_define_protected_method(mod, name, function, argc)

def rb_define_module_function(mod, name, function, argc)
rb_define_method(mod, name, function, argc)
mod.send :module_function, name
cext_module_function mod, name.to_sym
end

def rb_define_singleton_method(object, name, function, argc)
rb_define_method(object.singleton_class, name, function, argc)
end

def rb_define_alloc_func(ruby_class, function)
ruby_class.send(:define_method, :allocate) do
function.call(self)
end
end

def rb_alias(mod, new_name, old_name)
mod.send(:alias_method, new_name, old_name)
end
@@ -427,6 +446,22 @@ def rb_undef(mod, name)
end
end

def rb_attr(ruby_class, name, read, write, ex)
raise 'rb_attr with ex not supported' unless ex.zero?

if read
ruby_class.send :define_method, name do
instance_variable_get(name)
end
end

if write
ruby_class.send :define_method, :"#{name}=" do |value|
instance_variable_set(name, value)
end
end
end

def rb_funcall(object, name, argc, args=[])
object.__send__(name, *args)
end