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

Commits on Oct 1, 2015

  1. Copy the full SHA
    a56d58a View commit details
  2. [Truffle] Save the default definee in the frame and use it to know wh…

    …ere to define methods.
    eregon committed Oct 1, 2015
    Copy the full SHA
    c5925bd View commit details
  3. Copy the full SHA
    c8faf0a View commit details
  4. Copy the full SHA
    e297e50 View commit details
  5. Copy the full SHA
    fc8dd47 View commit details
  6. Copy the full SHA
    325cf46 View commit details
  7. Copy the full SHA
    7b4b14f View commit details
Showing with 292 additions and 136 deletions.
  1. +0 −6 spec/truffle/tags/language/def_tags.txt
  2. +10 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/BasicObjectNodes.java
  3. +3 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/BindingNodes.java
  4. +19 −10 truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
  5. +5 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/MethodNodes.java
  6. +6 −3 truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
  7. +3 −0 truffle/src/main/java/org/jruby/truffle/nodes/core/ProcNodes.java
  8. +3 −6 truffle/src/main/java/org/jruby/truffle/nodes/core/YieldingCoreMethodNode.java
  9. +4 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayNodes.java
  10. +3 −0 truffle/src/main/java/org/jruby/truffle/nodes/dispatch/CachedDispatchNode.java
  11. +3 −0 truffle/src/main/java/org/jruby/truffle/nodes/dispatch/UncachedDispatchNode.java
  12. +3 −7 truffle/src/main/java/org/jruby/truffle/nodes/methods/AddMethodNode.java
  13. +76 −0 truffle/src/main/java/org/jruby/truffle/nodes/methods/DeclarationContext.java
  14. +37 −0 truffle/src/main/java/org/jruby/truffle/nodes/methods/GetDefaultDefineeNode.java
  15. +4 −1 truffle/src/main/java/org/jruby/truffle/nodes/objects/OpenModuleNode.java
  16. +3 −1 truffle/src/main/java/org/jruby/truffle/nodes/supercall/GeneralSuperCallNode.java
  17. +5 −1 truffle/src/main/java/org/jruby/truffle/nodes/supercall/GeneralSuperReCallNode.java
  18. +9 −2 truffle/src/main/java/org/jruby/truffle/nodes/yield/CallBlockNode.java
  19. +7 −1 truffle/src/main/java/org/jruby/truffle/nodes/yield/YieldDispatchHeadNode.java
  20. +14 −2 truffle/src/main/java/org/jruby/truffle/runtime/RubyArguments.java
  21. +27 −37 truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
  22. +11 −4 truffle/src/main/java/org/jruby/truffle/runtime/subsystems/SimpleShell.java
  23. +2 −16 truffle/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
  24. +3 −1 truffle/src/main/java/org/jruby/truffle/translator/ModuleTranslator.java
  25. +2 −2 truffle/src/main/java/org/jruby/truffle/translator/TranslatorDriver.java
  26. +30 −28 truffle/src/main/ruby/core/rubinius/common/exception.rb
6 changes: 0 additions & 6 deletions spec/truffle/tags/language/def_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
fails:A nested method definition creates an instance method when evaluated in an instance method
fails:A nested method definition creates a class method when evaluated in a class method
fails:A method definition inside an instance_eval creates a class method when the receiver is a class
fails:A method definition in an eval creates an instance method
fails:A method definition in an eval creates a class method
fails:A method definition in an eval creates a singleton method
fails:An instance method with a default argument does not call a method with the same name as the local
fails:An instance method with a default argument shadows an existing method with the same name as the local
Original file line number Diff line number Diff line change
@@ -15,8 +15,10 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.nodes.Node.Child;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
@@ -25,6 +27,7 @@
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.dispatch.RubyCallNode;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.nodes.methods.UnsupportedOperationBehavior;
import org.jruby.truffle.nodes.objects.AllocateObjectNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
@@ -136,13 +139,13 @@ public abstract static class InstanceEvalNode extends CoreMethodArrayArgumentsNo

public InstanceEvalNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
yield = new YieldDispatchHeadNode(context);
yield = new YieldDispatchHeadNode(context, DeclarationContext.INSTANCE_EVAL);
}

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(string)")
public Object instanceEval(Object receiver, DynamicObject string, NotProvided block) {
return getContext().instanceEval(Layouts.STRING.getByteList(string), receiver, this);
return getContext().instanceEval(Layouts.STRING.getByteList(string), receiver, "(eval)", this);
}

