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 246682bb7f1b3923f2340b7a5f4d887feb889b80..dfc372a3ed7589e2c18b15a986297e123783fa2e 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 @@ -475,7 +475,6 @@ public class BasePackage extends RBuiltinPackage { add(GetFunctions.Get.class, GetFunctionsFactory.GetNodeGen::create); add(GetFunctions.Get0.class, GetFunctionsFactory.Get0NodeGen::create); add(GetFunctions.MGet.class, GetFunctionsFactory.MGetNodeGen::create); - add(GetOldClass.class, GetOldClassNodeGen::create); add(OptionsFunctions.GetOption.class, OptionsFunctionsFactory.GetOptionNodeGen::create); add(GetText.class, GetTextNodeGen::create); add(Getwd.class, GetwdNodeGen::create); @@ -586,6 +585,7 @@ public class BasePackage extends RBuiltinPackage { add(NamespaceFunctions.RegisterNamespace.class, NamespaceFunctionsFactory.RegisterNamespaceNodeGen::create); add(NamespaceFunctions.UnregisterNamespace.class, NamespaceFunctionsFactory.UnregisterNamespaceNodeGen::create); add(NormalizePath.class, NormalizePathNodeGen::create); + add(OldClass.class, OldClassNodeGen::create); add(OnExit.class, OnExitNodeGen::create); add(OptionsFunctions.Options.class, OptionsFunctionsFactory.OptionsNodeGen::create); add(Order.class, OrderNodeGen::create); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GetOldClass.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OldClass.java similarity index 67% rename from com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GetOldClass.java rename to com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OldClass.java index a0e3caa5659487e3fd021c13191e4756a508ce73..14fa5968ae185f36753702ceeff1ba52718fdb24 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GetOldClass.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OldClass.java @@ -25,50 +25,37 @@ package com.oracle.truffle.r.nodes.builtin.base; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; -import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.GetClassAttributeNode; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.function.ClassHierarchyNode; import com.oracle.truffle.r.runtime.builtins.RBuiltin; -import com.oracle.truffle.r.runtime.data.RFunction; +import com.oracle.truffle.r.runtime.data.RAttributable; import com.oracle.truffle.r.runtime.data.RNull; -import com.oracle.truffle.r.runtime.data.RSymbol; -import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; @RBuiltin(name = "oldClass", kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) -public abstract class GetOldClass extends RBuiltinNode.Arg1 { +public abstract class OldClass extends RBuiltinNode.Arg1 { private final ConditionProfile isObjectProfile = ConditionProfile.createBinaryProfile(); @Child private GetClassAttributeNode getClassNode = GetClassAttributeNode.create(); static { - Casts.noCasts(GetOldClass.class); + Casts.noCasts(OldClass.class); } @Specialization - protected Object getOldClass(RAbstractContainer arg, - @Cached("createWithImplicit()") ClassHierarchyNode hierarchy) { - if (isObjectProfile.profile(getClassNode.isObject(arg))) { - return hierarchy.execute(arg); + protected Object getOldClass(RAttributable arg) { + Object clazz = getClassNode.execute(arg); + if (isObjectProfile.profile(clazz != null)) { + return clazz; } else { return RNull.instance; } } - @Specialization - protected Object getOldClass(@SuppressWarnings("unused") RSymbol arg) { - return RNull.instance; - } - - @Specialization - protected Object getOldClass(@SuppressWarnings("unused") RFunction arg) { - return RNull.instance; - } - - @Specialization - protected Object getOldClass(@SuppressWarnings("unused") RNull arg) { + @Fallback + protected Object getOldClass(@SuppressWarnings("unused") Object arg) { return RNull.instance; } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateClass.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateClass.java index b32345f7ff7d7d80c006a9356eaf8cdabfcf0617..e45147319f4d1608535cd35788ef28dc61a80b2f 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateClass.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateClass.java @@ -90,7 +90,7 @@ public abstract class UpdateClass extends RBuiltinNode.Arg2 { if (!getClassNode.isObject(arg)) { initTypeof(); RType argType = typeof.execute(arg); - if (argType.equals(className) || (mode == RType.Double && (argType == RType.Integer || argType == RType.Double))) { + if (argType.getClazz().equals(className) || (mode == RType.Double && (argType == RType.Integer || argType == RType.Double))) { // "explicit" attribute might have been set (e.g. by oldClass<-) return setClass(arg, RNull.instance); } @@ -127,7 +127,16 @@ public abstract class UpdateClass extends RBuiltinNode.Arg2 { return result; } - @Specialization + @Specialization(guards = "className.getLength() == 1") + @TruffleBoundary + protected Object setClassLengthOne(RAbstractContainer arg, RStringVector className, + @Cached("create()") TypeFromModeNode typeFromMode, + @Cached("create()") GetClassAttributeNode getClassNode) { + RType mode = typeFromMode.execute(className.getDataAt(0)); + return setClassInternal(arg, className.getDataAt(0), mode, getClassNode); + } + + @Specialization(guards = "className.getLength() != 1") @TruffleBoundary protected Object setClass(RAbstractContainer arg, RStringVector className) { RAbstractContainer result = reuseNonShared(arg); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateOldClass.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateOldClass.java index d161c6383775de582b12f109d93730547cc9aede..081c587999d6d92b74275099bb64fcc3eafeca0a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateOldClass.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateOldClass.java @@ -33,6 +33,7 @@ import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.SetClass import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.unary.CastStringNode; import com.oracle.truffle.r.nodes.unary.CastStringNodeGen; +import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RNull; @@ -89,4 +90,9 @@ public abstract class UpdateOldClass extends RBuiltinNode.Arg2 { setClassAttributeNode.reset(result); return result; } + + @Specialization + protected Object setOldClass(@SuppressWarnings("unused") RNull arg, @SuppressWarnings("unused") Object className) { + throw error(Message.INVALID_NULL_LHS); + } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/compiler/R/compiler_overrides.R b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/compiler/R/compiler_overrides.R new file mode 100644 index 0000000000000000000000000000000000000000..f7bfb97550110fae9ecf410b22f25fcd7aaaaa62 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/compiler/R/compiler_overrides.R @@ -0,0 +1,24 @@ +# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. + +eval(expression({ +compile <- function(f, ...) f +}), asNamespace("compiler")) diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java index 0a8d63ec7ed252318654e764ef1e79573fbcfcf3..5f3c5e577e81a4c16cb1a55aa006ad9dab0d1fb3 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java @@ -35,9 +35,18 @@ import com.oracle.truffle.r.runtime.RDeparse; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RType; +import com.oracle.truffle.r.runtime.data.RComplex; +import com.oracle.truffle.r.runtime.data.RComplexVector; +import com.oracle.truffle.r.runtime.data.RDoubleVector; +import com.oracle.truffle.r.runtime.data.RIntVector; import com.oracle.truffle.r.runtime.data.RLanguage; +import com.oracle.truffle.r.runtime.data.RLogicalVector; +import com.oracle.truffle.r.runtime.data.RRaw; +import com.oracle.truffle.r.runtime.data.RRawVector; import com.oracle.truffle.r.runtime.data.RString; +import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.data.RSymbol; +import com.oracle.truffle.r.runtime.data.RVector; import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; @@ -153,6 +162,56 @@ public abstract class BinaryBooleanNode extends RBuiltinNode.Arg2 { return RString.valueOf(RDeparse.deparse(val, RDeparse.MAX_CUTOFF, false, RDeparse.KEEPINTEGER, -1)); } + protected static boolean isOneList(Object left, Object right) { + return isRAbstractListVector(left) ^ isRAbstractListVector(right); + } + + @Specialization(guards = {"isOneList(left, right)"}) + protected Object doList(VirtualFrame frame, RAbstractVector left, RAbstractVector right, + @Cached("create()") CastTypeNode cast, + + @Cached("createRecursive()") BinaryBooleanNode recursive) { + Object recursiveLeft = left; + if (isRAbstractListVector(left)) { + recursiveLeft = castListToAtomic(left, cast, right.getRType()); + } + Object recursiveRight = right; + if (isRAbstractListVector(right)) { + recursiveRight = castListToAtomic(right, cast, left.getRType()); + } + return recursive.execute(frame, recursiveLeft, recursiveRight); + } + + @TruffleBoundary + private static Object castListToAtomic(RAbstractVector source, CastTypeNode cast, RType type) { + RVector<?> result = type.create(source.getLength(), false); + Object store = result.getInternalStore(); + for (int i = 0; i < source.getLength(); i++) { + Object value = source.getDataAtAsObject(i); + if (type == RType.Character) { + value = RDeparse.deparse(value); + ((RStringVector) result).setDataAt(store, i, (String) value); + } else { + value = cast.execute(value, type); + if (value instanceof RAbstractVector && ((RAbstractVector) value).getLength() == 1) { + value = ((RAbstractVector) value).getDataAtAsObject(0); + } + if (type == RType.Integer && value instanceof Integer) { + ((RIntVector) result).setDataAt(store, i, (int) value); + } else if (type == RType.Double && value instanceof Double) { + ((RDoubleVector) result).setDataAt(store, i, (double) value); + } else if (type == RType.Logical && value instanceof Byte) { + ((RLogicalVector) result).setDataAt(store, i, (byte) value); + } else if (type == RType.Complex && value instanceof RComplex) { + ((RComplexVector) result).setDataAt(store, i, (RComplex) value); + } else if (type == RType.Raw && value instanceof RRaw) { + ((RRawVector) result).setRawDataAt(store, i, ((RRaw) value).getValue()); + } + } + } + return result; + } + protected BinaryBooleanNode createRecursive() { return BinaryBooleanNode.create(factory); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementDispatchNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementDispatchNode.java index 797c096ae9a022fd1f8d599e86b0ca240619bd9b..46906aeebc5ce7b0133ff4eef73a250d0baef3a8 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementDispatchNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementDispatchNode.java @@ -34,7 +34,6 @@ import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.r.nodes.RASTUtils; import com.oracle.truffle.r.nodes.access.WriteVariableNode; import com.oracle.truffle.r.nodes.access.WriteVariableSyntaxNode; -import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RInternalError; @@ -158,16 +157,7 @@ public final class ReplacementDispatchNode extends OperatorNode { current = call.getSyntaxArguments()[0]; } RSyntaxLookup variable = (RSyntaxLookup) current; - ReadVariableNode varRead = createReplacementForVariableUsing(variable, isSuper); - return ReplacementNode.create(getLazySourceSection(), operator, varRead, lhs.asRSyntaxNode(), rhs, calls, variable.getIdentifier(), isSuper, tempNamesStartIndex, isVoid); - } - - private static ReadVariableNode createReplacementForVariableUsing(RSyntaxLookup var, boolean isSuper) { - if (isSuper) { - return ReadVariableNode.createSuperLookup(var.getLazySourceSection(), var.getIdentifier()); - } else { - return ReadVariableNode.create(var.getLazySourceSection(), var.getIdentifier(), true); - } + return ReplacementNode.create(getLazySourceSection(), operator, variable, lhs.asRSyntaxNode(), rhs, calls, isSuper, tempNamesStartIndex, isVoid); } /* diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java index ca56335a05ff1e8ee2ae11e192a9e19829cdfc22..284ebf3436c1618a1eb5833555b8b75403c78a03 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java @@ -35,6 +35,7 @@ import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.r.nodes.access.RemoveAndAnswerNode; import com.oracle.truffle.r.nodes.access.WriteVariableNode; import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode; +import com.oracle.truffle.r.nodes.function.PeekLocalVariableNode; import com.oracle.truffle.r.nodes.function.RCallSpecialNode; import com.oracle.truffle.r.nodes.function.visibility.SetVisibilityNode; import com.oracle.truffle.r.nodes.unary.GetNonSharedNode; @@ -65,8 +66,8 @@ abstract class ReplacementNode extends OperatorNode { return RContext.getASTBuilder().process(this).asRNode(); } - public static ReplacementNode create(SourceSection source, RSyntaxLookup operator, RNode target, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, - String targetVarName, boolean isSuper, int tempNamesStartIndex, boolean isVoid) { + public static ReplacementNode create(SourceSection source, RSyntaxLookup operator, RSyntaxLookup variable, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, + boolean isSuper, int tempNamesStartIndex, boolean isVoid) { CompilerAsserts.neverPartOfCompilation(); // Note: if specials are turned off in FastR, onlySpecials will never be true boolean createSpecial = hasOnlySpecialCalls(calls); @@ -76,12 +77,12 @@ abstract class ReplacementNode extends OperatorNode { * special call for "replace". */ if (isVoid) { - return new SpecialVoidReplacementNode(source, operator, target, lhs, rhs, calls, targetVarName, isSuper, tempNamesStartIndex); + return new SpecialVoidReplacementNode(source, operator, variable, lhs, rhs, calls, isSuper, tempNamesStartIndex); } else { - return new SpecialReplacementNode(source, operator, target, lhs, rhs, calls, targetVarName, isSuper, tempNamesStartIndex); + return new SpecialReplacementNode(source, operator, variable, lhs, rhs, calls, isSuper, tempNamesStartIndex); } } else { - return new GenericReplacementNode(source, operator, target, lhs, rhs, calls, targetVarName, isSuper, tempNamesStartIndex); + return new GenericReplacementNode(source, operator, variable, lhs, rhs, calls, isSuper, tempNamesStartIndex); } } @@ -163,6 +164,14 @@ abstract class ReplacementNode extends OperatorNode { return null; } + private static RNode createReplacementTarget(RSyntaxLookup variable, boolean isSuper, boolean localPeek) { + if (isSuper) { + return ReadVariableNode.createSuperLookup(variable.getLazySourceSection(), variable.getIdentifier()); + } else { + return localPeek ? new PeekLocalVariableNode(variable.getIdentifier()) : ReadVariableNode.create(variable.getLazySourceSection(), variable.getIdentifier(), true); + } + } + private abstract static class ReplacementWithRhsNode extends ReplacementNode { @Child private WriteVariableNode storeRhs; @@ -226,15 +235,12 @@ abstract class ReplacementNode extends OperatorNode { private final List<RSyntaxCall> calls; private final int tempNamesStartIndex; private final boolean isSuper; - private final String targetVarName; - private final RNode target; + private final RSyntaxLookup variable; - SpecialReplacementNode(SourceSection source, RSyntaxLookup operator, RNode target, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, String targetVarName, - boolean isSuper, int tempNamesStartIndex) { + SpecialReplacementNode(SourceSection source, RSyntaxLookup operator, RSyntaxLookup variable, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, boolean isSuper, int tempNamesStartIndex) { super(source, operator, lhs, rhs, tempNamesStartIndex); - this.target = target; + this.variable = variable; this.calls = calls; - this.targetVarName = targetVarName; this.isSuper = isSuper; this.tempNamesStartIndex = tempNamesStartIndex; @@ -242,7 +248,7 @@ abstract class ReplacementNode extends OperatorNode { * Creates a replacement that consists only of {@link RCallSpecialNode} calls. */ CodeBuilderContext codeBuilderContext = new CodeBuilderContext(tempNamesStartIndex + 2); - RNode extractFunc = target; + RNode extractFunc = createReplacementTarget(variable, isSuper, true); for (int i = calls.size() - 1; i >= 1; i--) { extractFunc = createSpecialFunctionQuery(calls.get(i), extractFunc.asRSyntaxNode(), codeBuilderContext); ((RCallSpecialNode) extractFunc).setPropagateFullCallNeededException(); @@ -261,7 +267,7 @@ abstract class ReplacementNode extends OperatorNode { replaceCall.execute(frame); } catch (FullCallNeededException e) { CompilerDirectives.transferToInterpreterAndInvalidate(); - replace(new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), calls, targetVarName, isSuper, + replace(new GenericReplacementNode(getLazySourceSection(), operator, variable, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), calls, isSuper, tempNamesStartIndex)).executeReplacement(frame); } } @@ -280,16 +286,14 @@ abstract class ReplacementNode extends OperatorNode { private final List<RSyntaxCall> calls; private final int tempNamesStartIndex; private final boolean isSuper; - private final String targetVarName; - private final RNode target; + private final RSyntaxLookup variable; - SpecialVoidReplacementNode(SourceSection source, RSyntaxLookup operator, RNode target, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, String targetVarName, - boolean isSuper, int tempNamesStartIndex) { + SpecialVoidReplacementNode(SourceSection source, RSyntaxLookup operator, RSyntaxLookup variable, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, boolean isSuper, + int tempNamesStartIndex) { super(source, operator, lhs); - this.target = target; + this.variable = variable; this.rhs = rhs; this.calls = calls; - this.targetVarName = targetVarName; this.isSuper = isSuper; this.tempNamesStartIndex = tempNamesStartIndex; @@ -297,7 +301,7 @@ abstract class ReplacementNode extends OperatorNode { * Creates a replacement that consists only of {@link RCallSpecialNode} calls. */ CodeBuilderContext codeBuilderContext = new CodeBuilderContext(tempNamesStartIndex + 2); - RNode extractFunc = target; + RNode extractFunc = createReplacementTarget(variable, isSuper, true); for (int i = calls.size() - 1; i >= 1; i--) { extractFunc = createSpecialFunctionQuery(calls.get(i), extractFunc.asRSyntaxNode(), codeBuilderContext); ((RCallSpecialNode) extractFunc).setPropagateFullCallNeededException(); @@ -309,8 +313,8 @@ abstract class ReplacementNode extends OperatorNode { @Override public Object execute(VirtualFrame frame) { CompilerDirectives.transferToInterpreterAndInvalidate(); - GenericReplacementNode replacement = new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), calls, - targetVarName, isSuper, tempNamesStartIndex); + GenericReplacementNode replacement = new GenericReplacementNode(getLazySourceSection(), operator, variable, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), calls, + isSuper, tempNamesStartIndex); return replace(replacement).execute(frame); } @@ -324,8 +328,9 @@ abstract class ReplacementNode extends OperatorNode { replaceCall.execute(frame); } catch (FullCallNeededException e) { CompilerDirectives.transferToInterpreterAndInvalidate(); - GenericReplacementNode replacement = replace(new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), - calls, targetVarName, isSuper, tempNamesStartIndex)); + GenericReplacementNode replacement = replace( + new GenericReplacementNode(getLazySourceSection(), operator, variable, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), + calls, isSuper, tempNamesStartIndex)); if (e.rhsValue == null) { // we haven't queried the rhs value yet @@ -352,8 +357,7 @@ abstract class ReplacementNode extends OperatorNode { @Children private final WriteVariableNode[] updates; - GenericReplacementNode(SourceSection source, RSyntaxLookup operator, RNode target, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, String targetVarName, boolean isSuper, - int tempNamesStartIndex) { + GenericReplacementNode(SourceSection source, RSyntaxLookup operator, RSyntaxLookup variable, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, boolean isSuper, int tempNamesStartIndex) { super(source, operator, lhs, rhs, tempNamesStartIndex); /* * When there are more than two function calls in LHS, then we save some function calls @@ -363,6 +367,7 @@ abstract class ReplacementNode extends OperatorNode { CodeBuilderContext codeBuilderContext = new CodeBuilderContext(tempNamesStartIndex + calls.size() + 1); int targetIndex = tempNamesStartIndex; + RNode target = createReplacementTarget(variable, isSuper, false); instructions.add(WriteVariableNode.createAnonymous(getTargetTemp(targetIndex), WriteVariableNode.Mode.INVISIBLE, wrapForSlotUpdate(target, calls.get(calls.size() - 1)))); /* * Create the calls that extract inner components - only needed for complex replacements @@ -387,7 +392,7 @@ abstract class ReplacementNode extends OperatorNode { if (i < calls.size() - 1) { instructions.add(WriteVariableNode.createAnonymous(getRHSTemp(++replacementIndex), WriteVariableNode.Mode.INVISIBLE, update)); } else { - instructions.add(WriteVariableNode.createAnonymous(targetVarName, WriteVariableNode.Mode.REGULAR, update, isSuper)); + instructions.add(WriteVariableNode.createAnonymous(variable.getIdentifier(), WriteVariableNode.Mode.REGULAR, update, isSuper)); } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/FunctionDefinitionNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/FunctionDefinitionNode.java index 3f33e34cf801c3982970601817ad65269ceeae31..388fd224ee8f5c083a140726c617a4dfd277506a 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/FunctionDefinitionNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/FunctionDefinitionNode.java @@ -175,10 +175,10 @@ public final class FunctionDefinitionNode extends RRootNode implements RSyntaxNo List<RCodeBuilder.Argument<RSyntaxNode>> args = new ArrayList<>(); for (int i = 0; i < getFormalArguments().getLength(); i++) { RNode value = getFormalArguments().getArgument(i); - SourceSection source = argSourceSections == null ? getSourceSection() : argSourceSections[i]; + SourceSection source = argSourceSections == null ? getLazySourceSection() : argSourceSections[i]; args.add(RCodeBuilder.argument(source, getFormalArguments().getSignature().getName(i), value == null ? null : builder.process(value.asRSyntaxNode()))); } - RootCallTarget callTarget = builder.rootFunction(getRLanguage(), getSourceSection(), args, builder.process(getBody()), name); + RootCallTarget callTarget = builder.rootFunction(getRLanguage(), getLazySourceSection(), args, builder.process(getBody()), name); return callTarget; } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/PeekLocalVariableNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/PeekLocalVariableNode.java new file mode 100644 index 0000000000000000000000000000000000000000..6ee9ad6abffc088c26d921c5b8a0c0d3f768992e --- /dev/null +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/PeekLocalVariableNode.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.nodes.function; + +import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.profiles.ValueProfile; +import com.oracle.truffle.api.source.SourceSection; +import com.oracle.truffle.r.nodes.access.variables.LocalReadVariableNode; +import com.oracle.truffle.r.nodes.function.visibility.SetVisibilityNode; +import com.oracle.truffle.r.runtime.Utils; +import com.oracle.truffle.r.runtime.builtins.RSpecialFactory; +import com.oracle.truffle.r.runtime.nodes.RNode; +import com.oracle.truffle.r.runtime.nodes.RSyntaxLookup; +import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; + +public final class PeekLocalVariableNode extends RNode implements RSyntaxNode, RSyntaxLookup { + + @Child private LocalReadVariableNode read; + @Child private SetVisibilityNode visibility; + + private final ValueProfile valueProfile = ValueProfile.createClassProfile(); + + public PeekLocalVariableNode(String name) { + this.read = LocalReadVariableNode.create(Utils.intern(name), true); + } + + @Override + public Object execute(VirtualFrame frame) { + Object value = read.execute(frame); + if (value == null) { + throw RSpecialFactory.throwFullCallNeeded(); + } + return valueProfile.profile(value); + } + + @Override + public Object visibleExecute(VirtualFrame frame) { + try { + return execute(frame); + } finally { + if (visibility == null) { + CompilerDirectives.transferToInterpreter(); + visibility = insert(SetVisibilityNode.create()); + } + visibility.execute(frame, true); + } + } + + @Override + public void setSourceSection(SourceSection source) { + // nothing to do + } + + @Override + public String getIdentifier() { + return (String) read.getIdentifier(); + } + + @Override + public boolean isFunctionLookup() { + return false; + } + + @Override + public SourceSection getSourceSection() { + return null; + } + + @Override + public SourceSection getLazySourceSection() { + return null; + } +} 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 31cb895142930c6a530ad3597cf778573046127e..98a793a0147a1f032e48fafd264fc5299d5874e0 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 @@ -32,9 +32,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeCost; import com.oracle.truffle.api.nodes.NodeInfo; -import com.oracle.truffle.api.profiles.ValueProfile; import com.oracle.truffle.api.source.SourceSection; -import com.oracle.truffle.r.nodes.access.variables.LocalReadVariableNode; import com.oracle.truffle.r.nodes.function.visibility.SetVisibilityNode; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.FastROptions; @@ -43,7 +41,6 @@ import com.oracle.truffle.r.runtime.RDispatch; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RVisibility; -import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltinDescriptor; import com.oracle.truffle.r.runtime.builtins.RSpecialFactory; import com.oracle.truffle.r.runtime.context.RContext; @@ -57,60 +54,6 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxElement; import com.oracle.truffle.r.runtime.nodes.RSyntaxLookup; import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; -final class PeekLocalVariableNode extends RNode implements RSyntaxLookup { - - @Child private LocalReadVariableNode read; - @Child private SetVisibilityNode visibility; - - private final ValueProfile valueProfile = ValueProfile.createClassProfile(); - - PeekLocalVariableNode(String name) { - this.read = LocalReadVariableNode.create(Utils.intern(name), true); - } - - @Override - public Object execute(VirtualFrame frame) { - Object value = read.execute(frame); - if (value == null) { - throw RSpecialFactory.throwFullCallNeeded(); - } - return valueProfile.profile(value); - } - - @Override - public Object visibleExecute(VirtualFrame frame) { - try { - return execute(frame); - } finally { - if (visibility == null) { - CompilerDirectives.transferToInterpreter(); - visibility = insert(SetVisibilityNode.create()); - } - visibility.execute(frame, true); - } - } - - @Override - public void setSourceSection(SourceSection source) { - // nothing to do - } - - @Override - public String getIdentifier() { - return (String) read.getIdentifier(); - } - - @Override - public boolean isFunctionLookup() { - return false; - } - - @Override - public SourceSection getLazySourceSection() { - return null; - } -} - @NodeChild(value = "delegate", type = RNode.class) abstract class ClassCheckNode extends RNode { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/instrumentation/RInstrumentation.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/instrumentation/RInstrumentation.java index 11255b7cc08a46132cc79e6e7a0cd08379a67502..56581f056d86f41181c127609c525a11ae84f6b4 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/instrumentation/RInstrumentation.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/instrumentation/RInstrumentation.java @@ -54,7 +54,7 @@ public class RInstrumentation { } public static SourceSection getSourceSection(RFunction func) { - return getFunctionDefinitionNode(func).getSourceSection(); + return func.getRootNode().getSourceSection(); } /** @@ -79,7 +79,8 @@ public class RInstrumentation { builder.tagIs(tag); SourceSection fdns = fdn.getSourceSection(); builder.indexIn(fdns.getCharIndex(), fdns.getCharLength()); - builder.sourceIs(fdns.getSource()); + Source source = fdns.getSource(); + builder.sourceIs(s -> source.equals(s)); return builder; } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 60d3794b83ae8ca0134c376aeb103c78f72fad11..c92d40e833503d3bcc33aac8b09e65cb5267d05f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -3085,7 +3085,7 @@ In anyDuplicated.default(c(1L, 2L, 1L, 1L, 3L, 2L), incomparables = "cat") : #argv <- list(c('1', '4', '6', '9', '11', NA, '15', '16', '17', '20', '21', '23', '29', '41', '45', '48', '55', '62', '63', '65', '70', '74', '82', '83', '85', '86', '92', '93', '97', '98', '99', '103', '104', '106', '108', '109', '112', '113', '120', '126', '127', '128', '132', '139', '142', '145', '148', '151', '159', '164', '165', '169', '171', '173', '175', '189', '191', '193', '194', '195', '198', '200', '202', '209', '212', '213', '215', '216', '221', '223', '224', '227'), FALSE, FALSE); .Internal(anyDuplicated(argv[[1]], argv[[2]], argv[[3]])) [1] 0 -##com.oracle.truffle.r.test.builtins.TestBuiltin_anyDuplicated.testanyDuplicated18#Ignored.ImplementationError# +##com.oracle.truffle.r.test.builtins.TestBuiltin_anyDuplicated.testanyDuplicated18# #argv <- structure(list(x = structure(c(3, 2, 7, 2, 6, 2, 7, 2), .Dim = c(4L, 2L), .Dimnames = list(c('A', 'B', 'C', 'D'), c('M', 'F'))), MARGIN = 0), .Names = c('x', 'MARGIN'));do.call('anyDuplicated', argv) [1] 4 @@ -3129,7 +3129,7 @@ In anyDuplicated.default(c(1L, 2L, 1L, 1L, 3L, 2L), incomparables = "cat") : #argv <- structure(list(x = c(1, NA, 3, NA, 3), incomparables = c(3, NA)), .Names = c('x', 'incomparables'));do.call('anyDuplicated.default', argv) [1] 0 -##com.oracle.truffle.r.test.builtins.TestBuiltin_anyDuplicatedmatrix.testanyDuplicatedmatrix1#Ignored.ImplementationError# +##com.oracle.truffle.r.test.builtins.TestBuiltin_anyDuplicatedmatrix.testanyDuplicatedmatrix1# #argv <- structure(list(x = structure(c(3, 2, 7, 2, 6, 2, 7, 2), .Dim = c(4L, 2L), .Dimnames = list(c('A', 'B', 'C', 'D'), c('M', 'F'))), MARGIN = 0), .Names = c('x', 'MARGIN'));do.call('anyDuplicated.matrix', argv) [1] 4 @@ -39368,7 +39368,7 @@ ab TRUE TRUE #argv <- list(c(1, 1, 10, 1, 1, 10, 10), 0);`!=`(argv[[1]],argv[[2]]); [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE -##com.oracle.truffle.r.test.builtins.TestBuiltin_operators.testoperators130#Ignored.ImplementationError# +##com.oracle.truffle.r.test.builtins.TestBuiltin_operators.testoperators130# #argv <- list(2, structure(list(2L), class = structure('L', package = '.GlobalEnv')));`==`(argv[[1]],argv[[2]]); [1] TRUE @@ -45101,7 +45101,7 @@ Error in prod(list()) : invalid 'type' (list) of argument #prod( ); [1] 1 -##com.oracle.truffle.r.test.builtins.TestBuiltin_prod.testprod11#Ignored.ImplementationError# +##com.oracle.truffle.r.test.builtins.TestBuiltin_prod.testprod11# #argv <- list(numeric(0));prod(argv[[1]]); [1] 1 @@ -45117,7 +45117,7 @@ Error in prod(list()) : invalid 'type' (list) of argument #argv <- list(structure(c(4L, 4L, 2L), .Names = c('Hair', 'Eye', 'Sex')));prod(argv[[1]]); [1] 32 -##com.oracle.truffle.r.test.builtins.TestBuiltin_prod.testprod5#Ignored.ImplementationError# +##com.oracle.truffle.r.test.builtins.TestBuiltin_prod.testprod5# #argv <- list(integer(0));prod(argv[[1]]); [1] 1 @@ -63982,7 +63982,7 @@ Error in sinpi() : 0 arguments passed to 'sinpi' which requires 1 [4,] 0.77779571 -0.7607391 -0.2539115 [5,] 0.12480246 0.8953586 0.6454113 -##com.oracle.truffle.r.test.builtins.TestBuiltin_sinpi.testsin6#Ignored.Unimplemented# +##com.oracle.truffle.r.test.builtins.TestBuiltin_sinpi.testsin6# #argv <- list(c(-0.560475646552213-0.710406563699301i, -0.23017748948328+0.25688370915653i, 1.55870831414912-0.24669187846237i, 0.070508391424576-0.347542599397733i, 0.129287735160946-0.951618567265016i, 1.71506498688328-0.04502772480892i, 0.460916205989202-0.784904469457076i, -1.26506123460653-1.66794193658814i, -0.686852851893526-0.380226520287762i, -0.445661970099958+0.918996609060766i, 1.22408179743946-0.57534696260839i, 0.359813827057364+0.607964322225033i, 0.40077145059405-1.61788270828916i, 0.11068271594512-0.055561965524539i, -0.555841134754075+0.519407203943462i, 1.78691313680308+0.30115336216671i, 0.497850478229239+0.105676194148943i, -1.96661715662964-0.64070600830538i, 0.701355901563686-0.849704346033582i, -0.47279140772793-1.02412879060491i, -1.06782370598685+0.11764659710013i, -0.217974914658295-0.947474614184802i, -1.02600444830724-0.49055744370067i, -0.72889122929114-0.256092192198247i, -0.62503926784926+1.84386200523221i, -1.68669331074241-0.65194990169546i, 0.837787044494525+0.235386572284857i, 0.153373117836515+0.077960849563711i, -1.13813693701195-0.96185663413013i, 1.25381492106993-0.0713080861236i, 0.42646422147681+1.44455085842335i, -0.295071482992271+0.451504053079215i, 0.895125661045022+0.04123292199294i, 0.878133487533042-0.422496832339625i, 0.82158108163749-2.05324722154052i, 0.68864025410009+1.13133721341418i, 0.55391765353759-1.46064007092482i, -0.061911710576722+0.739947510877334i, -0.30596266373992+1.90910356921748i, -0.38047100101238-1.4438931609718i, -0.694706978920513+0.701784335374711i, -0.207917278019599-0.262197489402468i, -1.26539635156826-1.57214415914549i, 2.16895596533851-1.51466765378175i, 1.20796199830499-1.60153617357459i, -1.12310858320335-0.5309065221703i, -0.40288483529908-1.4617555849959i, -0.466655353623219+0.687916772975828i, 0.77996511833632+2.10010894052567i, -0.08336906647183-1.28703047603518i, 0.253318513994755+0.787738847475178i, -0.028546755348703+0.76904224100091i, -0.042870457291316+0.332202578950118i, 1.36860228401446-1.00837660827701i, -0.225770985659268-0.119452606630659i, 1.51647060442954-0.28039533517025i, -1.54875280423022+0.56298953322048i, 0.584613749636069-0.372438756103829i, 0.123854243844614+0.976973386685621i, 0.215941568743973-0.374580857767014i, 0.37963948275988+1.05271146557933i, -0.5023234531093-1.04917700666607i, -0.33320738366942-1.26015524475811i, -1.01857538310709+3.2410399349424i, -1.07179122647558-0.41685758816043i, 0.303528641404258+0.298227591540715i, 0.448209778629426+0.636569674033849i, 0.053004226730504-0.483780625708744i, 0.922267467879738+0.516862044313609i, 2.05008468562714+0.36896452738509i, -0.491031166056535-0.215380507641693i, -2.30916887564081+0.06529303352532i, 1.00573852446226-0.03406725373846i, -0.70920076258239+2.12845189901618i, -0.688008616467358-0.741336096272828i, 1.0255713696967-1.09599626707466i, -0.284773007051009+0.037788399171079i, -1.22071771225454+0.31048074944314i, 0.18130347974915+0.436523478910183i, -0.138891362439045-0.458365332711106i, 0.00576418589989-1.06332613397119i, 0.38528040112633+1.26318517608949i, -0.370660031792409-0.349650387953555i, 0.644376548518833-0.865512862653374i, -0.220486561818751-0.236279568941097i, 0.331781963915697-0.197175894348552i, 1.09683901314935+1.10992028971364i, 0.435181490833803+0.084737292197196i, -0.325931585531227+0.754053785184521i, 1.14880761845109-0.49929201717226i, 0.993503855962119+0.214445309581601i, 0.54839695950807-0.324685911490835i, 0.238731735111441+0.094583528173571i, -0.627906076039371-0.895363357977542i, 1.36065244853001-1.31080153332797i, -0.60025958714713+1.99721338474797i, 2.18733299301658+0.60070882367242i, 1.53261062618519-1.25127136162494i, -0.235700359100477-0.611165916680421i, -1.02642090030678-1.18548008459731i));sinpi(argv[[1]]); Error in sinpi(argv[[1]]) : unimplemented complex function @@ -82631,6 +82631,46 @@ Error: attempt to use zero-length variable name #{ `` <- 123 } Error: attempt to use zero-length variable name +##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# +#proto <- c(11,11); f <- function() { for (i in 1:2) print(proto[[i]] <- i); proto }; f() +[1] 1 +[1] 2 +[1] 1 2 + +##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# +#proto <- c(11,11); f <- function() { for (i in 1:2) print(proto[[i]] <<- i); proto }; f() +[1] 1 +[1] 2 +[1] 1 2 + +##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# +#proto <- c(11,11); f <- function() { for (i in 1:2) proto[[i]] <- i; proto }; f() +[1] 1 2 + +##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# +#proto <- c(11,11); f <- function() { for (i in 1:2) proto[[i]] <<- i; proto }; f() +[1] 1 2 + +##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# +#proto <- c(11,11); f <- function() { proto <- c(4,5); for (i in 1:2) print(proto[[i]] <- i); proto }; f() +[1] 1 +[1] 2 +[1] 1 2 + +##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# +#proto <- c(11,11); f <- function() { proto <- c(4,5); for (i in 1:2) print(proto[[i]] <<- i); proto }; f() +[1] 1 +[1] 2 +[1] 4 5 + +##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# +#proto <- c(11,11); f <- function() { proto <- c(4,5); for (i in 1:2) proto[[i]] <- i; proto }; f() +[1] 1 2 + +##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# +#proto <- c(11,11); f <- function() { proto <- c(4,5); for (i in 1:2) proto[[i]] <<- i; proto }; f() +[1] 4 5 + ##com.oracle.truffle.r.test.library.base.TestSimpleAssignment.testMisc# #{ `f<-` <- function(x, y=42, value) { x[1]<-value+y; x }; y<-1:10; f(y)<-7; y } [1] 49 2 3 4 5 6 7 8 9 10 diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_anyDuplicated.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_anyDuplicated.java index c341da371c863d86f83700e7f625222080c9d22e..c71d8d2f225dc049e5f5b105c71e03ff14076360 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_anyDuplicated.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_anyDuplicated.java @@ -99,10 +99,7 @@ public class TestBuiltin_anyDuplicated extends TestBase { @Test public void testanyDuplicated18() { - // FIXME RInternalError: java.lang.ArrayIndexOutOfBoundsException: 0 - assertEval(Ignored.ImplementationError, - "argv <- structure(list(x = structure(c(3, 2, 7, 2, 6, 2, 7, 2), .Dim = c(4L, 2L), .Dimnames = list(c('A', 'B', 'C', 'D'), c('M', 'F'))), MARGIN = 0), .Names = c('x', 'MARGIN'));" + - "do.call('anyDuplicated', argv)"); + assertEval("argv <- structure(list(x = structure(c(3, 2, 7, 2, 6, 2, 7, 2), .Dim = c(4L, 2L), .Dimnames = list(c('A', 'B', 'C', 'D'), c('M', 'F'))), MARGIN = 0), .Names = c('x', 'MARGIN'));do.call('anyDuplicated', argv)"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_anyDuplicatedmatrix.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_anyDuplicatedmatrix.java index 431b920e047a30de4e9b6c8d9852d7ece22d202f..5b96ccfd74992d64d2247cc9b4cb749c8c56840d 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_anyDuplicatedmatrix.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_anyDuplicatedmatrix.java @@ -20,9 +20,7 @@ public class TestBuiltin_anyDuplicatedmatrix extends TestBase { @Test public void testanyDuplicatedmatrix1() { - // FIXME RInternalError: java.lang.ArrayIndexOutOfBoundsException: 0 - assertEval(Ignored.ImplementationError, - "argv <- structure(list(x = structure(c(3, 2, 7, 2, 6, 2, 7, 2), .Dim = c(4L, 2L), .Dimnames = list(c('A', 'B', 'C', 'D'), c('M', 'F'))), MARGIN = 0), .Names = c('x', 'MARGIN'));" + - "do.call('anyDuplicated.matrix', argv)"); + assertEval("argv <- structure(list(x = structure(c(3, 2, 7, 2, 6, 2, 7, 2), .Dim = c(4L, 2L), .Dimnames = list(c('A', 'B', 'C', 'D'), c('M', 'F'))), MARGIN = 0), .Names = c('x', 'MARGIN'));" + + "do.call('anyDuplicated.matrix', argv)"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_operators.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_operators.java index 63d1eb580265a07e67d39700cb150a9ecd5d187d..c37823ed8171ddb1df5fd91911597ce6c04bd992 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_operators.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_operators.java @@ -701,11 +701,7 @@ public class TestBuiltin_operators extends TestBase { @Test public void testoperators130() { - // FIXME - // Expected output: [1] TRUE - // FastR output: Error in argv[[1]] == argv[[2]] : - // operations are possible only for numeric, logical or complex types - assertEval(Ignored.ImplementationError, "argv <- list(2, structure(list(2L), class = structure('L', package = '.GlobalEnv')));`==`(argv[[1]],argv[[2]]);"); + assertEval("argv <- list(2, structure(list(2L), class = structure('L', package = '.GlobalEnv')));`==`(argv[[1]],argv[[2]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_prod.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_prod.java index 836bf949acab8989f002d851f62808efe117080b..26d8221b69e8d54e9c7dd56a299611135679105f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_prod.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_prod.java @@ -39,9 +39,7 @@ public class TestBuiltin_prod extends TestBase { @Test public void testprod5() { - // FIXME ArrayIndexOutOfBoundsException: 0 - // com.oracle.truffle.r.runtime.data.RIntVector.getDataAt(RIntVector.java:75) - assertEval(Ignored.ImplementationError, "argv <- list(integer(0));prod(argv[[1]]);"); + assertEval("argv <- list(integer(0));prod(argv[[1]]);"); } @Test @@ -72,9 +70,7 @@ public class TestBuiltin_prod extends TestBase { @Test public void testprod11() { - // FIXME ArrayIndexOutOfBoundsException: 0 - // com.oracle.truffle.r.runtime.data.RIntVector.getDataAt(RIntVector.java:75) - assertEval(Ignored.ImplementationError, "argv <- list(numeric(0));prod(argv[[1]]);"); + assertEval("argv <- list(numeric(0));prod(argv[[1]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sinpi.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sinpi.java index 9669b73fb210cfe8b7a9a251b72c22908f0f03e5..25ac0d6955ee7c8d008f30eb2367fe61759b926d 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sinpi.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sinpi.java @@ -56,8 +56,7 @@ public class TestBuiltin_sinpi extends TestBase { @Test public void testsin6() { - assertEval(Ignored.Unimplemented, - "argv <- list(c(-0.560475646552213-0.710406563699301i, -0.23017748948328+0.25688370915653i, 1.55870831414912-0.24669187846237i, 0.070508391424576-0.347542599397733i, 0.129287735160946-0.951618567265016i, 1.71506498688328-0.04502772480892i, 0.460916205989202-0.784904469457076i, -1.26506123460653-1.66794193658814i, -0.686852851893526-0.380226520287762i, -0.445661970099958+0.918996609060766i, 1.22408179743946-0.57534696260839i, 0.359813827057364+0.607964322225033i, 0.40077145059405-1.61788270828916i, 0.11068271594512-0.055561965524539i, -0.555841134754075+0.519407203943462i, 1.78691313680308+0.30115336216671i, 0.497850478229239+0.105676194148943i, -1.96661715662964-0.64070600830538i, 0.701355901563686-0.849704346033582i, -0.47279140772793-1.02412879060491i, -1.06782370598685+0.11764659710013i, -0.217974914658295-0.947474614184802i, -1.02600444830724-0.49055744370067i, -0.72889122929114-0.256092192198247i, -0.62503926784926+1.84386200523221i, -1.68669331074241-0.65194990169546i, 0.837787044494525+0.235386572284857i, 0.153373117836515+0.077960849563711i, -1.13813693701195-0.96185663413013i, 1.25381492106993-0.0713080861236i, 0.42646422147681+1.44455085842335i, -0.295071482992271+0.451504053079215i, 0.895125661045022+0.04123292199294i, 0.878133487533042-0.422496832339625i, 0.82158108163749-2.05324722154052i, 0.68864025410009+1.13133721341418i, 0.55391765353759-1.46064007092482i, -0.061911710576722+0.739947510877334i, -0.30596266373992+1.90910356921748i, -0.38047100101238-1.4438931609718i, -0.694706978920513+0.701784335374711i, -0.207917278019599-0.262197489402468i, -1.26539635156826-1.57214415914549i, 2.16895596533851-1.51466765378175i, 1.20796199830499-1.60153617357459i, -1.12310858320335-0.5309065221703i, -0.40288483529908-1.4617555849959i, -0.466655353623219+0.687916772975828i, 0.77996511833632+2.10010894052567i, -0.08336906647183-1.28703047603518i, 0.253318513994755+0.787738847475178i, -0.028546755348703+0.76904224100091i, -0.042870457291316+0.332202578950118i, 1.36860228401446-1.00837660827701i, -0.225770985659268-0.119452606630659i, 1.51647060442954-0.28039533517025i, -1.54875280423022+0.56298953322048i, 0.584613749636069-0.372438756103829i, 0.123854243844614+0.976973386685621i, 0.215941568743973-0.374580857767014i, 0.37963948275988+1.05271146557933i, -0.5023234531093-1.04917700666607i, -0.33320738366942-1.26015524475811i, -1.01857538310709+3.2410399349424i, -1.07179122647558-0.41685758816043i, 0.303528641404258+0.298227591540715i, 0.448209778629426+0.636569674033849i, 0.053004226730504-0.483780625708744i, 0.922267467879738+0.516862044313609i, 2.05008468562714+0.36896452738509i, -0.491031166056535-0.215380507641693i, -2.30916887564081+0.06529303352532i, 1.00573852446226-0.03406725373846i, -0.70920076258239+2.12845189901618i, -0.688008616467358-0.741336096272828i, 1.0255713696967-1.09599626707466i, -0.284773007051009+0.037788399171079i, -1.22071771225454+0.31048074944314i, 0.18130347974915+0.436523478910183i, -0.138891362439045-0.458365332711106i, 0.00576418589989-1.06332613397119i, 0.38528040112633+1.26318517608949i, -0.370660031792409-0.349650387953555i, 0.644376548518833-0.865512862653374i, -0.220486561818751-0.236279568941097i, 0.331781963915697-0.197175894348552i, 1.09683901314935+1.10992028971364i, 0.435181490833803+0.084737292197196i, -0.325931585531227+0.754053785184521i, 1.14880761845109-0.49929201717226i, 0.993503855962119+0.214445309581601i, 0.54839695950807-0.324685911490835i, 0.238731735111441+0.094583528173571i, -0.627906076039371-0.895363357977542i, 1.36065244853001-1.31080153332797i, -0.60025958714713+1.99721338474797i, 2.18733299301658+0.60070882367242i, 1.53261062618519-1.25127136162494i, -0.235700359100477-0.611165916680421i, -1.02642090030678-1.18548008459731i));sinpi(argv[[1]]);"); + assertEval("argv <- list(c(-0.560475646552213-0.710406563699301i, -0.23017748948328+0.25688370915653i, 1.55870831414912-0.24669187846237i, 0.070508391424576-0.347542599397733i, 0.129287735160946-0.951618567265016i, 1.71506498688328-0.04502772480892i, 0.460916205989202-0.784904469457076i, -1.26506123460653-1.66794193658814i, -0.686852851893526-0.380226520287762i, -0.445661970099958+0.918996609060766i, 1.22408179743946-0.57534696260839i, 0.359813827057364+0.607964322225033i, 0.40077145059405-1.61788270828916i, 0.11068271594512-0.055561965524539i, -0.555841134754075+0.519407203943462i, 1.78691313680308+0.30115336216671i, 0.497850478229239+0.105676194148943i, -1.96661715662964-0.64070600830538i, 0.701355901563686-0.849704346033582i, -0.47279140772793-1.02412879060491i, -1.06782370598685+0.11764659710013i, -0.217974914658295-0.947474614184802i, -1.02600444830724-0.49055744370067i, -0.72889122929114-0.256092192198247i, -0.62503926784926+1.84386200523221i, -1.68669331074241-0.65194990169546i, 0.837787044494525+0.235386572284857i, 0.153373117836515+0.077960849563711i, -1.13813693701195-0.96185663413013i, 1.25381492106993-0.0713080861236i, 0.42646422147681+1.44455085842335i, -0.295071482992271+0.451504053079215i, 0.895125661045022+0.04123292199294i, 0.878133487533042-0.422496832339625i, 0.82158108163749-2.05324722154052i, 0.68864025410009+1.13133721341418i, 0.55391765353759-1.46064007092482i, -0.061911710576722+0.739947510877334i, -0.30596266373992+1.90910356921748i, -0.38047100101238-1.4438931609718i, -0.694706978920513+0.701784335374711i, -0.207917278019599-0.262197489402468i, -1.26539635156826-1.57214415914549i, 2.16895596533851-1.51466765378175i, 1.20796199830499-1.60153617357459i, -1.12310858320335-0.5309065221703i, -0.40288483529908-1.4617555849959i, -0.466655353623219+0.687916772975828i, 0.77996511833632+2.10010894052567i, -0.08336906647183-1.28703047603518i, 0.253318513994755+0.787738847475178i, -0.028546755348703+0.76904224100091i, -0.042870457291316+0.332202578950118i, 1.36860228401446-1.00837660827701i, -0.225770985659268-0.119452606630659i, 1.51647060442954-0.28039533517025i, -1.54875280423022+0.56298953322048i, 0.584613749636069-0.372438756103829i, 0.123854243844614+0.976973386685621i, 0.215941568743973-0.374580857767014i, 0.37963948275988+1.05271146557933i, -0.5023234531093-1.04917700666607i, -0.33320738366942-1.26015524475811i, -1.01857538310709+3.2410399349424i, -1.07179122647558-0.41685758816043i, 0.303528641404258+0.298227591540715i, 0.448209778629426+0.636569674033849i, 0.053004226730504-0.483780625708744i, 0.922267467879738+0.516862044313609i, 2.05008468562714+0.36896452738509i, -0.491031166056535-0.215380507641693i, -2.30916887564081+0.06529303352532i, 1.00573852446226-0.03406725373846i, -0.70920076258239+2.12845189901618i, -0.688008616467358-0.741336096272828i, 1.0255713696967-1.09599626707466i, -0.284773007051009+0.037788399171079i, -1.22071771225454+0.31048074944314i, 0.18130347974915+0.436523478910183i, -0.138891362439045-0.458365332711106i, 0.00576418589989-1.06332613397119i, 0.38528040112633+1.26318517608949i, -0.370660031792409-0.349650387953555i, 0.644376548518833-0.865512862653374i, -0.220486561818751-0.236279568941097i, 0.331781963915697-0.197175894348552i, 1.09683901314935+1.10992028971364i, 0.435181490833803+0.084737292197196i, -0.325931585531227+0.754053785184521i, 1.14880761845109-0.49929201717226i, 0.993503855962119+0.214445309581601i, 0.54839695950807-0.324685911490835i, 0.238731735111441+0.094583528173571i, -0.627906076039371-0.895363357977542i, 1.36065244853001-1.31080153332797i, -0.60025958714713+1.99721338474797i, 2.18733299301658+0.60070882367242i, 1.53261062618519-1.25127136162494i, -0.235700359100477-0.611165916680421i, -1.02642090030678-1.18548008459731i));sinpi(argv[[1]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleAssignment.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleAssignment.java index fe48ffd5e21ce2303ac0682f1f4ea44c84b4f40c..b775649fd5aacf44a8ecb210ab33419fe40e2bee 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleAssignment.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleAssignment.java @@ -4,7 +4,7 @@ * http://www.gnu.org/licenses/gpl-2.0.html * * Copyright (c) 2012-2014, Purdue University - * Copyright (c) 2013, 2016, Oracle and/or its affiliates + * Copyright (c) 2013, 2017, Oracle and/or its affiliates * * All rights reserved. */ @@ -111,5 +111,14 @@ public class TestSimpleAssignment extends TestBase { assertEval("{ f <- function() { if (FALSE) { x <- 1 } ; g <- function() { x } ; g() } ; f() }"); assertEval("{ f <- function() { if (FALSE) { c <- 1 } ; g <- function() { c } ; g() } ; typeof(f()) }"); assertEval("{ `f<-` <- function(x, y=42, value) { x[1]<-value+y; x }; y<-1:10; f(y)<-7; y }"); + + assertEval("proto <- c(11,11); f <- function() { for (i in 1:2) proto[[i]] <- i; proto }; f()"); + assertEval("proto <- c(11,11); f <- function() { for (i in 1:2) print(proto[[i]] <- i); proto }; f()"); + assertEval("proto <- c(11,11); f <- function() { proto <- c(4,5); for (i in 1:2) proto[[i]] <- i; proto }; f()"); + assertEval("proto <- c(11,11); f <- function() { proto <- c(4,5); for (i in 1:2) print(proto[[i]] <- i); proto }; f()"); + assertEval("proto <- c(11,11); f <- function() { for (i in 1:2) proto[[i]] <<- i; proto }; f()"); + assertEval("proto <- c(11,11); f <- function() { for (i in 1:2) print(proto[[i]] <<- i); proto }; f()"); + assertEval("proto <- c(11,11); f <- function() { proto <- c(4,5); for (i in 1:2) proto[[i]] <<- i; proto }; f()"); + assertEval("proto <- c(11,11); f <- function() { proto <- c(4,5); for (i in 1:2) print(proto[[i]] <<- i); proto }; f()"); } }