Skip to content

Commit

Permalink
Showing 10 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ protected Object ruby(VirtualFrame frame, String expression, Object... arguments

protected Object rubyWithSelf(Object self, String expression, Object... arguments) {
final MaterializedFrame evalFrame = setupFrame(self, arguments);
final DynamicObject binding = Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), self, evalFrame);
final DynamicObject binding = Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), evalFrame);
return getContext().eval(expression, binding, true, "inline-ruby", this);
}

Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@
import org.jruby.RubyString;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.ProcNodes;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.StringSupport;
@@ -84,7 +83,7 @@ public void trace(VirtualFrame frame) {
file,
line,
context.getCoreLibrary().getNilObject(),
Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), RubyArguments.getSelf(frame.getArguments()), frame.materialize()),
Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), frame.materialize()),
context.getCoreLibrary().getNilObject()
};

Original file line number Diff line number Diff line change
@@ -59,7 +59,6 @@ public Object initializeCopy(DynamicObject self, DynamicObject from) {
final Object[] copiedArguments = RubyArguments.pack(method, Layouts.BINDING.getFrame(from), boundSelf, boundBlock, userArguments);
final MaterializedFrame copiedFrame = Truffle.getRuntime().createMaterializedFrame(copiedArguments);

Layouts.BINDING.setSelf(self, Layouts.BINDING.getSelf(from));
Layouts.BINDING.setFrame(self, copiedFrame);

return self;
Original file line number Diff line number Diff line change
@@ -294,7 +294,7 @@ public DynamicObject binding() {
final MaterializedFrame callerFrame = RubyCallStack.getCallerFrame(getContext())
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, false).materialize();

return Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), RubyArguments.getSelf(callerFrame.getArguments()), callerFrame);
return Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), callerFrame);
}
}

@@ -547,8 +547,8 @@ public Object evalNoBindingCached(
) {
final DynamicObject callerBinding = getCallerBinding(frame);

final Object callerSelf = Layouts.BINDING.getSelf(callerBinding);
final MaterializedFrame parentFrame = Layouts.BINDING.getFrame(callerBinding);
final Object callerSelf = RubyArguments.getSelf(parentFrame.getArguments());

final InternalMethod method = new InternalMethod(
cachedRootNode.getRootNode().getSharedMethodInfo(),
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ public BindingNode(RubyContext context, SourceSection sourceSection) {
public Object binding(DynamicObject proc) {
final MaterializedFrame frame = Layouts.PROC.getDeclarationFrame(proc);

return Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), RubyArguments.getSelf(frame.getArguments()), frame);
return Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), frame);
}

}
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@
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.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

@@ -25,7 +25,7 @@ public SetTopLevelBindingNode(RubyContext context, SourceSection sourceSection)

@Override
public Object execute(VirtualFrame frame) {
final DynamicObject binding = Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), RubyArguments.getSelf(frame.getArguments()), frame.materialize());
final DynamicObject binding = Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), frame.materialize());
Layouts.MODULE.getFields(getContext().getCoreLibrary().getObjectClass()).setConstant(this, "TOPLEVEL_BINDING", binding);
return nil();
}
Original file line number Diff line number Diff line change
@@ -22,14 +22,15 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import jnr.posix.SpawnFileAction;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.RubyGC;
import org.jruby.RubyString;
import org.jruby.ext.rbconfig.RbConfigLibrary;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.BacktraceFormatter;
@@ -89,7 +90,7 @@ public MaterializedFrame visitFrame(FrameInstance frameInstance) {

});

return Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), RubyArguments.getSelf(frame.getArguments()), frame);
return Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), frame);
}

}
Original file line number Diff line number Diff line change
@@ -358,7 +358,8 @@ public Object eval(String code, DynamicObject binding, boolean ownScopeForAssign
public Object eval(ByteList code, DynamicObject binding, boolean ownScopeForAssignments, String filename, Node currentNode) {
assert RubyGuards.isRubyBinding(binding);
final Source source = Source.fromText(code, filename);
return execute(source, code.getEncoding(), TranslatorDriver.ParserContext.EVAL, Layouts.BINDING.getSelf(binding), Layouts.BINDING.getFrame(binding), ownScopeForAssignments, currentNode, NodeWrapper.IDENTITY);
final MaterializedFrame frame = Layouts.BINDING.getFrame(binding);
return execute(source, code.getEncoding(), TranslatorDriver.ParserContext.EVAL, RubyArguments.getSelf(frame.getArguments()), frame, ownScopeForAssignments, currentNode, NodeWrapper.IDENTITY);
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import org.jruby.truffle.om.dsl.api.Layout;
import org.jruby.truffle.om.dsl.api.Nullable;

@Layout
public interface BindingLayout extends BasicObjectLayout {
@@ -22,14 +21,10 @@ DynamicObjectFactory createBindingShape(DynamicObject logicalClass,
DynamicObject metaClass);

DynamicObject createBinding(DynamicObjectFactory factory,
@Nullable Object self,
@Nullable MaterializedFrame frame);
MaterializedFrame frame);

boolean isBinding(DynamicObject object);

Object getSelf(DynamicObject object);
void setSelf(DynamicObject object, Object self);

MaterializedFrame getFrame(DynamicObject object);
void setFrame(DynamicObject object, MaterializedFrame frame);

Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@
import com.oracle.truffle.api.source.LineLocation;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.tools.LineToProbesMap;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.core.ProcNodes;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

@@ -53,7 +53,7 @@ public synchronized void attach(String file, int line, final DynamicObject block

@Override
public void enter(Probe probe, Node node, VirtualFrame frame) {
final DynamicObject binding = Layouts.BINDING.createBinding(context.getCoreLibrary().getBindingFactory(), RubyArguments.getSelf(frame.getArguments()), frame.materialize());
final DynamicObject binding = Layouts.BINDING.createBinding(context.getCoreLibrary().getBindingFactory(), frame.materialize());
ProcNodes.rootCall(block, binding);
}

2 comments on commit eb907ac

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we no longer use them, but I thought there were cases where we needed to provide a different self. We have something similar for the yield helpers.

@eregon
Copy link
Member Author

@eregon eregon commented on eb907ac Sep 16, 2015

Choose a reason for hiding this comment

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

Yeah, calling a block might need to change self (instance_eval) but that's a non-issue as we just create a new frame with the right self. Binding captures the environment at a given point, and its self can only ever be the one that was captured at that point.

Sorry, something went wrong.

Please sign in to comment.