Skip to content
Snippets Groups Projects
Commit 49468004 authored by Florian Angerer's avatar Florian Angerer
Browse files

added builtin function "is.single"

parent 00b47ca4
No related branches found
No related tags found
No related merge requests found
......@@ -683,6 +683,7 @@ public class BasePackage extends RBuiltinPackage {
add(WhichFunctions.WhichMax.class, WhichFunctions.WhichMax::create);
add(WhichFunctions.WhichMin.class, WhichFunctions.WhichMin::create);
add(Xtfrm.class, XtfrmNodeGen::create);
add(IsSingle.class, IsSingleNodeGen::create);
// infix functions
add(Subscript.class, SubscriptNodeGen::create, Subscript::special);
......
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.nodes.builtin.base;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.r.nodes.builtin.CastBuilder;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
@RBuiltin(name = "is.single", kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE)
public abstract class IsSingle extends RBuiltinNode {
@Override
protected void createCasts(CastBuilder casts) {
casts.arg("x").mustNotBeMissing(RError.Message.ARGUMENTS_PASSED, 0, "'is.single'", 1);
}
@Specialization
protected Object isSingle(@SuppressWarnings("unused") Object x) {
throw RError.error(this, RError.Message.UNIMPLEMENTED_TYPE_IN_R, "single");
}
}
......@@ -782,7 +782,8 @@ public final class RError extends RuntimeException {
MACRO_CAN_BE_APPLIED_TO("%s can only be applied to a '%s', not a '%s'"),
LOSS_OF_ACCURACY_MOD("probable complete loss of accuracy in modulus"),
LENGTH_MISAPPLIED("LENGTH or similar applied to %s object"),
TOO_MANY_ARGS("too many arguments");
TOO_MANY_ARGS("too many arguments"),
UNIMPLEMENTED_TYPE_IN_R("type \"%s\" unimplemented in R");
public final String message;
final boolean hasArgs;
......
......@@ -24202,6 +24202,26 @@ Levels: a.b.c a.b.b.c a.c
#argv <- list(structure(3.14159265358979, class = structure('3.14159265358979', class = 'testit')));isS4(argv[[1]]);
[1] FALSE
 
##com.oracle.truffle.r.test.builtins.TestBuiltin_isSingle.testisSingle0#
#is.single
function (x) .Primitive("is.single")
##com.oracle.truffle.r.test.builtins.TestBuiltin_isSingle.testisSingle1#
#is.single()
Error in is.single() : 0 arguments passed to 'is.single' which requires 1
##com.oracle.truffle.r.test.builtins.TestBuiltin_isSingle.testisSingle2#
#is.single(0)
Error in is.single(0) : type "single" unimplemented in R
##com.oracle.truffle.r.test.builtins.TestBuiltin_isSingle.testisSingle3#
#is.single(NULL)
Error in is.single(NULL) : type "single" unimplemented in R
##com.oracle.truffle.r.test.builtins.TestBuiltin_isSingle.testisSingle4#
#is.single(+)
Error: unexpected ')' in "is.single(+)"
##com.oracle.truffle.r.test.builtins.TestBuiltin_isTRUE.testIsTRUE#
#{ file.path("a", "b", c("d","e","f")) }
[1] "a/b/d" "a/b/e" "a/b/f"
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.test.builtins;
import org.junit.Test;
import com.oracle.truffle.r.test.TestBase;
public class TestBuiltin_isSingle extends TestBase {
@Test
public void testisSingle0() {
assertEval("is.single");
}
@Test
public void testisSingle1() {
assertEval("is.single()");
}
@Test
public void testisSingle2() {
assertEval("is.single(0)");
}
@Test
public void testisSingle3() {
assertEval("is.single(NULL)");
}
@Test
public void testisSingle4() {
assertEval("is.single(+)");
}
}
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