Skip to content
Snippets Groups Projects
Commit bfabc11c authored by Lukas Stadler's avatar Lukas Stadler
Browse files

work on dput and deparse

parent 23b70b05
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,8 @@ public abstract class DPut extends RBuiltinNode {
@Override
protected void createCasts(CastBuilder casts) {
casts.firstIntegerWithError(2, RError.Message.WRONG_LENGTH_ARG, "opts");
casts.arg("file").mustBe(RConnection.class);
casts.arg("opts").asIntegerVector().findFirst();
}
@Specialization
......
......@@ -11,6 +11,7 @@
*/
package com.oracle.truffle.r.nodes.builtin.base;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL;
......@@ -24,7 +25,6 @@ import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
// Part of this transcribed from GnuR src/main/deparse.c
......@@ -33,22 +33,22 @@ public abstract class Deparse extends RBuiltinNode {
@Override
protected void createCasts(CastBuilder casts) {
casts.firstIntegerWithError(1, null, null);
casts.toLogical(2);
casts.toInteger(3);
casts.toInteger(4);
casts.arg("width.cutoff").asIntegerVector().findFirst(0);
casts.arg("backtick").asLogicalVector().findFirst(RRuntime.LOGICAL_TRUE).map(toBoolean());
casts.arg("control").asIntegerVector().findFirst();
casts.arg("nlines").asIntegerVector().findFirst(-1);
}
@Specialization
@TruffleBoundary
protected RStringVector deparse(Object expr, int widthCutoffArg, RAbstractLogicalVector backtick, int control, int nlines) {
protected RStringVector deparse(Object expr, int widthCutoffArg, boolean backtick, int control, int nlines) {
int widthCutoff = widthCutoffArg;
if (widthCutoff == RRuntime.INT_NA || widthCutoff < RDeparse.MIN_Cutoff || widthCutoff > RDeparse.MAX_Cutoff) {
RError.warning(this, RError.Message.DEPARSE_INVALID_CUTOFF);
widthCutoff = RDeparse.DEFAULT_Cutoff;
}
String[] data = RDeparse.deparse(expr, widthCutoff, RRuntime.fromLogical(backtick.getDataAt(0)), control, nlines).split("\n");
String[] data = RDeparse.deparse(expr, widthCutoff, backtick, control, nlines).split("\n");
return RDataFactory.createStringVector(data, RDataFactory.COMPLETE_VECTOR);
}
}
......@@ -226,7 +226,7 @@ public class TestBuiltin_deparse extends TestBase {
@Test
public void testdeparse40() {
assertEval(Ignored.Unknown, "argv <- list(logical(0), logical(0), FALSE, 69, -1L); .Internal(deparse(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]]))");
assertEval(Output.IgnoreWarningContext, "argv <- list(logical(0), logical(0), FALSE, 69, -1L); .Internal(deparse(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]]))");
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment