diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java index 6b744995ded6878082f2db0655c7bbc01ef53447..751f3de92a21b8538597d41e82489963b8644a92 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java @@ -35,7 +35,6 @@ import com.oracle.truffle.r.engine.TruffleRLanguage; import com.oracle.truffle.r.engine.interop.RAbstractVectorAccessFactoryFactory.VectorReadNodeGen; import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode; -import com.oracle.truffle.r.nodes.builtin.base.InfixFunctions.AccessArraySubscriptBuiltin; import com.oracle.truffle.r.nodes.control.RLengthNode; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.data.RLogical; @@ -60,7 +59,6 @@ public final class RAbstractVectorAccessFactory implements Factory18 { abstract static class VectorReadNode extends RootNode { @CompilationFinal private boolean lengthAccess; - @Child private AccessArraySubscriptBuiltin builtin; @Child private ExtractVectorNode extract = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true); @Child private RLengthNode lengthNode = RLengthNode.create(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java index 32661bc40b93333b29364439a5549844ac0b7d24..46def37dbc60490a3042b9f83b9a077f1b35d68d 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java @@ -33,7 +33,6 @@ import com.oracle.truffle.r.nodes.binary.BinaryBooleanScalarNodeGen; import com.oracle.truffle.r.nodes.binary.ColonNode; import com.oracle.truffle.r.nodes.binary.ColonNodeGen; import com.oracle.truffle.r.nodes.builtin.RBuiltinPackage; -import com.oracle.truffle.r.nodes.builtin.base.InfixFunctions.AccessArraySubscriptSpecialBuiltin; import com.oracle.truffle.r.nodes.builtin.base.fastpaths.AssignFastPathNodeGen; import com.oracle.truffle.r.nodes.builtin.base.fastpaths.ExistsFastPathNodeGen; import com.oracle.truffle.r.nodes.builtin.base.fastpaths.GetFastPathNodeGen; @@ -47,6 +46,44 @@ import com.oracle.truffle.r.nodes.builtin.base.foreign.DotC; import com.oracle.truffle.r.nodes.builtin.base.foreign.DotCNodeGen; import com.oracle.truffle.r.nodes.builtin.base.foreign.ForeignFunctions; import com.oracle.truffle.r.nodes.builtin.base.foreign.ForeignFunctionsFactory; +import com.oracle.truffle.r.nodes.builtin.base.infix.AccessField; +import com.oracle.truffle.r.nodes.builtin.base.infix.AccessFieldNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.AssignBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.AssignBuiltinEq; +import com.oracle.truffle.r.nodes.builtin.base.infix.AssignBuiltinEqNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.AssignBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.AssignOuterBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.AssignOuterBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.BraceBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.BraceBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.BreakBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.BreakBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.ForBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.ForBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.FunctionBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.FunctionBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.IfBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.IfBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.NextBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.NextBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.ParenBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.ParenBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.RepeatBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.RepeatBuiltinNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.Subscript; +import com.oracle.truffle.r.nodes.builtin.base.infix.SubscriptNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.Subset; +import com.oracle.truffle.r.nodes.builtin.base.infix.SubsetNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.Tilde; +import com.oracle.truffle.r.nodes.builtin.base.infix.TildeNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.UpdateField; +import com.oracle.truffle.r.nodes.builtin.base.infix.UpdateFieldNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.UpdateSubscript; +import com.oracle.truffle.r.nodes.builtin.base.infix.UpdateSubscriptNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.UpdateSubset; +import com.oracle.truffle.r.nodes.builtin.base.infix.UpdateSubsetNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.WhileBuiltin; +import com.oracle.truffle.r.nodes.builtin.base.infix.WhileBuiltinNodeGen; import com.oracle.truffle.r.nodes.builtin.base.system.SystemFunction; import com.oracle.truffle.r.nodes.builtin.base.system.SystemFunctionNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastRContext; @@ -387,27 +424,6 @@ public class BasePackage extends RBuiltinPackage { add(IConv.class, IConvNodeGen::create); add(Identical.class, Identical::create); add(NumericalFunctions.Im.class, NumericalFunctionsFactory.ImNodeGen::create); - add(InfixFunctions.AccessArraySubscriptBuiltin.class, InfixFunctionsFactory.AccessArraySubscriptBuiltinNodeGen::create, AccessArraySubscriptSpecialBuiltin::create); - add(InfixFunctions.AccessArraySubscriptDefaultBuiltin.class, InfixFunctionsFactory.AccessArraySubscriptBuiltinNodeGen::create); - add(InfixFunctions.AccessArraySubsetBuiltin.class, InfixFunctionsFactory.AccessArraySubsetBuiltinNodeGen::create); - add(InfixFunctions.AccessArraySubsetDefaultBuiltin.class, InfixFunctionsFactory.AccessArraySubsetBuiltinNodeGen::create); - add(InfixFunctions.AccessFieldBuiltin.class, InfixFunctionsFactory.AccessFieldBuiltinNodeGen::create); - add(InfixFunctions.AssignBuiltin.class, InfixFunctionsFactory.AssignBuiltinNodeGen::create); - add(InfixFunctions.AssignBuiltinEq.class, InfixFunctionsFactory.AssignBuiltinEqNodeGen::create); - add(InfixFunctions.AssignOuterBuiltin.class, InfixFunctionsFactory.AssignOuterBuiltinNodeGen::create); - add(InfixFunctions.BraceBuiltin.class, InfixFunctionsFactory.BraceBuiltinNodeGen::create); - add(InfixFunctions.BreakBuiltin.class, InfixFunctionsFactory.BreakBuiltinNodeGen::create); - add(InfixFunctions.ForBuiltin.class, InfixFunctionsFactory.ForBuiltinNodeGen::create); - add(InfixFunctions.FunctionBuiltin.class, InfixFunctionsFactory.FunctionBuiltinNodeGen::create); - add(InfixFunctions.IfBuiltin.class, InfixFunctionsFactory.IfBuiltinNodeGen::create); - add(InfixFunctions.NextBuiltin.class, InfixFunctionsFactory.NextBuiltinNodeGen::create); - add(InfixFunctions.ParenBuiltin.class, InfixFunctionsFactory.ParenBuiltinNodeGen::create); - add(InfixFunctions.RepeatBuiltin.class, InfixFunctionsFactory.RepeatBuiltinNodeGen::create); - add(InfixFunctions.TildeBuiltin.class, InfixFunctionsFactory.TildeBuiltinNodeGen::create); - add(InfixFunctions.UpdateArrayNodeSubscriptBuiltin.class, InfixFunctionsFactory.UpdateArrayNodeSubscriptBuiltinNodeGen::create); - add(InfixFunctions.UpdateArraySubsetBuiltin.class, InfixFunctionsFactory.UpdateArraySubsetBuiltinNodeGen::create); - add(InfixFunctions.UpdateFieldBuiltin.class, InfixFunctionsFactory.UpdateFieldBuiltinNodeGen::create); - add(InfixFunctions.WhileBuiltin.class, InfixFunctionsFactory.WhileBuiltinNodeGen::create); add(InheritsBuiltin.class, InheritsBuiltinNodeGen::create); add(Interactive.class, InteractiveNodeGen::create); add(Internal.class, InternalNodeGen::create); @@ -641,6 +657,29 @@ public class BasePackage extends RBuiltinPackage { add(WhichFunctions.WhichMax.class, WhichFunctions.WhichMax::create); add(WhichFunctions.WhichMin.class, WhichFunctions.WhichMin::create); add(Xtfrm.class, XtfrmNodeGen::create); + + // infix functions + add(Subscript.class, SubscriptNodeGen::create, Subscript::special); + add(Subscript.DefaultBuiltin.class, SubscriptNodeGen::create, Subscript::special); + add(Subset.class, SubsetNodeGen::create, Subset::special); + add(Subset.DefaultBuiltin.class, SubsetNodeGen::create, Subset::special); + add(AccessField.class, AccessFieldNodeGen::create); + add(AssignBuiltin.class, AssignBuiltinNodeGen::create); + add(AssignBuiltinEq.class, AssignBuiltinEqNodeGen::create); + add(AssignOuterBuiltin.class, AssignOuterBuiltinNodeGen::create); + add(BraceBuiltin.class, BraceBuiltinNodeGen::create); + add(BreakBuiltin.class, BreakBuiltinNodeGen::create); + add(ForBuiltin.class, ForBuiltinNodeGen::create); + add(FunctionBuiltin.class, FunctionBuiltinNodeGen::create); + add(IfBuiltin.class, IfBuiltinNodeGen::create); + add(NextBuiltin.class, NextBuiltinNodeGen::create); + add(ParenBuiltin.class, ParenBuiltinNodeGen::create); + add(RepeatBuiltin.class, RepeatBuiltinNodeGen::create); + add(Tilde.class, TildeNodeGen::create); + add(UpdateSubscript.class, UpdateSubscriptNodeGen::create); + add(UpdateSubset.class, UpdateSubsetNodeGen::create); + add(UpdateField.class, UpdateFieldNodeGen::create); + add(WhileBuiltin.class, WhileBuiltinNodeGen::create); } private static void addFastPath(MaterializedFrame baseFrame, String name, FastPathFactory factory) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/InfixFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/InfixFunctions.java deleted file mode 100644 index c067d06eb48b2d7ad30d8cf159d49f7ff9b200e6..0000000000000000000000000000000000000000 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/InfixFunctions.java +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (c) 2013, 2016, 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.RDispatch.INTERNAL_GENERIC; -import static com.oracle.truffle.r.runtime.RVisibility.CUSTOM; -import static com.oracle.truffle.r.runtime.RVisibility.OFF; -import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; -import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; -import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_FRAME; -import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; - -import java.util.Arrays; - -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.NodeChild; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.profiles.BranchProfile; -import com.oracle.truffle.api.profiles.ConditionProfile; -import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; -import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode; -import com.oracle.truffle.r.nodes.access.vector.ReplaceVectorNode; -import com.oracle.truffle.r.nodes.builtin.CastBuilder; -import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.builtin.base.InfixFunctionsFactory.AccessArraySubscriptSpecialBuiltinNodeGen; -import com.oracle.truffle.r.nodes.builtin.base.InfixFunctionsFactory.PromiseEvaluatorNodeGen; -import com.oracle.truffle.r.nodes.function.ClassHierarchyNode; -import com.oracle.truffle.r.nodes.function.ClassHierarchyNodeGen; -import com.oracle.truffle.r.nodes.function.PromiseHelperNode; -import com.oracle.truffle.r.nodes.function.RCallNode; -import com.oracle.truffle.r.nodes.function.RCallSpecialNode; -import com.oracle.truffle.r.nodes.unary.CastListNode; -import com.oracle.truffle.r.nodes.unary.CastListNodeGen; -import com.oracle.truffle.r.runtime.RDeparse; -import com.oracle.truffle.r.runtime.RError; -import com.oracle.truffle.r.runtime.RInternalError; -import com.oracle.truffle.r.runtime.RRuntime; -import com.oracle.truffle.r.runtime.RType; -import com.oracle.truffle.r.runtime.RVisibility; -import com.oracle.truffle.r.runtime.builtins.RBehavior; -import com.oracle.truffle.r.runtime.builtins.RBuiltin; -import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; -import com.oracle.truffle.r.runtime.data.RDataFactory; -import com.oracle.truffle.r.runtime.data.RLanguage; -import com.oracle.truffle.r.runtime.data.RLogical; -import com.oracle.truffle.r.runtime.data.RMissing; -import com.oracle.truffle.r.runtime.data.RNull; -import com.oracle.truffle.r.runtime.data.RPromise; -import com.oracle.truffle.r.runtime.data.RStringVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractListVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractVector; -import com.oracle.truffle.r.runtime.env.REnvironment; -import com.oracle.truffle.r.runtime.nodes.RBaseNode; -import com.oracle.truffle.r.runtime.nodes.RNode; -import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; - -/** - * Work-around builtins for infix operators that FastR (currently) does not define as functions. - * These definitions create the illusion that the definitions exist, even if they are not actually - * bound to anything useful. - * - * One important reason that these must exist as {@link RBuiltin}s is that they occur when deparsing - * packages and the deparse logic depends on them being found as builtins. See {@link RDeparse}. - * - */ -public class InfixFunctions { - - @NodeChild(value = "op") - protected abstract static class PromiseEvaluator extends RNode { - - protected PromiseEvaluator create() { - return PromiseEvaluatorNodeGen.create(null); - } - - protected abstract Object execute(VirtualFrame frame, Object op); - - @Specialization(guards = {"!isRPromise(op)", "!isRArgsValuesAndNames(op)"}) - protected Object eval(Object op) { - return op; - } - - @Specialization - protected Object eval(VirtualFrame frame, RPromise p, // - @Cached("new()") PromiseHelperNode promiseHelper) { - return promiseHelper.evaluate(frame, p); - } - - @Specialization(guards = "!args.isEmpty()") - protected RArgsValuesAndNames eval(VirtualFrame frame, RArgsValuesAndNames args, // - @Cached("create()") PromiseEvaluator evalRecursive) { - Object[] values = args.getArguments(); - for (int i = 0; i < values.length; i++) { - values[i] = evalRecursive.execute(frame, values[i]); - } - return args; - } - - @Specialization(guards = "args.isEmpty()") - protected RArgsValuesAndNames evalEmpty(RArgsValuesAndNames args) { - return args; - } - } - - public abstract static class AccessArrayBuiltin extends RBuiltinNode { - - @Child private ExtractVectorNode extractNode; - - @Override - protected void createCasts(CastBuilder casts) { - casts.toLogical(2); - } - - protected abstract boolean isSubset(); - - protected Object access(VirtualFrame frame, Object vector, byte exact, RArgsValuesAndNames inds, Object dropDim) { - if (extractNode == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - extractNode = insert(ExtractVectorNode.create(isSubset() ? ElementAccessMode.SUBSET : ElementAccessMode.SUBSCRIPT, false)); - } - return extractNode.apply(frame, vector, inds.getArguments(), RLogical.valueOf(exact), dropDim); - } - - protected boolean noInd(RArgsValuesAndNames inds) { - return inds.isEmpty(); - } - } - - @RBuiltin(name = "[", kind = PRIMITIVE, parameterNames = {"x", "...", "drop"}, dispatch = INTERNAL_GENERIC, behavior = PURE) - public abstract static class AccessArraySubsetBuiltin extends AccessArrayBuiltin { - - @Override - protected boolean isSubset() { - return true; - } - - @SuppressWarnings("unused") - @Specialization - protected RNull get(RNull x, Object inds, Object dropVec) { - return x; - } - - @SuppressWarnings("unused") - @Specialization(guards = "noInd(inds)") - protected Object getNoInd(Object x, RArgsValuesAndNames inds, Object dropVec) { - return x; - } - - @SuppressWarnings("unused") - @Specialization - protected Object get(Object x, RMissing inds, Object dropVec) { - return x; - } - - @Specialization(guards = "!noInd(inds)") - protected Object get(VirtualFrame frame, Object x, RArgsValuesAndNames inds, Object dropVec) { - return access(frame, x, RRuntime.LOGICAL_TRUE, inds, dropVec); - } - } - - @RBuiltin(name = ".subset", kind = PRIMITIVE, parameterNames = {"", "...", "drop"}, behavior = PURE) - public abstract static class AccessArraySubsetDefaultBuiltin { - - } - - @NodeChild(value = "arguments", type = RNode[].class) - public abstract static class AccessArraySubscriptSpecialBuiltin extends RNode { - - @Child private ClassHierarchyNode classHierarchy = ClassHierarchyNodeGen.create(false, false); - - public static RNode create(RNode[] arguments) { - return arguments.length == 2 ? AccessArraySubscriptSpecialBuiltinNodeGen.create(arguments) : null; - } - - protected boolean simpleVector(RAbstractVector vector) { - return classHierarchy.execute(vector) == null; - } - - protected static boolean inIntRange(RAbstractVector vector, int index) { - return index >= 1 && index <= vector.getLength(); - } - - protected static boolean inDoubleRange(RAbstractVector vector, double index) { - return index >= 1 && index <= vector.getLength(); - } - - private static int toInt(double index) { - int i = (int) index; - return i == 0 ? 1 : i - 1; - } - - @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) - protected static int access(RAbstractIntVector vector, int index) { - return vector.getDataAt(index - 1); - } - - @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) - protected static double access(RAbstractDoubleVector vector, int index) { - return vector.getDataAt(index - 1); - } - - @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) - protected static int access(RAbstractIntVector vector, double index) { - return vector.getDataAt(toInt(index)); - } - - @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) - protected static double access(RAbstractDoubleVector vector, double index) { - return vector.getDataAt(toInt(index)); - } - - @SuppressWarnings("unused") - @Fallback - protected static Object access(Object vector, Object index) { - throw RCallSpecialNode.fullCallNeeded(); - } - } - - @RBuiltin(name = "[[", kind = PRIMITIVE, parameterNames = {"", "...", "exact", "drop"}, dispatch = INTERNAL_GENERIC, behavior = PURE) - public abstract static class AccessArraySubscriptBuiltin extends AccessArrayBuiltin { - - @Override - protected boolean isSubset() { - return false; - } - - private final ConditionProfile emptyExactProfile = ConditionProfile.createBinaryProfile(); - - @Override - public Object[] getDefaultParameterValues() { - return new Object[]{RMissing.instance, RArgsValuesAndNames.EMPTY, RRuntime.LOGICAL_TRUE, RRuntime.LOGICAL_TRUE}; - } - - @SuppressWarnings("unused") - @Specialization - protected RNull getNoInd(RNull x, Object inds, Object exactVec, Object dropVec) { - return x; - } - - @SuppressWarnings("unused") - @Specialization(guards = "noInd(inds)") - protected Object getNoInd(Object x, RArgsValuesAndNames inds, RAbstractLogicalVector exactVec, RAbstractLogicalVector dropVec) { - throw RError.error(this, RError.Message.NO_INDEX); - } - - @SuppressWarnings("unused") - @Specialization - protected Object get(Object x, RMissing inds, RAbstractLogicalVector exactVec, RAbstractLogicalVector dropVec) { - throw RError.error(this, RError.Message.NO_INDEX); - } - - @Specialization(guards = "!noInd(inds)") - protected Object get(VirtualFrame frame, Object x, RArgsValuesAndNames inds, RAbstractLogicalVector exactVec, @SuppressWarnings("unused") RAbstractLogicalVector dropVec) { - /* - * TODO this should not be handled here. The new vector access nodes handle this, remove - * this check as soon as its the default and the old implementation is gone. - */ - byte exact; - if (emptyExactProfile.profile(exactVec.getLength() == 0)) { - exact = RRuntime.LOGICAL_FALSE; - } else { - exact = exactVec.getDataAt(0); - } - return access(frame, x, exact, inds, RRuntime.LOGICAL_TRUE); - } - } - - @RBuiltin(name = ".subset2", kind = PRIMITIVE, parameterNames = {"x", "...", "exact", "drop"}, behavior = PURE) - public abstract static class AccessArraySubscriptDefaultBuiltin { - } - - public abstract static class UpdateArrayBuiltin extends RBuiltinNode { - - @Child private ReplaceVectorNode replaceNode; - - private final ConditionProfile argsLengthLargerThanOneProfile = ConditionProfile.createBinaryProfile(); - - protected Object update(VirtualFrame frame, Object vector, RArgsValuesAndNames args, Object value, boolean isSubset) { - if (replaceNode == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - replaceNode = insert(ReplaceVectorNode.create(isSubset ? ElementAccessMode.SUBSET : ElementAccessMode.SUBSCRIPT, false)); - } - Object[] pos; - if (argsLengthLargerThanOneProfile.profile(args.getLength() > 1)) { - pos = Arrays.copyOf(args.getArguments(), args.getLength() - 1); - } else { - pos = new Object[]{RMissing.instance}; - } - return replaceNode.apply(frame, vector, pos, value); - } - - @Specialization(guards = "noInd(args)") - @SuppressWarnings("unused") - protected Object getNoInd(Object x, RArgsValuesAndNames args) { - throw RError.error(this, RError.Message.INVALID_ARG_NUMBER, "SubAssignArgs"); - } - - protected boolean noInd(RArgsValuesAndNames args) { - return args.isEmpty(); - } - } - - @RBuiltin(name = "[<-", kind = PRIMITIVE, parameterNames = {"", "..."}, dispatch = INTERNAL_GENERIC, behavior = PURE) - public abstract static class UpdateArraySubsetBuiltin extends UpdateArrayBuiltin { - - private static final boolean IS_SUBSET = true; - - @Specialization(guards = "!noInd(args)") - protected Object update(VirtualFrame frame, Object x, RArgsValuesAndNames args) { - Object value = args.getArgument(args.getLength() - 1); - return update(frame, x, args, value, IS_SUBSET); - } - } - - @RBuiltin(name = "[[<-", kind = PRIMITIVE, parameterNames = {"", "..."}, dispatch = INTERNAL_GENERIC, behavior = PURE) - public abstract static class UpdateArrayNodeSubscriptBuiltin extends UpdateArrayBuiltin { - - private static final boolean IS_SUBSET = false; - - @Specialization(guards = "!noInd(args)") - protected Object update(VirtualFrame frame, Object x, RArgsValuesAndNames args) { - Object value = args.getArgument(args.getLength() - 1); - return update(frame, x, args, value, IS_SUBSET); - } - } - - @RBuiltin(name = "<-", visibility = RVisibility.OFF, kind = PRIMITIVE, parameterNames = {"x", "i"}, behavior = RBehavior.MODIFIES_FRAME) - public abstract static class AssignBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x, Object i) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "=", visibility = RVisibility.OFF, kind = PRIMITIVE, parameterNames = {"x", "i"}, behavior = RBehavior.MODIFIES_FRAME) - public abstract static class AssignBuiltinEq extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x, Object i) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "<<-", visibility = RVisibility.OFF, kind = PRIMITIVE, parameterNames = {"x", "i"}, behavior = COMPLEX) - public abstract static class AssignOuterBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x, Object i) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "$", kind = PRIMITIVE, parameterNames = {"", ""}, dispatch = INTERNAL_GENERIC, behavior = PURE) - public abstract static class AccessFieldBuiltin extends RBuiltinNode { - - @Child private ExtractVectorNode extract = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true); - private final BranchProfile invalidAtomicVector = BranchProfile.create(); - private final BranchProfile error = BranchProfile.create(); - - @Specialization - protected Object access(VirtualFrame frame, Object container, String field) { - if (!(container instanceof RAbstractListVector)) { - invalidAtomicVector.enter(); - if (container instanceof RAbstractVector) { - error.enter(); - throw RError.error(this, RError.Message.DOLLAR_ATOMIC_VECTORS); - } - } - return extract.applyAccessField(frame, container, field); - } - - @Fallback - protected Object fallbackError(@SuppressWarnings("unused") Object container, @SuppressWarnings("unused") Object field) { - throw RError.error(this, RError.Message.INVALID_SUBSCRIPT_TYPE, RType.Language.getName()); - } - } - - @RBuiltin(name = "$<-", kind = PRIMITIVE, parameterNames = {"", "", "value"}, dispatch = INTERNAL_GENERIC, behavior = PURE) - public abstract static class UpdateFieldBuiltin extends RBuiltinNode { - - private final BranchProfile coerceList = BranchProfile.create(); - @Child private ReplaceVectorNode extract = ReplaceVectorNode.create(ElementAccessMode.SUBSCRIPT, true); - @Child private CastListNode castList; - - @Specialization - protected Object update(VirtualFrame frame, Object container, String field, Object value) { - Object updatedObject = container; - if (!(container instanceof RAbstractListVector)) { - coerceList.enter(); - updatedObject = coerceList(container, updatedObject); - } - return extract.apply(frame, updatedObject, new Object[]{field}, value); - } - - private Object coerceList(Object object, Object vector) { - Object updatedVector = vector; - if (object instanceof RAbstractVector) { - if (castList == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - castList = insert(CastListNodeGen.create(true, true, false)); - } - RError.warning(this, RError.Message.COERCING_LHS_TO_LIST); - updatedVector = castList.executeList(vector); - } - return updatedVector; - } - - @Fallback - protected Object fallbackError(@SuppressWarnings("unused") Object container, Object field, @SuppressWarnings("unused") Object value) { - // TODO: the error message is not quite correct for all types; - // for example: x<-list(a=7); `$<-`(x, c("a"), 42);) - throw RError.error(this, RError.Message.INVALID_SUBSCRIPT_TYPE, RRuntime.classToString(field.getClass())); - } - } - - @RBuiltin(name = "{", visibility = CUSTOM, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) - public abstract static class BraceBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "(", kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) - public abstract static class ParenBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } - - /** - * This a rather strange function. It is where, in GnuR, that the "formula" class is set and the - * ".Environment" attribute on the "call". N.B. the "response" can be missing, which is actually - * handled by an evaluated argument of type {@link RMissing}, although it appears as if the - * "model" argument is missing, i.e. {@code ~ x} result in {@code `~`(x)}. - */ - @RBuiltin(name = "~", kind = PRIMITIVE, parameterNames = {"x", "y"}, nonEvalArgs = {0, 1}, behavior = READS_FRAME) - public abstract static class TildeBuiltin extends RBuiltinNode { - private static final RStringVector FORMULA_CLASS = RDataFactory.createStringVectorFromScalar(RRuntime.FORMULA_CLASS); - - @Override - public Object[] getDefaultParameterValues() { - return new Object[]{RMissing.instance, RMissing.instance}; - } - - @Specialization - protected RLanguage tilde(VirtualFrame frame, RPromise response, @SuppressWarnings("unused") RMissing model) { - return doTilde(frame, null, ((RNode) response.getRep()).asRSyntaxNode()); - } - - @Specialization - protected RLanguage tilde(VirtualFrame frame, RPromise response, RPromise model) { - return doTilde(frame, ((RNode) response.getRep()).asRSyntaxNode(), ((RNode) model.getRep()).asRSyntaxNode()); - } - - private RLanguage doTilde(VirtualFrame frame, @SuppressWarnings("unused") RSyntaxNode response, @SuppressWarnings("unused") RSyntaxNode model) { - RCallNode call = (RCallNode) ((RBaseNode) getParent()).asRSyntaxNode(); - RLanguage lang = RDataFactory.createLanguage(call); - lang.setClassAttr(FORMULA_CLASS); - REnvironment env = REnvironment.frameToEnvironment(frame.materialize()); - lang.setAttr(RRuntime.DOT_ENVIRONMENT, env); - return lang; - } - } - - @RBuiltin(name = "if", visibility = CUSTOM, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) - public abstract static class IfBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "while", visibility = OFF, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) - public abstract static class WhileBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "repeat", visibility = OFF, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) - public abstract static class RepeatBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "for", visibility = OFF, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) - public abstract static class ForBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "break", kind = PRIMITIVE, parameterNames = {"x"}, behavior = COMPLEX) - public abstract static class BreakBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "next", kind = PRIMITIVE, parameterNames = {"x"}, behavior = COMPLEX) - public abstract static class NextBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } - - @RBuiltin(name = "function", kind = PRIMITIVE, parameterNames = {"x"}, behavior = READS_FRAME) - public abstract static class FunctionBuiltin extends RBuiltinNode { - @SuppressWarnings("unused") - @Specialization - protected Object doIt(Object x) { - throw RInternalError.unimplemented(); - } - } -} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Mapply.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Mapply.java index d9e462d2389cd15358294cb570e2e5822d2bff83..ae415ae7923a679ae710be12093f9d180ed1d239 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Mapply.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Mapply.java @@ -23,7 +23,8 @@ package com.oracle.truffle.r.nodes.builtin.base; -import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.instanceOf; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.nullValue; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; @@ -39,8 +40,9 @@ import com.oracle.truffle.r.nodes.access.WriteVariableNode.Mode; import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode; import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.builtin.base.InfixFunctions.AccessArraySubscriptBuiltin; import com.oracle.truffle.r.nodes.builtin.base.MapplyNodeGen.MapplyInternalNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.infix.Subscript; +import com.oracle.truffle.r.nodes.builtin.base.infix.SubscriptNodeGen; import com.oracle.truffle.r.nodes.control.RLengthNode; import com.oracle.truffle.r.nodes.function.RCallNode; import com.oracle.truffle.r.runtime.AnonymousFrameVariable; @@ -78,7 +80,7 @@ public abstract class Mapply extends RBuiltinNode { protected static final class ElementNode extends Node { @Child private Length lengthNode; - @Child private AccessArraySubscriptBuiltin indexedLoadNode; + @Child private Subscript indexedLoadNode; @Child private WriteVariableNode writeVectorElementNode; private final String vectorElementName; private final String argName; @@ -87,7 +89,7 @@ public abstract class Mapply extends RBuiltinNode { // the name is a hack to treat ReadVariableNode-s as syntax nodes this.vectorElementName = "*" + AnonymousFrameVariable.create(vectorElementName); this.lengthNode = insert(LengthNodeGen.create(null)); - this.indexedLoadNode = insert(InfixFunctionsFactory.AccessArraySubscriptBuiltinNodeGen.create(null)); + this.indexedLoadNode = insert(SubscriptNodeGen.create(null)); this.writeVectorElementNode = insert(WriteVariableNode.createAnonymous(this.vectorElementName, null, Mode.REGULAR)); this.argName = argName; } @@ -124,7 +126,7 @@ public abstract class Mapply extends RBuiltinNode { public abstract Object[] execute(VirtualFrame frame, RAbstractListVector dots, RFunction function, RAbstractListVector additionalArguments); - private static Object getVecElement(VirtualFrame frame, RAbstractListVector dots, int i, int listIndex, int[] lengths, AccessArraySubscriptBuiltin indexedLoadNode) { + private static Object getVecElement(VirtualFrame frame, RAbstractListVector dots, int i, int listIndex, int[] lengths, Subscript indexedLoadNode) { Object listElem = dots.getDataAt(listIndex); RAbstractContainer vec = null; if (listElem instanceof RAbstractContainer) { @@ -196,7 +198,7 @@ public abstract class Mapply extends RBuiltinNode { @SuppressWarnings("unused") @Cached("createArgsIdentifier()") Object argsIdentifier, @Cached("createFrameSlotNode(argsIdentifier)") FrameSlotNode slotNode, @Cached("create()") RLengthNode lengthNode, - @Cached("createIndexedLoadNode()") AccessArraySubscriptBuiltin indexedLoadNode, + @Cached("createIndexedLoadNode()") Subscript indexedLoadNode, @Cached("createExplicitCallNode(argsIdentifier)") RCallNode callNode) { int dotsLength = dots.getLength(); int moreArgsLength = moreArgs.getLength(); @@ -280,8 +282,8 @@ public abstract class Mapply extends RBuiltinNode { return RCallNode.createExplicitCall(argsIdentifier); } - protected AccessArraySubscriptBuiltin createIndexedLoadNode() { - return InfixFunctionsFactory.AccessArraySubscriptBuiltinNodeGen.create(null); + protected Subscript createIndexedLoadNode() { + return SubscriptNodeGen.create(null); } protected boolean sameNames(RAbstractListVector list, RAbstractListVector cachedList) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AccessField.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AccessField.java new file mode 100644 index 0000000000000000000000000000000000000000..d38e586b7a6b94fcf98a6d530c5cf64cc5b3c776 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AccessField.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; +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.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Fallback; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.profiles.BranchProfile; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; +import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.RType; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.model.RAbstractListVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractVector; + +@RBuiltin(name = "$", kind = PRIMITIVE, parameterNames = {"", ""}, dispatch = INTERNAL_GENERIC, behavior = PURE) +public abstract class AccessField extends RBuiltinNode { + + @Child private ExtractVectorNode extract = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true); + + private final ConditionProfile invalidAtomicVector = ConditionProfile.createBinaryProfile(); + private final BranchProfile error = BranchProfile.create(); + + @Specialization + protected Object access(VirtualFrame frame, Object container, String field) { + if (!invalidAtomicVector.profile(container instanceof RAbstractListVector) && container instanceof RAbstractVector) { + error.enter(); + throw RError.error(this, RError.Message.DOLLAR_ATOMIC_VECTORS); + } + return extract.applyAccessField(frame, container, field); + } + + @Fallback + @TruffleBoundary + protected Object fallbackError(@SuppressWarnings("unused") Object container, @SuppressWarnings("unused") Object field) { + throw RError.error(this, RError.Message.INVALID_SUBSCRIPT_TYPE, RType.Language.getName()); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..0af31a87568f97662b715ea3ea2cc3bd3984b762 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignBuiltin.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.RVisibility; +import com.oracle.truffle.r.runtime.builtins.RBehavior; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "<-", visibility = RVisibility.OFF, kind = PRIMITIVE, parameterNames = {"x", "i"}, behavior = RBehavior.MODIFIES_FRAME) +public abstract class AssignBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x, Object i) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignBuiltinEq.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignBuiltinEq.java new file mode 100644 index 0000000000000000000000000000000000000000..95885e8a30e140035c60acd02d82af57ec80a8a7 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignBuiltinEq.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.RVisibility; +import com.oracle.truffle.r.runtime.builtins.RBehavior; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "=", visibility = RVisibility.OFF, kind = PRIMITIVE, parameterNames = {"x", "i"}, behavior = RBehavior.MODIFIES_FRAME) +public abstract class AssignBuiltinEq extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x, Object i) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignOuterBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignOuterBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..3e77803457c58a3b68035474e52d27c0054f6e49 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AssignOuterBuiltin.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.RVisibility; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "<<-", visibility = RVisibility.OFF, kind = PRIMITIVE, parameterNames = {"x", "i"}, behavior = COMPLEX) +public abstract class AssignOuterBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x, Object i) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/BraceBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/BraceBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..8f16de33a5ca16e9e182d07f0d22825ae99cfc06 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/BraceBuiltin.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RVisibility.CUSTOM; +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.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "{", visibility = CUSTOM, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) +public abstract class BraceBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/BreakBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/BreakBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..01f7da077754737f1d0db909b9d2c5868026fe5a --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/BreakBuiltin.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "break", kind = PRIMITIVE, parameterNames = {"x"}, behavior = COMPLEX) +public abstract class BreakBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ForBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ForBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..3f73a57513005f5fba456f7c5cb8bd7c86c65b4e --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ForBuiltin.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RVisibility.OFF; +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.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "for", visibility = OFF, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) +public abstract class ForBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/FunctionBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/FunctionBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..8cff9b6229b75dfb53bc83565fa8ac1c8a4762ad --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/FunctionBuiltin.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_FRAME; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "function", kind = PRIMITIVE, parameterNames = {"x"}, behavior = READS_FRAME) +public abstract class FunctionBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/IfBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/IfBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..fa86a26fed9099b43264b70447ccf4a05b2e9b8a --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/IfBuiltin.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RVisibility.CUSTOM; +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.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "if", visibility = CUSTOM, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) +public abstract class IfBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/NextBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/NextBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..b26ceb62690aa9016ec6dde9c9380820d2a511ab --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/NextBuiltin.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "next", kind = PRIMITIVE, parameterNames = {"x"}, behavior = COMPLEX) +public abstract class NextBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ParenBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ParenBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..23c4c9cbf938de9aa25c65137c0498499e9cb009 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/ParenBuiltin.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +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.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "(", kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) +public abstract class ParenBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/RepeatBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/RepeatBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..457a84b43eaad8023f769941eeeb642fec26fe59 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/RepeatBuiltin.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RVisibility.OFF; +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.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "repeat", visibility = OFF, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) +public abstract class RepeatBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java new file mode 100644 index 0000000000000000000000000000000000000000..f21fc5411eeeafa476eabc0dbb903dfc62b85ec4 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; +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.Cached; +import com.oracle.truffle.api.dsl.Fallback; +import com.oracle.truffle.api.dsl.NodeChild; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; +import com.oracle.truffle.r.nodes.access.vector.ExtractListElement; +import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.function.ClassHierarchyNode; +import com.oracle.truffle.r.nodes.function.ClassHierarchyNodeGen; +import com.oracle.truffle.r.nodes.function.RCallSpecialNode; +import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; +import com.oracle.truffle.r.runtime.data.RList; +import com.oracle.truffle.r.runtime.data.RLogical; +import com.oracle.truffle.r.runtime.data.RMissing; +import com.oracle.truffle.r.runtime.data.RNull; +import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractVector; +import com.oracle.truffle.r.runtime.nodes.RNode; + +@NodeChild(value = "arguments", type = RNode[].class) +abstract class SubscriptSpecial extends RNode { + + @Child private ClassHierarchyNode classHierarchy = ClassHierarchyNodeGen.create(false, false); + + protected boolean simpleVector(RAbstractVector vector) { + return classHierarchy.execute(vector) == null; + } + + protected static boolean inIntRange(RAbstractVector vector, int index) { + return index >= 1 && index <= vector.getLength(); + } + + protected static boolean inDoubleRange(RAbstractVector vector, double index) { + return index > 0 && index < (vector.getLength() + 1); + } + + private static int toInt(double index) { + int i = (int) index; + return i == 0 ? 1 : i - 1; + } + + @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) + protected static int access(RAbstractIntVector vector, int index) { + return vector.getDataAt(index - 1); + } + + @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) + protected static double access(RAbstractDoubleVector vector, int index) { + return vector.getDataAt(index - 1); + } + + @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) + protected static String access(RAbstractStringVector vector, int index) { + return vector.getDataAt(index - 1); + } + + @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) + protected static Object access(RList vector, int index, + @Cached("create()") ExtractListElement extract) { + return extract.execute(vector, index - 1); + } + + @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) + protected static int access(RAbstractIntVector vector, double index) { + return vector.getDataAt(toInt(index)); + } + + @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) + protected static double access(RAbstractDoubleVector vector, double index) { + return vector.getDataAt(toInt(index)); + } + + @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) + protected static String access(RAbstractStringVector vector, double index) { + return vector.getDataAt(toInt(index)); + } + + @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) + protected static Object access(RList vector, double index, + @Cached("create()") ExtractListElement extract) { + return extract.execute(vector, toInt(index)); + } + + @SuppressWarnings("unused") + @Fallback + protected Object access(Object vector, Object index) { + throw RCallSpecialNode.fullCallNeeded(); + } +} + +@RBuiltin(name = "[[", kind = PRIMITIVE, parameterNames = {"", "...", "exact", "drop"}, dispatch = INTERNAL_GENERIC, behavior = PURE) +public abstract class Subscript extends RBuiltinNode { + + @RBuiltin(name = ".subset2", kind = PRIMITIVE, parameterNames = {"x", "...", "exact", "drop"}, behavior = PURE) + public abstract class DefaultBuiltin { + // same implementation as "[[", with different dispatch + } + + public static RNode special(RNode[] arguments) { + return arguments.length == 2 ? SubscriptSpecialNodeGen.create(arguments) : null; + } + + @Child private ExtractVectorNode extractNode = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, false); + + @Override + public Object[] getDefaultParameterValues() { + return new Object[]{RMissing.instance, RArgsValuesAndNames.EMPTY, RRuntime.LOGICAL_TRUE, RRuntime.LOGICAL_TRUE}; + } + + @SuppressWarnings("unused") + @Specialization + protected RNull getNoInd(RNull x, Object inds, Object exactVec, Object drop) { + return x; + } + + @SuppressWarnings("unused") + @Specialization(guards = "indexes.isEmpty()") + protected Object getNoInd(Object x, RArgsValuesAndNames indexes, RAbstractLogicalVector exact, RAbstractLogicalVector drop) { + throw RError.error(this, RError.Message.NO_INDEX); + } + + @SuppressWarnings("unused") + @Specialization + protected Object get(Object x, RMissing indexes, RAbstractLogicalVector exact, RAbstractLogicalVector drop) { + throw RError.error(this, RError.Message.NO_INDEX); + } + + @Specialization(guards = "!indexes.isEmpty()") + protected Object get(VirtualFrame frame, Object x, RArgsValuesAndNames indexes, RAbstractLogicalVector exact, @SuppressWarnings("unused") Object drop) { + /* + * "drop" is not actually used by this builtin, but it needs to be in the argument list + * (because the "drop" argument needs to be skipped). + */ + return extractNode.apply(frame, x, indexes.getArguments(), exact, RLogical.TRUE); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java new file mode 100644 index 0000000000000000000000000000000000000000..9878b4433371e49d5903cc263508a2563386cada --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; +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.Cached; +import com.oracle.truffle.api.dsl.Fallback; +import com.oracle.truffle.api.dsl.NodeChild; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; +import com.oracle.truffle.r.nodes.access.vector.ExtractListElement; +import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.function.ClassHierarchyNode; +import com.oracle.truffle.r.nodes.function.ClassHierarchyNodeGen; +import com.oracle.truffle.r.nodes.function.RCallSpecialNode; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; +import com.oracle.truffle.r.runtime.data.RAttributeProfiles; +import com.oracle.truffle.r.runtime.data.RDataFactory; +import com.oracle.truffle.r.runtime.data.RList; +import com.oracle.truffle.r.runtime.data.RLogical; +import com.oracle.truffle.r.runtime.data.RMissing; +import com.oracle.truffle.r.runtime.data.RNull; +import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractVector; +import com.oracle.truffle.r.runtime.nodes.RNode; + +@NodeChild(value = "arguments", type = RNode[].class) +abstract class SubsetSpecial extends RNode { + + @Child private ClassHierarchyNode classHierarchy = ClassHierarchyNodeGen.create(false, false); + + private final RAttributeProfiles attrProfiles = RAttributeProfiles.create(); + + protected boolean simpleVector(RAbstractVector vector) { + return classHierarchy.execute(vector) == null && vector.getNames(attrProfiles) == null; + } + + protected static boolean inIntRange(RAbstractVector vector, int index) { + return index >= 1 && index <= vector.getLength(); + } + + protected static boolean inDoubleRange(RAbstractVector vector, double index) { + return index >= 1 && index <= vector.getLength(); + } + + private static int toInt(double index) { + int i = (int) index; + return i == 0 ? 1 : i - 1; + } + + @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) + protected static int access(RAbstractIntVector vector, int index) { + return vector.getDataAt(index - 1); + } + + @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) + protected static double access(RAbstractDoubleVector vector, int index) { + return vector.getDataAt(index - 1); + } + + @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) + protected static String access(RAbstractStringVector vector, int index) { + return vector.getDataAt(index - 1); + } + + @Specialization(guards = {"simpleVector(vector)", "inIntRange(vector, index)"}) + protected static RList access(RList vector, int index, + @Cached("create()") ExtractListElement extract) { + return RDataFactory.createList(new Object[]{extract.execute(vector, index - 1)}); + } + + @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) + protected static int access(RAbstractIntVector vector, double index) { + return vector.getDataAt(toInt(index)); + } + + @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) + protected static double access(RAbstractDoubleVector vector, double index) { + return vector.getDataAt(toInt(index)); + } + + @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) + protected static String access(RAbstractStringVector vector, double index) { + return vector.getDataAt(toInt(index)); + } + + @Specialization(guards = {"simpleVector(vector)", "inDoubleRange(vector, index)"}) + protected static RList access(RList vector, double index, + @Cached("create()") ExtractListElement extract) { + return RDataFactory.createList(new Object[]{extract.execute(vector, toInt(index))}); + } + + @SuppressWarnings("unused") + @Fallback + protected static Object access(Object vector, Object index) { + throw RCallSpecialNode.fullCallNeeded(); + } +} + +@RBuiltin(name = "[", kind = PRIMITIVE, parameterNames = {"x", "...", "drop"}, dispatch = INTERNAL_GENERIC, behavior = PURE) +public abstract class Subset extends RBuiltinNode { + + @RBuiltin(name = ".subset", kind = PRIMITIVE, parameterNames = {"", "...", "drop"}, behavior = PURE) + public abstract class DefaultBuiltin { + // same implementation as "[", with different dispatch + } + + public static RNode special(RNode[] arguments) { + return arguments.length == 2 ? SubsetSpecialNodeGen.create(arguments) : null; + } + + @Child private ExtractVectorNode extractNode = ExtractVectorNode.create(ElementAccessMode.SUBSET, false); + + @Override + protected void createCasts(CastBuilder casts) { + casts.toLogical(2); + } + + @SuppressWarnings("unused") + @Specialization + protected RNull get(RNull x, Object indexes, Object drop) { + return x; + } + + @SuppressWarnings("unused") + @Specialization(guards = "indexes.isEmpty()") + protected Object getNoInd(Object x, RArgsValuesAndNames indexes, Object drop) { + return x; + } + + @SuppressWarnings("unused") + @Specialization + protected Object get(Object x, RMissing indexes, Object drop) { + return x; + } + + @Specialization(guards = "!indexes.isEmpty()") + protected Object get(VirtualFrame frame, Object x, RArgsValuesAndNames indexes, Object drop) { + return extractNode.apply(frame, x, indexes.getArguments(), RLogical.TRUE, drop); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Tilde.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Tilde.java new file mode 100644 index 0000000000000000000000000000000000000000..fd4796410cebd8a2190091ecd20c614312a5ae79 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Tilde.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_FRAME; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.function.RCallNode; +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.RLanguage; +import com.oracle.truffle.r.runtime.data.RMissing; +import com.oracle.truffle.r.runtime.data.RPromise; +import com.oracle.truffle.r.runtime.data.RStringVector; +import com.oracle.truffle.r.runtime.env.REnvironment; +import com.oracle.truffle.r.runtime.nodes.RBaseNode; +import com.oracle.truffle.r.runtime.nodes.RNode; +import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; + +/** + * This a rather strange function. It is where, in GnuR, that the "formula" class is set and the + * ".Environment" attribute on the "call". N.B. the "response" can be missing, which is actually + * handled by an evaluated argument of type {@link RMissing}, although it appears as if the "model" + * argument is missing, i.e. {@code ~ x} result in {@code `~`(x)}. + */ +@RBuiltin(name = "~", kind = PRIMITIVE, parameterNames = {"x", "y"}, nonEvalArgs = {0, 1}, behavior = READS_FRAME) +public abstract class Tilde extends RBuiltinNode { + + private static final RStringVector FORMULA_CLASS = RDataFactory.createStringVectorFromScalar(RRuntime.FORMULA_CLASS); + + @Override + public Object[] getDefaultParameterValues() { + return new Object[]{RMissing.instance, RMissing.instance}; + } + + @Specialization + protected RLanguage tilde(VirtualFrame frame, RPromise response, @SuppressWarnings("unused") RMissing model) { + return doTilde(frame, null, ((RNode) response.getRep()).asRSyntaxNode()); + } + + @Specialization + protected RLanguage tilde(VirtualFrame frame, RPromise response, RPromise model) { + return doTilde(frame, ((RNode) response.getRep()).asRSyntaxNode(), ((RNode) model.getRep()).asRSyntaxNode()); + } + + private RLanguage doTilde(VirtualFrame frame, @SuppressWarnings("unused") RSyntaxNode response, @SuppressWarnings("unused") RSyntaxNode model) { + RCallNode call = (RCallNode) ((RBaseNode) getParent()).asRSyntaxNode(); + RLanguage lang = RDataFactory.createLanguage(call); + lang.setClassAttr(FORMULA_CLASS); + REnvironment env = REnvironment.frameToEnvironment(frame.materialize()); + lang.setAttr(RRuntime.DOT_ENVIRONMENT, env); + return lang; + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateField.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateField.java new file mode 100644 index 0000000000000000000000000000000000000000..e6ee8c4e25fd4673dd797db0f808f1632c0453fc --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateField.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; +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.CompilerDirectives; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Fallback; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; +import com.oracle.truffle.r.nodes.access.vector.ReplaceVectorNode; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.unary.CastListNode; +import com.oracle.truffle.r.nodes.unary.CastListNodeGen; +import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.model.RAbstractListVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractVector; + +@RBuiltin(name = "$<-", kind = PRIMITIVE, parameterNames = {"", "", "value"}, dispatch = INTERNAL_GENERIC, behavior = PURE) +public abstract class UpdateField extends RBuiltinNode { + + @Child private ReplaceVectorNode extract = ReplaceVectorNode.create(ElementAccessMode.SUBSCRIPT, true); + @Child private CastListNode castList; + + private final ConditionProfile coerceList = ConditionProfile.createBinaryProfile(); + + @Specialization + protected Object update(VirtualFrame frame, Object container, String field, Object value) { + Object updatedObject = container; + if (!coerceList.profile(container instanceof RAbstractListVector)) { + updatedObject = coerceList(container, updatedObject); + } + return extract.apply(frame, updatedObject, new Object[]{field}, value); + } + + private Object coerceList(Object object, Object vector) { + Object updatedVector = vector; + if (object instanceof RAbstractVector) { + if (castList == null) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + castList = insert(CastListNodeGen.create(true, true, false)); + } + RError.warning(this, RError.Message.COERCING_LHS_TO_LIST); + updatedVector = castList.executeList(vector); + } + return updatedVector; + } + + @Fallback + @TruffleBoundary + protected Object fallbackError(@SuppressWarnings("unused") Object container, Object field, @SuppressWarnings("unused") Object value) { + // TODO: the error message is not quite correct for all types; + // for example: x<-list(a=7); `$<-`(x, c("a"), 42);) + throw RError.error(this, RError.Message.INVALID_SUBSCRIPT_TYPE, RRuntime.classToString(field.getClass())); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java new file mode 100644 index 0000000000000000000000000000000000000000..abae6d456fa6566e628f29e2ff3d06c169aaa80f --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; +import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import java.util.Arrays; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; +import com.oracle.truffle.r.nodes.access.vector.ReplaceVectorNode; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; +import com.oracle.truffle.r.runtime.data.RMissing; + +@RBuiltin(name = "[[<-", kind = PRIMITIVE, parameterNames = {"", "..."}, dispatch = INTERNAL_GENERIC, behavior = PURE) +public abstract class UpdateSubscript extends RBuiltinNode { + + @Child private ReplaceVectorNode replaceNode = ReplaceVectorNode.create(ElementAccessMode.SUBSCRIPT, false); + + private final ConditionProfile argsLengthLargerThanOneProfile = ConditionProfile.createBinaryProfile(); + + @Specialization(guards = "!args.isEmpty()") + protected Object update(VirtualFrame frame, Object x, RArgsValuesAndNames args) { + Object value = args.getArgument(args.getLength() - 1); + Object[] pos; + if (argsLengthLargerThanOneProfile.profile(args.getLength() > 1)) { + pos = Arrays.copyOf(args.getArguments(), args.getLength() - 1); + } else { + pos = new Object[]{RMissing.instance}; + } + return replaceNode.apply(frame, x, pos, value); + } + + @Specialization(guards = "args.isEmpty()") + @SuppressWarnings("unused") + protected Object getNoInd(Object x, RArgsValuesAndNames args) { + throw RError.error(this, RError.Message.INVALID_ARG_NUMBER, "SubAssignArgs"); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubset.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubset.java new file mode 100644 index 0000000000000000000000000000000000000000..468a2e3ab3b793efc115e41f38b9981d8cd3c190 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubset.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; +import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +import java.util.Arrays; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; +import com.oracle.truffle.r.nodes.access.vector.ReplaceVectorNode; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; +import com.oracle.truffle.r.runtime.data.RMissing; + +@RBuiltin(name = "[<-", kind = PRIMITIVE, parameterNames = {"", "..."}, dispatch = INTERNAL_GENERIC, behavior = PURE) +public abstract class UpdateSubset extends RBuiltinNode { + + @Child private ReplaceVectorNode replaceNode = ReplaceVectorNode.create(ElementAccessMode.SUBSET, false); + + private final ConditionProfile argsLengthLargerThanOneProfile = ConditionProfile.createBinaryProfile(); + + @Specialization(guards = "!args.isEmpty()") + protected Object update(VirtualFrame frame, Object x, RArgsValuesAndNames args) { + Object value = args.getArgument(args.getLength() - 1); + Object[] pos; + if (argsLengthLargerThanOneProfile.profile(args.getLength() > 1)) { + pos = Arrays.copyOf(args.getArguments(), args.getLength() - 1); + } else { + pos = new Object[]{RMissing.instance}; + } + return replaceNode.apply(frame, x, pos, value); + } + + @Specialization(guards = "args.isEmpty()") + @SuppressWarnings("unused") + protected Object getNoInd(Object x, RArgsValuesAndNames args) { + throw RError.error(this, RError.Message.INVALID_ARG_NUMBER, "SubAssignArgs"); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/WhileBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/WhileBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..9512dd07b558e46252f01859656fa879f34015c6 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/WhileBuiltin.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2016, 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.infix; + +import static com.oracle.truffle.r.runtime.RVisibility.OFF; +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.RBuiltinNode; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; + +@RBuiltin(name = "while", visibility = OFF, kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) +public abstract class WhileBuiltin extends RBuiltinNode { + @SuppressWarnings("unused") + @Specialization + protected Object doIt(Object x) { + throw RInternalError.unimplemented(); + } +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java index c2d61bfb227fca501542427026c13c971b3838d3..044773513f6598af456b3be185fda9108d69737c 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java @@ -23,11 +23,10 @@ package com.oracle.truffle.r.nodes.builtin.helpers; import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.r.nodes.RASTBuilder; -import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode; import com.oracle.truffle.r.runtime.JumpToTopLevelException; import com.oracle.truffle.r.runtime.RArguments; import com.oracle.truffle.r.runtime.RCaller; @@ -48,6 +47,7 @@ import com.oracle.truffle.r.runtime.data.RPairList; import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.env.REnvironment; import com.oracle.truffle.r.runtime.instrument.InstrumentationState.BrowserState; +import com.oracle.truffle.r.runtime.nodes.RCodeBuilder; import com.oracle.truffle.r.runtime.nodes.RNode; import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; @@ -64,9 +64,6 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; */ public abstract class BrowserInteractNode extends RNode { - // it's never meant to be executed - private static final RSyntaxNode browserCall = new RASTBuilder().call(RSyntaxNode.INTERNAL, ReadVariableNode.create("browser")); - public static final int STEP = 0; public static final int NEXT = 1; public static final int CONTINUE = 2; @@ -87,7 +84,7 @@ public abstract class BrowserInteractNode extends RNode { if (currentCaller == null) { currentCaller = RCaller.topLevel; } - RCaller browserCaller = RCaller.create(null, currentCaller, browserCall); + RCaller browserCaller = createCaller(currentCaller); try { browserState.setInBrowser(browserCaller); LW: while (true) { @@ -176,6 +173,12 @@ public abstract class BrowserInteractNode extends RNode { return exitMode; } + @TruffleBoundary + private static RCaller createCaller(RCaller currentCaller) { + RCodeBuilder<RSyntaxNode> builder = RContext.getASTBuilder(); + return RCaller.create(null, currentCaller, builder.call(RSyntaxNode.INTERNAL, builder.lookup(RSyntaxNode.INTERNAL, "browser", true))); + } + private static String getSrcinfo(RStringVector element) { Object srcref = element.getAttr(RRuntime.R_SRCREF); if (srcref != null) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractListElement.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractListElement.java index 35bbcbf01095cd8a29f5a2fcb94924006a3c49ce..6ecdd95d18dbd4e533d7a1e20b05aa0a4d2518c6 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractListElement.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractListElement.java @@ -52,6 +52,10 @@ public abstract class ExtractListElement extends Node { public abstract Object execute(RAbstractContainer container, int index); + public static ExtractListElement create() { + return ExtractListElementNodeGen.create(); + } + @Specialization protected Object doList(RListBase list, int index, @Cached("create()") UpdateStateOfListElement updateStateNode) { Object element = list.getDataAt(index); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java index fc91a9d69277994c0b9e909950283645ce98bd14..c86bb8ea230a03ad1f112810f5d7e49f4635329a 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java @@ -196,5 +196,4 @@ public abstract class ExtractVectorNode extends Node { return cached; } } - } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallSpecialNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallSpecialNode.java index 7ac75d817183132bb315803506c9142990a6ec66..3f0d7bfa66c14a49b0b12bfb5731edae52441c20 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallSpecialNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallSpecialNode.java @@ -38,6 +38,7 @@ import com.oracle.truffle.r.runtime.data.RFunction; import com.oracle.truffle.r.runtime.data.RPromise; import com.oracle.truffle.r.runtime.nodes.RNode; import com.oracle.truffle.r.runtime.nodes.RSyntaxCall; +import com.oracle.truffle.r.runtime.nodes.RSyntaxConstant; import com.oracle.truffle.r.runtime.nodes.RSyntaxElement; import com.oracle.truffle.r.runtime.nodes.RSyntaxLookup; import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; @@ -140,7 +141,7 @@ public final class RCallSpecialNode extends RCallBaseNode implements RSyntaxNode return null; } for (RSyntaxNode argument : arguments) { - if (!(argument instanceof RSyntaxLookup)) { + if (!(argument instanceof RSyntaxLookup || argument instanceof RSyntaxConstant)) { // argument is not a simple lookup -> bail out return null; } @@ -153,7 +154,12 @@ public final class RCallSpecialNode extends RCallBaseNode implements RSyntaxNode } RNode[] localArguments = new RNode[arguments.length]; for (int i = 0; i < arguments.length; i++) { - localArguments[i] = new PeekLocalVariableNode(((RSyntaxLookup) arguments[i]).getIdentifier()); + if (arguments[i] instanceof RSyntaxLookup) { + localArguments[i] = new PeekLocalVariableNode(((RSyntaxLookup) arguments[i]).getIdentifier()); + } else { + assert arguments[i] instanceof RSyntaxConstant; + localArguments[i] = RContext.getASTBuilder().process(arguments[i]).asRNode(); + } } RNode special = builtinDescriptor.getSpecialCall().apply(localArguments); if (special == null) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/builtins/RBuiltinDescriptor.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/builtins/RBuiltinDescriptor.java index c48d1283be72ae620076c3f4cab9cf2f4fdd6f01..3196442a05c3e0038d28ba2966eac0de5e5c7367 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/builtins/RBuiltinDescriptor.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/builtins/RBuiltinDescriptor.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.function.Function; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.PrimitiveMethodsInfo; import com.oracle.truffle.r.runtime.RDispatch;