Skip to content

Commit

Permalink
[Truffle] Set top-level visibility only in RubyContext.load and Truff…
Browse files Browse the repository at this point in the history
…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 da135d7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand Down
21 changes: 14 additions & 7 deletions core/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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() {
Expand Down
Expand Up @@ -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) {
Expand Down

0 comments on commit da135d7

Please sign in to comment.