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

Commits on Apr 20, 2015

  1. Copy the full SHA
    5539cbd View commit details
  2. Copy the full SHA
    190234d View commit details
  3. Copy the full SHA
    4e6eab6 View commit details
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/module/include_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
fails:Module#include raises a TypeError when the argument is not a Module
fails:Module#include doesn't include module if it is included in a super class
fails:Module#include preserves ancestor order
fails:Module#include detects cyclic includes
fails:Module#include returns the class it's included into
fails:Module#include? raises a TypeError when no module was given
fails:Module#include accepts no-arguments

This file was deleted.

Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.nodes.rubinius.ByteArrayNodesFactory;
import org.jruby.truffle.nodes.rubinius.PosixNodesFactory;
import org.jruby.truffle.nodes.rubinius.RubiniusTypeNodes;
import org.jruby.truffle.nodes.rubinius.RubiniusTypeNodesFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -101,6 +103,7 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, ByteArrayNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TimeNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, PosixNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, RubiniusTypeNodesFactory.getFactories());

// Give the core library manager a chance to tweak some of those methods

Original file line number Diff line number Diff line change
@@ -61,13 +61,14 @@ private static void addMethod(RubyClass rubyObjectClass, MethodDetails methodDet
final RubyContext context = rubyObjectClass.getContext();

RubyModule module;
String fullName = methodDetails.getClassAnnotation().name();

if (methodDetails.getClassAnnotation().name().equals("main")) {
if (fullName.equals("main")) {
module = context.getCoreLibrary().getMainObject().getSingletonClass(null);
} else {
module = rubyObjectClass;

for (String moduleName : methodDetails.getClassAnnotation().name().split("::")) {
for (String moduleName : fullName.split("::")) {
final RubyConstant constant = ModuleOperations.lookupConstant(context, LexicalScope.NONE, module, moduleName);

if (constant == null) {
@@ -78,7 +79,7 @@ private static void addMethod(RubyClass rubyObjectClass, MethodDetails methodDet
}
}

assert module != null : methodDetails.getClassAnnotation().name();
assert module != null : fullName;

final CoreMethod anno = methodDetails.getMethodAnnotation();

Original file line number Diff line number Diff line change
@@ -1161,76 +1161,6 @@ public Object initializeCopy(RubyClass self, RubyClass from) {

}

@CoreMethod(names = "include", argumentsAsArray = true, required = 1)
public abstract static class IncludeNode extends CoreMethodNode {

@Child private CallDispatchHeadNode appendFeaturesNode;
@Child private CallDispatchHeadNode includedNode;

public IncludeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
appendFeaturesNode = DispatchHeadNodeFactory.createMethodCall(context, true);
includedNode = DispatchHeadNodeFactory.createMethodCall(context, true);
}

public IncludeNode(IncludeNode prev) {
super(prev);
appendFeaturesNode = prev.appendFeaturesNode;
includedNode = prev.includedNode;
}

@Specialization
public RubyNilClass include(VirtualFrame frame, RubyModule module, Object[] args) {
notDesignedForCompilation();

// Note that we traverse the arguments backwards

for (int n = args.length - 1; n >= 0; n--) {
if (args[n] instanceof RubyModule) {
final RubyModule included = (RubyModule) args[n];

appendFeaturesNode.call(frame, included, "append_features", null, module);
includedNode.call(frame, included, "included", null, module);
}
}

return nil();
}
}

@CoreMethod(names = "include?", required = 1)
public abstract static class IncludePNode extends CoreMethodNode {

@Child private DispatchHeadNode appendFeaturesNode;

public IncludePNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
appendFeaturesNode = DispatchHeadNodeFactory.createMethodCall(context);
}

public IncludePNode(IncludePNode prev) {
super(prev);
appendFeaturesNode = prev.appendFeaturesNode;
}

@Specialization
public boolean include(RubyModule module, RubyModule included) {
notDesignedForCompilation();

ModuleChain ancestor = module.getParentModule();

while (ancestor != null) {
if (ancestor.getActualModule() == included) {
return true;
}

ancestor = ancestor.getParentModule();
}

return false;
}
}

@CoreMethod(names = "included", required = 1, visibility = Visibility.PRIVATE)
public abstract static class IncludedNode extends CoreMethodNode {

@@ -1681,7 +1611,7 @@ public PublicInstanceMethodsNode(PublicInstanceMethodsNode prev) {

@Specialization
public RubyArray publicInstanceMethods(RubyModule module, UndefinedPlaceholder argument) {
return publicInstanceMethods(module, false);
return publicInstanceMethods(module, true);
}

@Specialization
@@ -1690,12 +1620,10 @@ public RubyArray publicInstanceMethods(RubyModule module, boolean includeAncesto

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(),
module.filterMethods(includeAncestors, new RubyModule.MethodFilter() {

@Override
public boolean filter(InternalMethod method) {
return method.getVisibility() == Visibility.PUBLIC;
}

}).toArray());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.core.CoreClass;
import org.jruby.truffle.nodes.core.CoreMethod;
import org.jruby.truffle.nodes.core.YieldingCoreMethodNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyProc;

@CoreClass(name = "Rubinius::Type")
public abstract class RubiniusTypeNodes {

@CoreMethod(names = "each_ancestor", onSingleton = true, required = 1, needsBlock = true)
public abstract static class EachAncestorNode extends YieldingCoreMethodNode {

public EachAncestorNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public EachAncestorNode(EachAncestorNode prev) {
super(prev);
}

@Specialization
public RubyNilClass eachAncestor(VirtualFrame frame, RubyModule module, RubyProc block) {
for (RubyModule ancestor : module.ancestors()) {
yield(frame, block, ancestor);
}
return nil();
}

}

}
Original file line number Diff line number Diff line change
@@ -321,9 +321,13 @@ public CoreLibrary(RubyContext context) {
truffleDebugModule = defineModule(truffleModule, "Debug");
defineModule(truffleModule, "Primitive");

// Rubinius

rubiniusModule = defineModule("Rubinius");

rubiniusFFIModule = defineModule(rubiniusModule, "FFI");
defineModule(defineModule(rubiniusFFIModule, "Platform"), "POSIX");
defineModule(rubiniusModule, "Type");

byteArrayClass = defineClass(rubiniusModule, objectClass, "ByteArray");
lookupTableClass = defineClass(rubiniusModule, hashClass, "LookupTable");
6 changes: 5 additions & 1 deletion truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
@@ -23,6 +23,10 @@
require_relative 'core/rubinius/api/shims/metrics'
require_relative 'core/rubinius/api/shims/module'

# Load alpha.rb

require_relative 'core/rubinius/alpha'

# Load bootstrap (ordered according to Rubinius' load_order.txt)

require_relative 'core/rubinius/bootstrap/basic_object'
@@ -180,7 +184,7 @@
#require_relative 'core/rubinius/delta/file'
#require_relative 'core/rubinius/delta/rubinius'
#require_relative 'core/rubinius/delta/runtime'
#require_relative 'core/rubinius/delta/module'
require_relative 'core/rubinius/delta/module'
require_relative 'core/rubinius/delta/class'
#require_relative 'core/rubinius/delta/file_test'
require_relative 'core/rubinius/delta/kernel'
45 changes: 45 additions & 0 deletions truffle/src/main/ruby/core/rubinius/alpha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Rubinius nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Only part of Rubinius' alpha.rb

class Module

# :internal:
#
# Basic version of .include used in kernel code.
#
# Redefined in kernel/delta/module.rb.
#
def include(mod)
Rubinius.privately do
mod.append_features self # Truffle: moved the append_features inside the privately
mod.included self
end
self
end

end
13 changes: 12 additions & 1 deletion truffle/src/main/ruby/core/rubinius/common/module.rb
Original file line number Diff line number Diff line change
@@ -40,13 +40,24 @@

class Module

def include?(mod)
if !mod.kind_of?(Module) or mod.kind_of?(Class)
raise TypeError, "wrong argument type #{mod.class} (expected Module)"
end

return false if self.equal?(mod)

Rubinius::Type.each_ancestor(self) { |m| return true if mod.equal?(m) }

false
end

def extended(name)
end
private :extended

def method_added(name)
end

private :method_added

end
51 changes: 51 additions & 0 deletions truffle/src/main/ruby/core/rubinius/delta/module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Rubinius nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Only part of Rubinius' module.rb

class Module

# Invokes <code>Module#append_features</code> and
# <code>Module#included</code> on each argument, passing in self.
#
def include(*modules)
modules.reverse_each do |mod|
if !mod.kind_of?(Module) or mod.kind_of?(Class)
raise TypeError, "wrong argument type #{mod.class} (expected Module)"
end

Rubinius.privately do
mod.append_features self
end

Rubinius.privately do
mod.included self
end
end
self
end

end