Skip to content
Snippets Groups Projects
Commit b7da7c63 authored by Mick Jordan's avatar Mick Jordan
Browse files

deparse fixes for specializd trees (e.g. .Internal)

parent f0158347
Branches
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.r.nodes.access.*;
import com.oracle.truffle.r.nodes.access.ReadVariableNode.BuiltinFunctionVariableNode;
import com.oracle.truffle.r.nodes.builtin.*;
import com.oracle.truffle.r.nodes.function.*;
import com.oracle.truffle.r.nodes.instrument.RInstrumentableNode;
import com.oracle.truffle.r.nodes.function.PromiseNode.VarArgPromiseNode;
......@@ -207,6 +208,9 @@ public class RASTUtils {
gname = "`" + gname + "`";
}
return RDataFactory.createSymbol(gname);
} else if (child instanceof RBuiltinNode) {
RBuiltinNode builtinNode = (RBuiltinNode) child;
return RDataFactory.createSymbol((builtinNode.getBuiltin().getRBuiltin().name()));
} else if (child instanceof RCallNode) {
return findFunctionName(child, quote);
} else {
......
......@@ -32,6 +32,7 @@ import com.oracle.truffle.r.nodes.access.*;
import com.oracle.truffle.r.nodes.function.*;
import com.oracle.truffle.r.nodes.function.RCallNode.LeafCallNode;
import com.oracle.truffle.r.runtime.*;
import com.oracle.truffle.r.runtime.RDeparse.State;
import com.oracle.truffle.r.runtime.data.*;
@NodeFields(value = {@NodeField(name = "builtin", type = RBuiltinFactory.class), @NodeField(name = "suppliedArgsNames", type = String[].class)})
......@@ -186,6 +187,28 @@ public abstract class RBuiltinNode extends LeafCallNode implements VisibilityCon
") must be consistent!");
}
/*
* The following two overrides are only needed when a {@code .Internal} call has been rewritten
* to replace itself with the {@link RBuiltinNode}. It may be better to create an AST structure
* that is more similar to the normal case.
*/
@Override
public RNode getFunctionNode() {
return this;
}
@Override
public void deparse(State state) {
RBuiltin rb = getBuiltin().getRBuiltin();
assert rb.kind() == RBuiltinKind.INTERNAL;
state.append(".Internal(");
state.append(rb.name());
// arguments; there is no CallArgumentsNode, so we create one to reuse the deparse code
CallArgumentsNode.createUnnamed(false, false, getArguments()).deparse(state);
state.append(')');
}
/**
* A wrapper builtin is a {@link RCustomBuiltinNode} that is able to create any arbitrary node
* as builtin (e.g., 'max', 'sum', etc.). It can be used as normal builtin. Implement
......
......@@ -33,6 +33,7 @@ import com.oracle.truffle.r.nodes.*;
import com.oracle.truffle.r.nodes.access.*;
import com.oracle.truffle.r.nodes.function.PromiseHelperNode.PromiseCheckHelperNode;
import com.oracle.truffle.r.runtime.*;
import com.oracle.truffle.r.runtime.RDeparse.State;
import com.oracle.truffle.r.runtime.data.*;
import com.oracle.truffle.r.runtime.data.RPromise.Closure;
import com.oracle.truffle.r.runtime.data.RPromise.EvalPolicy;
......@@ -164,6 +165,11 @@ public class PromiseNode extends RNode {
return promiseCheckHelper.checkEvaluate(frame, obj);
}
}
@Override
public void deparse(State state) {
expr.deparse(state);
}
}
/**
......@@ -187,6 +193,11 @@ public class PromiseNode extends RNode {
// the assumption that the evaluation of default values should have no side effects
return defaultExpr.execute(frame);
}
@Override
public void deparse(State state) {
defaultExpr.deparse(state);
}
}
/**
......
......@@ -283,7 +283,7 @@ public abstract class RCallNode extends RNode {
@TruffleBoundary
protected RCallNode getParentCallNode() {
RNode parent = (RNode) getParent();
RNode parent = (RNode) unwrapParent();
if (!(parent instanceof RCallNode)) {
throw RInternalError.shouldNotReachHere();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment