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

small refactoring in IsTypeFunctions

parent 54e2bdb3
Branches
No related tags found
No related merge requests found
......@@ -43,35 +43,18 @@ public class IsTypeFunctions {
protected abstract static class ErrorAdapter extends RBuiltinNode {
protected final BranchProfile errorProfile = BranchProfile.create();
protected RError missingError() throws RError {
errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.ARGUMENT_MISSING, "x");
}
}
protected abstract static class IsFalseAdapter extends ErrorAdapter {
@Override
public RNode[] getParameterValues() {
return new RNode[]{ConstantNode.create(RMissing.instance)};
}
@Specialization
protected byte isType(RMissing value) throws RError {
controlVisibility();
throw missingError();
}
@Fallback
protected byte isType(Object value) {
return RRuntime.LOGICAL_FALSE;
protected RError missingError() throws RError {
errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.ARGUMENT_MISSING, "x");
}
}
protected abstract static class IsTrueAdapter extends ErrorAdapter {
@Override
public RNode[] getParameterValues() {
return new RNode[]{ConstantNode.create(RMissing.instance)};
}
protected abstract static class IsFalseAdapter extends ErrorAdapter {
@Specialization
protected byte isType(RMissing value) throws RError {
......@@ -81,7 +64,8 @@ public class IsTypeFunctions {
@Fallback
protected byte isType(Object value) {
return RRuntime.LOGICAL_TRUE;
controlVisibility();
return RRuntime.LOGICAL_FALSE;
}
}
......@@ -97,7 +81,13 @@ public class IsTypeFunctions {
}
@RBuiltin(name = "is.recursive", kind = PRIMITIVE, parameterNames = {"x"})
public abstract static class IsRecursive extends IsTrueAdapter {
public abstract static class IsRecursive extends ErrorAdapter {
@Specialization
protected byte isRecursive(RMissing value) throws RError {
controlVisibility();
throw missingError();
}
@Specialization
protected byte isRecursive(RNull arg) {
......@@ -112,13 +102,13 @@ public class IsTypeFunctions {
}
@Specialization
protected byte isAtomic(RList arg) {
protected byte isRecursive(RList arg) {
controlVisibility();
return RRuntime.LOGICAL_TRUE;
}
@Specialization
protected byte isAtomic(RFactor arg) {
protected byte isRecursive(RFactor arg) {
controlVisibility();
return RRuntime.LOGICAL_FALSE;
}
......@@ -127,6 +117,11 @@ public class IsTypeFunctions {
return arg.getElementClass() == Object.class;
}
@Fallback
protected byte isRecursiveFallback(Object value) {
controlVisibility();
return RRuntime.LOGICAL_TRUE;
}
}
@RBuiltin(name = "is.atomic", kind = PRIMITIVE, parameterNames = {"x"})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment