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

Commits on Jan 8, 2016

  1. Copy the full SHA
    ce104bd View commit details
  2. Copy the full SHA
    09f3379 View commit details
Original file line number Diff line number Diff line change
@@ -31,60 +31,37 @@ public class MethodDefinitionNode extends RubyNode {
private final String name;
private final SharedMethodInfo sharedMethodInfo;
private final CallTarget callTarget;
private final boolean captureBlock;
private final boolean captureDefaultDefinee;

@Child private GetDefaultDefineeNode getDefaultDefineeNode;

public MethodDefinitionNode(RubyContext context, SourceSection sourceSection, String name, SharedMethodInfo sharedMethodInfo,
CallTarget callTarget, boolean captureBlock, boolean captureDefaultDefinee) {
public MethodDefinitionNode(RubyContext context, SourceSection sourceSection, String name, SharedMethodInfo sharedMethodInfo, CallTarget callTarget) {
super(context, sourceSection);
this.name = name;
this.sharedMethodInfo = sharedMethodInfo;
this.callTarget = callTarget;
this.captureBlock = captureBlock;
this.captureDefaultDefinee = captureDefaultDefinee;
}

public InternalMethod executeMethod(VirtualFrame frame) {
final DynamicObject dummyModule = getContext().getCoreLibrary().getObjectClass();
final Visibility dummyVisibility = Visibility.PUBLIC;

final DynamicObject capturedBlock;

if (captureBlock) {
capturedBlock = RubyArguments.getBlock(frame.getArguments());
} else {
capturedBlock = null;
}

final DynamicObject capturedDefaultDefinee;

if (captureDefaultDefinee && RubyArguments.getDeclarationContext(frame.getArguments()) == DeclarationContext.INSTANCE_EVAL) {
if (RubyArguments.getDeclarationContext(frame.getArguments()) == DeclarationContext.INSTANCE_EVAL) {
if (getDefaultDefineeNode == null) {
CompilerDirectives.transferToInterpreter();
getDefaultDefineeNode = insert(new GetDefaultDefineeNode(getContext(), getSourceSection()));
}

capturedDefaultDefinee = getDefaultDefineeNode.execute(frame);
} else {
capturedDefaultDefinee = null;
}

return new InternalMethod(sharedMethodInfo, name, dummyModule, dummyVisibility, false, null, callTarget, capturedBlock, capturedDefaultDefinee);
return new InternalMethod(sharedMethodInfo, name, dummyModule, dummyVisibility, false, null, callTarget, null, capturedDefaultDefinee);
}

@Override
public Object execute(VirtualFrame frame) {
return executeMethod(frame);
}

public String getName() {
return name;
}

public SharedMethodInfo getSharedMethodInfo() {
return sharedMethodInfo;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2013, 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.methods;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;

/**
* Define a method from a module body (module/class/class << self ... end).
*/
public class ModuleBodyDefinitionNode extends RubyNode {

private final String name;
private final SharedMethodInfo sharedMethodInfo;
private final CallTarget callTarget;
private final boolean captureBlock;

public ModuleBodyDefinitionNode(RubyContext context, SourceSection sourceSection, String name, SharedMethodInfo sharedMethodInfo,
CallTarget callTarget, boolean captureBlock) {
super(context, sourceSection);
this.name = name;
this.sharedMethodInfo = sharedMethodInfo;
this.callTarget = callTarget;
this.captureBlock = captureBlock;
}

public InternalMethod executeMethod(VirtualFrame frame) {
final DynamicObject dummyModule = getContext().getCoreLibrary().getObjectClass();
final Visibility dummyVisibility = Visibility.PUBLIC;

final DynamicObject capturedBlock;

if (captureBlock) {
capturedBlock = RubyArguments.getBlock(frame.getArguments());
} else {
capturedBlock = null;
}

return new InternalMethod(sharedMethodInfo, name, dummyModule, dummyVisibility, false, null, callTarget, capturedBlock, null);
}

@Override
public Object execute(VirtualFrame frame) {
return executeMethod(frame);
}

}
Original file line number Diff line number Diff line change
@@ -15,9 +15,10 @@
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.nodes.methods.MethodDefinitionNode;
import org.jruby.truffle.nodes.methods.ModuleBodyDefinitionNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
@@ -33,12 +34,12 @@ public class OpenModuleNode extends RubyNode {
final protected LexicalScope lexicalScope;
@Child private IndirectCallNode callModuleDefinitionNode;

final private MethodDefinitionNode definitionMethod;
final private ModuleBodyDefinitionNode definitionMethod;

public OpenModuleNode(RubyContext context, SourceSection sourceSection, RubyNode definingModule, MethodDefinitionNode definitionMethod, LexicalScope lexicalScope) {
public OpenModuleNode(RubyContext context, SourceSection sourceSection, RubyNode definingModule, ModuleBodyDefinitionNode definition, LexicalScope lexicalScope) {
super(context, sourceSection);
this.definingModule = definingModule;
this.definitionMethod = definitionMethod;
this.definitionMethod = definition;
this.lexicalScope = lexicalScope;
callModuleDefinitionNode = Truffle.getRuntime().createIndirectCallNode();
}
Original file line number Diff line number Diff line change
@@ -812,9 +812,9 @@ private RubyNode openModule(SourceSection sourceSection, RubyNode defineOrGetNod

final BodyTranslator moduleTranslator = new BodyTranslator(currentNode, context, this, newEnvironment, source, false);

final MethodDefinitionNode definitionMethod = moduleTranslator.compileClassNode(sourceSection, name, bodyNode, sclass);
final ModuleBodyDefinitionNode definition = moduleTranslator.compileClassNode(sourceSection, name, bodyNode, sclass);

return new OpenModuleNode(context, sourceSection, defineOrGetNode, definitionMethod, newLexicalScope);
return new OpenModuleNode(context, sourceSection, defineOrGetNode, definition, newLexicalScope);
} finally {
environment.popLexicalScope();
}
@@ -829,7 +829,7 @@ private RubyNode openModule(SourceSection sourceSection, RubyNode defineOrGetNod
* newly allocated module or class.
* </p>
*/
private MethodDefinitionNode compileClassNode(SourceSection sourceSection, String name, org.jruby.ast.Node bodyNode, boolean sclass) {
private ModuleBodyDefinitionNode compileClassNode(SourceSection sourceSection, String name, org.jruby.ast.Node bodyNode, boolean sclass) {
RubyNode body;

parentSourceSection.push(sourceSection);
@@ -845,14 +845,13 @@ private MethodDefinitionNode compileClassNode(SourceSection sourceSection, Strin

final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body, environment.needsDeclarationFrame());

final MethodDefinitionNode definitionNode = new MethodDefinitionNode(
final ModuleBodyDefinitionNode definitionNode = new ModuleBodyDefinitionNode(
context,
sourceSection,
environment.getSharedMethodInfo().getName(),
environment.getSharedMethodInfo(),
Truffle.getRuntime().createCallTarget(rootNode),
sclass,
false);
sclass);

return definitionNode;
}
Original file line number Diff line number Diff line change
@@ -212,7 +212,7 @@ public MethodDefinitionNode compileMethodNode(SourceSection sourceSection, Strin
context, body.getSourceSection(), environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body, environment.needsDeclarationFrame());

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
return new MethodDefinitionNode(context, sourceSection, methodName, environment.getSharedMethodInfo(), callTarget, false, true);
return new MethodDefinitionNode(context, sourceSection, methodName, environment.getSharedMethodInfo(), callTarget);
}

private void declareArguments(SourceSection sourceSection, String methodName, SharedMethodInfo sharedMethodInfo) {