Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Adapt to new parsing API.
Browse files Browse the repository at this point in the history
chrisseaton committed May 24, 2016
1 parent 5c10f30 commit 36e729f
Showing 2 changed files with 16 additions and 25 deletions.
14 changes: 6 additions & 8 deletions truffle/src/main/java/org/jruby/truffle/RubyLanguage.java
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.instrumentation.ProvidedTags;
import com.oracle.truffle.api.instrumentation.StandardTags;
import com.oracle.truffle.api.nodes.Node;
@@ -79,8 +78,12 @@ protected void disposeContext(RubyContext context) {
}

@Override
protected CallTarget parse(Source source, Node node, String... argumentNames) throws IOException {
return Truffle.getRuntime().createCallTarget(new LazyRubyRootNode(null, null, source, argumentNames));
protected CallTarget parse(ParsingRequest request) throws IOException {
return Truffle.getRuntime().createCallTarget(
new LazyRubyRootNode(
request.createContextReference(this),
request.getSource(),
request.getArgumentNames()));
}

@Override
@@ -98,11 +101,6 @@ protected boolean isObjectOfLanguage(Object object) {
throw new UnsupportedOperationException();
}

@Override
protected Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws IOException {
return null;
}

@Override
protected String toString(RubyContext context, Object value) {
if (value == null) {
Original file line number Diff line number Diff line change
@@ -32,46 +32,39 @@
import org.jruby.truffle.language.parser.ParserContext;
import org.jruby.truffle.language.parser.jruby.TranslatorDriver;

import java.lang.ref.Reference;
import java.util.List;

public class LazyRubyRootNode extends RootNode implements InternalRootNode {

private final Reference<RubyContext> contextReference;
private final Source source;
private final String[] argumentNames;
private final List<String> argumentNames;

@CompilationFinal private RubyContext cachedContext;
@CompilationFinal private DynamicObject mainObject;
@CompilationFinal private InternalMethod method;

@Child private Node findContextNode;
@Child private DirectCallNode callNode;

public LazyRubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescriptor, Source source,
String[] argumentNames) {
super(RubyLanguage.class, sourceSection, frameDescriptor);
public LazyRubyRootNode(Reference<RubyContext> contextReference, Source source, List<String> argumentNames) {
super(RubyLanguage.class, null, null);
this.contextReference = contextReference;
this.source = source;
this.argumentNames = argumentNames;
}

@Override
public Object execute(VirtualFrame frame) {
if (findContextNode == null) {
CompilerDirectives.transferToInterpreter();
findContextNode = insert(RubyLanguage.INSTANCE.unprotectedCreateFindContextNode());
}

final RubyContext context = RubyLanguage.INSTANCE.unprotectedFindContext(findContextNode);

if (cachedContext == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
cachedContext = context;
}
final RubyContext context = contextReference.get();

if (callNode == null || context != cachedContext) {
CompilerDirectives.transferToInterpreterAndInvalidate();

final TranslatorDriver translator = new TranslatorDriver(context);

final RubyRootNode rootNode = translator.parse(context, source, UTF8Encoding.INSTANCE,
ParserContext.TOP_LEVEL, argumentNames, null, null, true, null);
ParserContext.TOP_LEVEL, argumentNames.toArray(new String[argumentNames.size()]), null, null, true, null);

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

0 comments on commit 36e729f

Please sign in to comment.