Skip to content
Permalink
Browse files
[Truffle] Set top-level visibility only in RubyContext.load and Truff…
…leBridgeImpl.execute.

* Since the meaning of ParserContext.TOP_LEVEL is unclear.
* De-duplicate one call to RubyContext.execute.
  • Loading branch information
eregon committed Dec 30, 2014
1 parent ba596b0 commit da135d79ee4793eb9f46036ff116c8bb793f2642
@@ -14,13 +14,16 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.TruffleBridge;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.TopLevelRaiseHandler;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.nodes.methods.SetFrameVisibilityNode;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
@@ -170,16 +173,18 @@ public Object execute(final TranslatorDriver.ParserContext parserContext, final
source = Source.fromBytes(bytes, inputFile, new BytesDecoder.UTF8BytesDecoder());
}

return truffleContext.execute(truffleContext, source, UTF8Encoding.INSTANCE, parserContext, self, parentFrame, null, new NodeWrapper() {
truffleContext.load(source, null, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
RubyContext context = node.getContext();
SourceSection sourceSection = node.getSourceSection();
return SequenceNode.sequence(context, sourceSection,
new SetTopLevelBindingNode(context, sourceSection),
new TopLevelRaiseHandler(context, sourceSection, node));
new TopLevelRaiseHandler(context, sourceSection,
SetFrameVisibilityNode.PRIVATE_VISIBILITY_WRAPPER.wrap(node)));
}
});
return truffleContext.getCoreLibrary().getNilObject();
}

@Override
@@ -12,13 +12,22 @@
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.translator.NodeWrapper;

public class SetFrameVisibilityNode extends RubyNode {

public static final NodeWrapper PRIVATE_VISIBILITY_WRAPPER = new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetFrameVisibilityNode(node.getContext(), node.getSourceSection(), node, Visibility.PRIVATE);
}
};

@Child protected RubyNode body;

final Visibility visibility;
@@ -18,17 +18,20 @@
import java.util.concurrent.atomic.*;

import com.oracle.truffle.api.object.Shape;

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.*;

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.frame.*;

import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.TruffleHooks;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.methods.SetFrameVisibilityNode;
import org.jruby.truffle.runtime.control.*;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.core.RubyArray;
@@ -139,10 +142,6 @@ public static String checkClassVariableName(RubyContext context, String name, Ru
return name;
}

public void load(Source source, RubyNode currentNode) {
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
}

public void loadFile(String fileName, RubyNode currentNode) {
if (new File(fileName).isAbsolute()) {
loadFileAbsolute(fileName, currentNode);
@@ -161,9 +160,17 @@ private void loadFileAbsolute(String fileName, RubyNode currentNode) {
}

// Assume UTF-8 for the moment

final Source source = Source.fromBytes(bytes, fileName, new BytesDecoder.UTF8BytesDecoder());
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);

load(source, currentNode, SetFrameVisibilityNode.PRIVATE_VISIBILITY_WRAPPER);
}

public void load(Source source, RubyNode currentNode) {
load(source, currentNode, NodeWrapper.IDENTITY);
}

public void load(Source source, RubyNode currentNode, NodeWrapper nodeWrapper) {
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode, nodeWrapper);
}

public RubySymbol.SymbolTable getSymbolTable() {
@@ -161,11 +161,6 @@ public RubyRootNode parse(RubyNode currentNode, RubyContext context, Source sour
truffleNode = rootNode.getBodyNode().accept(translator);
}

// Set default top-level visibility
if (parserContext == ParserContext.TOP_LEVEL) {
truffleNode = new SetFrameVisibilityNode(context, truffleNode.getSourceSection(), truffleNode, Visibility.PRIVATE);
}

// Load flip-flop states

if (environment.getFlipFlopStates().size() > 0) {

0 comments on commit da135d7

Please sign in to comment.