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

Commits on Jan 11, 2015

  1. Copy the full SHA
    e6ac68e View commit details
  2. [Truffle] Kernel#method

    chrisseaton committed Jan 11, 2015
    Copy the full SHA
    4e4a5f5 View commit details
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
Original file line number Diff line number Diff line change
@@ -96,6 +96,8 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TrufflePrimitiveNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, EncodingNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, EncodingConverterNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, MethodNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, UnboundMethodNodesFactory.getFactories());

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

8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -182,12 +182,12 @@ public RubyEncodingConverter executeRubyEncodingConverter(VirtualFrame frame) th
return RubyTypesGen.RUBYTYPES.expectRubyEncodingConverter(execute(frame));
}

public DispatchAction executeDispatchAction(VirtualFrame frame) throws UnexpectedResultException {
throw new UnsupportedOperationException();
public RubyMethod executeRubyMethod(VirtualFrame frame) throws UnexpectedResultException {
return RubyTypesGen.RUBYTYPES.expectRubyMethod(execute(frame));
}

public LexicalScope executeLexicalScope(VirtualFrame frame) throws UnexpectedResultException {
throw new UnsupportedOperationException();
public RubyUnboundMethod executeRubyUnboundMethod(VirtualFrame frame) throws UnexpectedResultException {
return RubyTypesGen.RUBYTYPES.expectRubyUnboundMethod(execute(frame));
}

public void executeVoid(VirtualFrame frame) {
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/truffle/nodes/RubyTypes.java
Original file line number Diff line number Diff line change
@@ -20,8 +20,6 @@
* using. Used by the DSL.
*/
@TypeSystem({ //
DispatchAction.class, //
LexicalScope.class, //
UndefinedPlaceholder.class, //
boolean.class, //
byte.class, //
@@ -55,6 +53,8 @@
RubyThread.class, //
RubyTime.class, //
RubyEncodingConverter.class, //
RubyMethod.class, //
RubyUnboundMethod.class, //
RubyBasicObject.class, //
ThreadLocal.class, //
Object[].class})
28 changes: 28 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -1316,6 +1316,34 @@ public Object loop(VirtualFrame frame) {
}
}

@CoreMethod(names = "method", required = 1)
public abstract static class MethodNode extends CoreMethodNode {

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

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

@Specialization
public RubyMethod method(Object object, RubySymbol name) {
notDesignedForCompilation();

// TODO(CS, 11-Jan-15) cache this lookup

final InternalMethod method = ModuleOperations.lookupMethod(getContext().getCoreLibrary().getMetaClass(object), name.toString());

if (method == null) {
throw new UnsupportedOperationException();
}

return new RubyMethod(getContext().getCoreLibrary().getMethodClass(), object, method);
}

}

@CoreMethod(names = "methods", optional = 1)
public abstract static class MethodsNode extends CoreMethodNode {

60 changes: 60 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/MethodNodes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.core;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.RubyMethod;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.InternalMethod;

@CoreClass(name = "Method")
public abstract class MethodNodes {

@CoreMethod(names = "call", argumentsAsArray = true)
public abstract static class CallNode extends CoreMethodNode {

@Child private IndirectCallNode callNode;

public CallNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
callNode = Truffle.getRuntime().createIndirectCallNode();
}

public CallNode(CallNode prev) {
super(prev);
callNode = prev.callNode;
}

@Specialization
public Object call(VirtualFrame frame, RubyMethod method, Object... arguments) {
// TODO(CS 11-Jan-15) should use a cache and DirectCallNode here so that we can inline - but it's
// incompatible with our current dispatch chain.

final InternalMethod internalMethod = method.getMethod();

return callNode.call(frame, method.getMethod().getCallTarget(), RubyArguments.pack(
internalMethod,
internalMethod.getDeclarationFrame(),
method.getObject(),
null,
arguments));
}

}

}
28 changes: 28 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -1261,6 +1261,34 @@ public RubyArray instanceMethods(RubyModule module, boolean includeAncestors) {
}
}

@CoreMethod(names = "instance_method", required = 1)
public abstract static class InstanceMethodNode extends CoreMethodNode {

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

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

@Specialization
public RubyUnboundMethod instanceMethod(RubyModule module, RubySymbol name) {
notDesignedForCompilation();

// TODO(CS, 11-Jan-15) cache this lookup

final InternalMethod method = ModuleOperations.lookupMethod(module, name.toString());

if (method == null) {
throw new UnsupportedOperationException();
}

return new RubyUnboundMethod(getContext().getCoreLibrary().getUnboundMethodClass(), method);
}

}

@CoreMethod(names = "private_constant", argumentsAsArray = true)
public abstract static class PrivateConstantNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.core;

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.yield.YieldDispatchHeadNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyMethod;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.core.RubyUnboundMethod;

@CoreClass(name = "UnboundMethod")
public abstract class UnboundMethodNodes {

@CoreMethod(names = "bind", required = 1)
public abstract static class BindNode extends CoreMethodNode {

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

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

@Specialization
public RubyMethod bind(RubyUnboundMethod unboundMethod, Object object) {
return new RubyMethod(getContext().getCoreLibrary().getMethodClass(), object, unboundMethod.getMethod());
}

}

}
12 changes: 12 additions & 0 deletions core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -111,6 +111,8 @@ public class CoreLibrary {
@CompilerDirectives.CompilationFinal private RubyClass edomClass;
@CompilerDirectives.CompilationFinal private RubyClass encodingConverterClass;
@CompilerDirectives.CompilationFinal private RubyClass encodingCompatibilityErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass methodClass;
@CompilerDirectives.CompilationFinal private RubyClass unboundMethodClass;

@CompilerDirectives.CompilationFinal private RubyArray argv;
@CompilerDirectives.CompilationFinal private RubyBasicObject globalVariablesObject;
@@ -280,6 +282,8 @@ public void initialize() {
zeroDivisionErrorClass.setAllocator(new RubyException.ExceptionAllocator());
encodingConverterClass = new RubyClass(context, encodingClass, objectClass, "Converter");
encodingConverterClass.setAllocator(new RubyEncodingConverter.EncodingConverterAllocator());
methodClass = new RubyClass(context, objectClass, objectClass, "Method");
unboundMethodClass = new RubyClass(context, objectClass, objectClass, "UnboundMethod");

encodingCompatibilityErrorClass = new RubyClass(context, encodingClass, standardErrorClass, "CompatibilityError");
encodingCompatibilityErrorClass.setAllocator(new RubyException.ExceptionAllocator());
@@ -916,4 +920,12 @@ public RubyClass getArgumentErrorClass() {
public RubyClass getEncodingConverterClass() {
return encodingConverterClass;
}

public RubyClass getUnboundMethodClass() {
return unboundMethodClass;
}

public RubyClass getMethodClass() {
return methodClass;
}
}
32 changes: 32 additions & 0 deletions core/src/main/java/org/jruby/truffle/runtime/core/RubyMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.runtime.core;

import org.jruby.truffle.runtime.methods.InternalMethod;

public class RubyMethod extends RubyBasicObject {

private Object object;
private InternalMethod method;

public RubyMethod(RubyClass rubyClass, Object object, InternalMethod method) {
super(rubyClass);
this.object = object;
this.method = method;
}

public InternalMethod getMethod() {
return method;
}

public Object getObject() {
return object;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.runtime.core;

import org.jruby.truffle.runtime.methods.InternalMethod;

public class RubyUnboundMethod extends RubyBasicObject {

private InternalMethod method;

public RubyUnboundMethod(RubyClass rubyClass, InternalMethod method) {
super(rubyClass);
this.method = method;
}

public InternalMethod getMethod() {
return method;
}
}