@Specialization(guards = "isRubyProc(block)")
@@ -153,17 +156,20 @@ public Object instanceEval(VirtualFrame frame, Object receiver, NotProvided stri
}

@CoreMethod(names = "instance_exec", needsBlock = true, rest = true)
public abstract static class InstanceExecNode extends YieldingCoreMethodNode {
public abstract static class InstanceExecNode extends CoreMethodArrayArgumentsNode {

@Child private YieldDispatchHeadNode yield;

public InstanceExecNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
yield = new YieldDispatchHeadNode(context, DeclarationContext.INSTANCE_EVAL);
}

@Specialization(guards = "isRubyProc(block)")
public Object instanceExec(VirtualFrame frame, Object receiver, Object[] arguments, DynamicObject block) {
CompilerDirectives.transferToInterpreter();

return yieldWithModifiedSelf(frame, block, receiver, arguments);
return yield.dispatchWithModifiedSelf(frame, block, receiver, arguments);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -45,8 +45,10 @@ public static DynamicObject createBinding(RubyContext context, MaterializedFrame
RubyArguments.pack(
RubyArguments.getMethod(arguments),
frame,
null, RubyArguments.getSelf(arguments),
null,
RubyArguments.getSelf(arguments),
RubyArguments.getBlock(arguments),
RubyArguments.getDeclarationContext(arguments),
RubyArguments.extractUserArguments(arguments)),
new FrameDescriptor(context.getCoreLibrary().getNilObject()));

29 changes: 19 additions & 10 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jcodings.Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
@@ -77,6 +78,7 @@
import org.jruby.truffle.runtime.subsystems.ThreadManager.BlockingAction;
import org.jruby.truffle.translator.NodeWrapper;
import org.jruby.truffle.translator.TranslatorDriver;
import org.jruby.truffle.translator.TranslatorDriver.ParserContext;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

@@ -562,7 +564,7 @@ public Object evalNoBindingCached(
final InternalMethod method = new InternalMethod(
cachedRootNode.getRootNode().getSharedMethodInfo(),
cachedRootNode.getRootNode().getSharedMethodInfo().getName(),
getContext().getCoreLibrary().getObjectClass(),
RubyArguments.getMethod(parentFrame.getArguments()).getDeclaringModule(),
Visibility.PUBLIC,
false,
cachedCallTarget,
@@ -571,17 +573,19 @@ public Object evalNoBindingCached(
return callNode.call(frame, RubyArguments.pack(
method,
parentFrame,
null, callerSelf,
null,
new Object[]{}));
callerSelf,
null,
RubyArguments.getDeclarationContext(parentFrame.getArguments()),
new Object[] {}));
}

@Specialization(guards = {
"isRubyString(source)"
}, contains = "evalNoBindingCached")
public Object evalNoBindingUncached(VirtualFrame frame, DynamicObject source, NotProvided binding,
NotProvided filename, NotProvided lineNumber) {
return getContext().eval(Layouts.STRING.getByteList(source), getCallerBinding(frame), true, this);
return doEval(source, getCallerBinding(frame), "(eval)", true);
}

@Specialization(guards = {
@@ -600,9 +604,7 @@ public Object evalNilBinding(VirtualFrame frame, DynamicObject source, DynamicOb
})
public Object evalBinding(DynamicObject source, DynamicObject binding, NotProvided filename,
NotProvided lineNumber) {
final Object result = getContext().eval(Layouts.STRING.getByteList(source), binding, false, this);
assert result != null;
return result;
return doEval(source, binding, "(eval)", false);
}

@Specialization(guards = {
@@ -622,7 +624,7 @@ public Object evalBinding(DynamicObject source, DynamicObject binding, DynamicOb
"isRubyString(filename)" })
public Object evalBindingFilename(DynamicObject source, DynamicObject binding, DynamicObject filename,
NotProvided lineNumber) {
return getContext().eval(Layouts.STRING.getByteList(source), binding, false, filename.toString(), this);
return evalBindingFilenameLine(source, binding, filename, 0);
}

@Specialization(guards = {
@@ -642,7 +644,7 @@ public Object evalBindingFilename(DynamicObject source, DynamicObject binding, D
"isRubyString(filename)" })
public Object evalBindingFilenameLine(DynamicObject source, DynamicObject binding, DynamicObject filename,
int lineNumber) {
return getContext().eval(Layouts.STRING.getByteList(source), binding, false, filename.toString(), this);
return doEval(source, binding, filename.toString(), false);
}

@TruffleBoundary
@@ -654,6 +656,13 @@ public Object evalBadBinding(DynamicObject source, DynamicObject badBinding, Not
throw new RaiseException(getContext().getCoreLibrary().typeErrorWrongArgumentType(badBinding, "binding", this));
}

@TruffleBoundary
private Object doEval(DynamicObject source, DynamicObject binding, String filename, boolean ownScopeForAssignments) {
final Object result = getContext().eval(ParserContext.EVAL, Layouts.STRING.getByteList(source), binding, ownScopeForAssignments, filename, this);
assert result != null;
return result;
}

protected RootNodeWrapper compileSource(VirtualFrame frame, DynamicObject sourceText) {
assert RubyGuards.isRubyString(sourceText);

@@ -664,7 +673,7 @@ protected RootNodeWrapper compileSource(VirtualFrame frame, DynamicObject source

final TranslatorDriver translator = new TranslatorDriver(getContext());

return new RootNodeWrapper(translator.parse(getContext(), source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.EVAL, parentFrame, true, this, new NodeWrapper() {
return new RootNodeWrapper(translator.parse(getContext(), source, UTF8Encoding.INSTANCE, ParserContext.EVAL, parentFrame, true, this, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return node; // return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), Visibility.PRIVATE, "simple eval", node);
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.NullSourceSection;
import com.oracle.truffle.api.source.SourceSection;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Helpers;
@@ -32,6 +33,7 @@
import org.jruby.truffle.nodes.core.BasicObjectNodes.ReferenceEqualNode;
import org.jruby.truffle.nodes.methods.CallMethodNode;
import org.jruby.truffle.nodes.methods.CallMethodNodeGen;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.nodes.objects.ClassNode;
import org.jruby.truffle.nodes.objects.ClassNodeGen;
import org.jruby.truffle.runtime.RubyArguments;
@@ -111,8 +113,10 @@ private Object[] packArguments(DynamicObject method, InternalMethod internalMeth
return RubyArguments.pack(
internalMethod,
internalMethod.getDeclarationFrame(),
null, Layouts.METHOD.getReceiver(method),
null,
Layouts.METHOD.getReceiver(method),
procOrNullNode.executeProcOrNull(block),
DeclarationContext.METHOD,
arguments);
}

Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.Visibility;
@@ -45,6 +46,7 @@
import org.jruby.truffle.nodes.methods.AddMethodNode;
import org.jruby.truffle.nodes.methods.CanBindMethodToModuleNode;
import org.jruby.truffle.nodes.methods.CanBindMethodToModuleNodeGen;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -60,6 +62,7 @@
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.translator.NodeWrapper;
import org.jruby.truffle.translator.TranslatorDriver;
import org.jruby.truffle.translator.TranslatorDriver.ParserContext;
import org.jruby.util.IdUtil;
import org.jruby.util.StringSupport;

@@ -605,7 +608,7 @@ public abstract static class ClassEvalNode extends CoreMethodArrayArgumentsNode

public ClassEvalNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
yield = new YieldDispatchHeadNode(context);
yield = new YieldDispatchHeadNode(context, DeclarationContext.CLASS_EVAL);
}

protected DynamicObject toStr(VirtualFrame frame, Object object) {
@@ -651,7 +654,7 @@ private Object classEvalSource(DynamicObject module, DynamicObject code, String
CompilerDirectives.transferToInterpreter();
Source source = Source.fromText(code.toString(), file);

return getContext().execute(source, encoding, TranslatorDriver.ParserContext.MODULE, module, callerFrame, this, new NodeWrapper() {
return getContext().execute(source, encoding, ParserContext.MODULE, module, callerFrame, true, DeclarationContext.CLASS_EVAL, this, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), Visibility.PUBLIC, "class_eval", node);
@@ -685,7 +688,7 @@ public abstract static class ClassExecNode extends CoreMethodArrayArgumentsNode

public ClassExecNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
yield = new YieldDispatchHeadNode(context);
yield = new YieldDispatchHeadNode(context, DeclarationContext.CLASS_EVAL);
}

public abstract Object executeClassExec(VirtualFrame frame, DynamicObject self, Object[] args, DynamicObject block);
Original file line number Diff line number Diff line change
@@ -22,12 +22,14 @@
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.NullSourceSection;
import com.oracle.truffle.api.source.SourceSection;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Helpers;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.nodes.objects.AllocateObjectNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -51,6 +53,7 @@ public static Object[] packArguments(DynamicObject proc, Object... args) {
Layouts.PROC.getDeclarationFrame(proc),
null, Layouts.PROC.getSelf(proc),
Layouts.PROC.getBlock(proc),
DeclarationContext.BLOCK,
args);
}

Original file line number Diff line number Diff line change
@@ -13,9 +13,11 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeGen;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
import org.jruby.truffle.runtime.RubyContext;

@@ -26,7 +28,7 @@ public abstract class YieldingCoreMethodNode extends CoreMethodArrayArgumentsNod

public YieldingCoreMethodNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
dispatchNode = new YieldDispatchHeadNode(context);
dispatchNode = new YieldDispatchHeadNode(context, DeclarationContext.BLOCK);
}

private boolean booleanCast(VirtualFrame frame, Object value) {
@@ -47,9 +49,4 @@ public boolean yieldIsTruthy(VirtualFrame frame, DynamicObject block, Object...
return booleanCast(frame, yield(frame, block, arguments));
}

public Object yieldWithModifiedSelf(VirtualFrame frame, DynamicObject block, Object self, Object... arguments) {
assert block == null || RubyGuards.isRubyProc(block);
return dispatchNode.dispatchWithModifiedSelf(frame, block, self, arguments);
}

}
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;

import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.nodes.RubyGuards;
@@ -41,6 +42,7 @@
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.locals.ReadDeclarationVariableNode;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
import org.jruby.truffle.pack.parser.PackParser;
@@ -2251,7 +2253,7 @@ public Object max(VirtualFrame frame, DynamicObject array) {

final InternalMethod method = RubyArguments.getMethod(frame.getArguments());
final VirtualFrame maximumClosureFrame = Truffle.getRuntime().createVirtualFrame(
RubyArguments.pack(method, null, null, array, null, new Object[] {}), maxBlock.getFrameDescriptor());
RubyArguments.pack(method, null, null, array, null, DeclarationContext.BLOCK, new Object[] {}), maxBlock.getFrameDescriptor());
maximumClosureFrame.setObject(maxBlock.getFrameSlot(), maximum);

final DynamicObject block = ProcNodes.createRubyProc(getContext().getCoreLibrary().getProcFactory(), ProcNodes.Type.PROC,
@@ -2356,7 +2358,7 @@ public Object min(VirtualFrame frame, DynamicObject array) {

final InternalMethod method = RubyArguments.getMethod(frame.getArguments());
final VirtualFrame minimumClosureFrame = Truffle.getRuntime().createVirtualFrame(
RubyArguments.pack(method, null, null, array, null, new Object[] {}), minBlock.getFrameDescriptor());
RubyArguments.pack(method, null, null, array, null, DeclarationContext.BLOCK, new Object[] {}), minBlock.getFrameDescriptor());
minimumClosureFrame.setObject(minBlock.getFrameSlot(), minimum);

final DynamicObject block = ProcNodes.createRubyProc(getContext().getCoreLibrary().getProcFactory(), ProcNodes.Type.PROC,
Original file line number Diff line number Diff line change
@@ -14,7 +14,9 @@
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.utilities.BranchProfile;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;
@@ -102,6 +104,7 @@ protected static Object call(DirectCallNode callNode, VirtualFrame frame, Intern
method.getSharedMethodInfo().needsCallerFrame() ? frame.materialize() : null,
receiver,
block,
DeclarationContext.METHOD,
arguments));
}
}
Original file line number Diff line number Diff line change
@@ -15,10 +15,12 @@
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.utilities.BranchProfile;

import org.jruby.truffle.nodes.conversion.ToJavaStringNode;
import org.jruby.truffle.nodes.conversion.ToJavaStringNodeGen;
import org.jruby.truffle.nodes.conversion.ToSymbolNode;
import org.jruby.truffle.nodes.conversion.ToSymbolNodeGen;
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.nodes.objects.MetaClassNode;
import org.jruby.truffle.nodes.objects.MetaClassNodeGen;
import org.jruby.truffle.runtime.RubyArguments;
@@ -119,6 +121,7 @@ private Object call(VirtualFrame frame, InternalMethod method, Object receiverOb
null,
receiverObject,
blockObject,
DeclarationContext.METHOD,
argumentsObjects));
}

Loading