Skip to content

Commit

Permalink
Showing 7 changed files with 47 additions and 14 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/language/def_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -30,7 +30,8 @@ public class DeclarationContext {
private enum DefaultDefinee {
LEXICAL_SCOPE,
SINGLETON_CLASS,
SELF
SELF,
CAPTURED

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Jan 7, 2016

Author Contributor

Left in by mistake - removed

}

public final Visibility visibility;
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import org.jruby.truffle.nodes.objects.SingletonClassNodeGen;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.methods.InternalMethod;

public class GetDefaultDefineeNode extends RubyNode {

@@ -31,6 +32,13 @@ public GetDefaultDefineeNode(RubyContext context, SourceSection sourceSection) {
@Override
public DynamicObject execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreter();

final DynamicObject capturedDefaultDefinee = RubyArguments.getMethod(frame.getArguments()).getCapturedDefaultDefinee();

if (capturedDefaultDefinee != null) {
return capturedDefaultDefinee;
}

This comment has been minimized.

Copy link
@eregon

eregon Jan 8, 2016

Member

Looks good! I didn't think of that approach, I was thinking to have an additional DefaultDefinee, but it seems more effort.


return RubyArguments.getDeclarationContext(frame.getArguments()).getModuleToDefineMethods(frame, getContext(), singletonClassNode);
}
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.nodes.methods;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
@@ -31,14 +32,18 @@ public class MethodDefinitionNode extends RubyNode {
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) {
CallTarget callTarget, boolean captureBlock, boolean captureDefaultDefinee) {
super(context, sourceSection);
this.name = name;
this.sharedMethodInfo = sharedMethodInfo;
this.callTarget = callTarget;
this.captureBlock = captureBlock;
this.captureDefaultDefinee = captureDefaultDefinee;
}

public InternalMethod executeMethod(VirtualFrame frame) {
@@ -53,7 +58,20 @@ public InternalMethod executeMethod(VirtualFrame frame) {
capturedBlock = null;
}

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

if (captureDefaultDefinee && 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);

This comment has been minimized.

Copy link
@eregon

eregon Jan 8, 2016

Member

I think it's time to have a ModuleBodyDefinitionNode or so :)

}

@Override
Original file line number Diff line number Diff line change
@@ -39,23 +39,24 @@ public class InternalMethod implements ObjectGraphNode {

private final CallTarget callTarget;
private final DynamicObject capturedBlock;
private final DynamicObject capturedDefaultDefinee;

public static InternalMethod fromProc(SharedMethodInfo sharedMethodInfo, String name, DynamicObject declaringModule,
Visibility visibility, DynamicObject proc, CallTarget callTarget) {
return new InternalMethod(sharedMethodInfo, name, declaringModule, visibility, false, proc, callTarget, null);
return new InternalMethod(sharedMethodInfo, name, declaringModule, visibility, false, proc, callTarget, null, null);
}

public InternalMethod(SharedMethodInfo sharedMethodInfo, String name, DynamicObject declaringModule,
Visibility visibility, CallTarget callTarget) {
this(sharedMethodInfo, name, declaringModule, visibility, false, null, callTarget, null);
this(sharedMethodInfo, name, declaringModule, visibility, false, null, callTarget, null, null);
}
public InternalMethod(SharedMethodInfo sharedMethodInfo, String name, DynamicObject declaringModule,
Visibility visibility, boolean undefined, DynamicObject proc, CallTarget callTarget) {
this(sharedMethodInfo, name, declaringModule, visibility, undefined, proc, callTarget, null);
this(sharedMethodInfo, name, declaringModule, visibility, undefined, proc, callTarget, null, null);
}

public InternalMethod(SharedMethodInfo sharedMethodInfo, String name, DynamicObject declaringModule,
Visibility visibility, boolean undefined, DynamicObject proc, CallTarget callTarget, DynamicObject capturedBlock) {
Visibility visibility, boolean undefined, DynamicObject proc, CallTarget callTarget, DynamicObject capturedBlock, DynamicObject capturedDefaultDefinee) {
assert RubyGuards.isRubyModule(declaringModule);
this.sharedMethodInfo = sharedMethodInfo;
this.declaringModule = declaringModule;
@@ -65,6 +66,7 @@ public InternalMethod(SharedMethodInfo sharedMethodInfo, String name, DynamicObj
this.proc = proc;
this.callTarget = callTarget;
this.capturedBlock = capturedBlock;
this.capturedDefaultDefinee = capturedDefaultDefinee;
}

public SharedMethodInfo getSharedMethodInfo() {
@@ -97,28 +99,28 @@ public InternalMethod withDeclaringModule(DynamicObject newDeclaringModule) {
if (newDeclaringModule == declaringModule) {
return this;
} else {
return new InternalMethod(sharedMethodInfo, name, newDeclaringModule, visibility, undefined, proc, callTarget, capturedBlock);
return new InternalMethod(sharedMethodInfo, name, newDeclaringModule, visibility, undefined, proc, callTarget, capturedBlock, capturedDefaultDefinee);
}
}

public InternalMethod withName(String newName) {
if (newName.equals(name)) {
return this;
} else {
return new InternalMethod(sharedMethodInfo, newName, declaringModule, visibility, undefined, proc, callTarget, capturedBlock);
return new InternalMethod(sharedMethodInfo, newName, declaringModule, visibility, undefined, proc, callTarget, capturedBlock, capturedDefaultDefinee);
}
}

public InternalMethod withVisibility(Visibility newVisibility) {
if (newVisibility == visibility) {
return this;
} else {
return new InternalMethod(sharedMethodInfo, name, declaringModule, newVisibility, undefined, proc, callTarget, capturedBlock);
return new InternalMethod(sharedMethodInfo, name, declaringModule, newVisibility, undefined, proc, callTarget, capturedBlock, capturedDefaultDefinee);
}
}

public InternalMethod undefined() {
return new InternalMethod(sharedMethodInfo, name, declaringModule, visibility, true, proc, callTarget, capturedBlock);
return new InternalMethod(sharedMethodInfo, name, declaringModule, visibility, true, proc, callTarget, capturedBlock, capturedDefaultDefinee);
}

public boolean isVisibleTo(Node currentNode, DynamicObject callerClass) {
@@ -170,4 +172,8 @@ public Set<DynamicObject> getAdjacentObjects() {
public DynamicObject getCapturedBlock() {
return capturedBlock;
}

public DynamicObject getCapturedDefaultDefinee() {
return capturedDefaultDefinee;
}
}
Original file line number Diff line number Diff line change
@@ -851,7 +851,8 @@ private MethodDefinitionNode compileClassNode(SourceSection sourceSection, Strin
environment.getSharedMethodInfo().getName(),
environment.getSharedMethodInfo(),
Truffle.getRuntime().createCallTarget(rootNode),
sclass);
sclass,
false);

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);
return new MethodDefinitionNode(context, sourceSection, methodName, environment.getSharedMethodInfo(), callTarget, false, true);
}

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

1 comment on commit 07e62b2

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, something went wrong.

Please sign in to comment.