diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java index 67a40b01db27b285d175d42e2532dd33feeaeea5..f562660aa447ba3864aa315eaa7a30046b2fcbc6 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java @@ -45,6 +45,7 @@ import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.r.ffi.impl.upcalls.UpCallsRFFI; +import com.oracle.truffle.r.ffi.processor.RFFICstring; import com.oracle.truffle.r.nodes.RASTUtils; import com.oracle.truffle.r.nodes.function.ClassHierarchyNode; import com.oracle.truffle.r.runtime.RArguments; @@ -555,6 +556,21 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { throw RInternalError.shouldNotReachHere(); } + @Override + public void SETLEVELS(Object x, int gpbits) { + if (x instanceof RTypedValue) { + ((RTypedValue) x).setGPBits(gpbits); + } else { + throw RInternalError.shouldNotReachHere(); + } + } + + @Override + @TruffleBoundary + public int Rf_isObject(Object x) { + throw implementedAsNode(); + } + @Override public void SET_STRING_ELT(Object x, long i, Object v) { RStringVector vector = guaranteeInstanceOf(x, RStringVector.class); @@ -1006,6 +1022,14 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { return result; } + @Override + @TruffleBoundary + public void SET_ENCLOS(Object x, Object enc) { + REnvironment env = guaranteeInstanceOf(x, REnvironment.class); + REnvironment enclosing = guaranteeInstanceOf(enc, REnvironment.class); + env.setParent(enclosing); + } + @Override public Object PRVALUE(Object x) { RPromise p = guaranteeInstanceOf(x, RPromise.class); @@ -2369,6 +2393,16 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { throw implementedAsNode(); } + @Override + public int R_nchar(@RFFICstring Object string, int type, int allowNA, int keepNA, @RFFICstring Object msgName) { + throw implementedAsNode(); + } + + @Override + public Object R_forceAndCall(Object e, Object f, int n, Object args) { + throw implementedAsNode(); + } + private static TruffleObject guaranteeVectorOrNull(Object obj, Class<? extends TruffleObject> clazz) { if (obj == RNull.instance) { return RNull.instance; diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/IsObjectNode.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/IsObjectNode.java new file mode 100644 index 0000000000000000000000000000000000000000..42f7b9246107a8d352f9b3c60573c9fcc0e438ab --- /dev/null +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/IsObjectNode.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018, 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 3 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 3 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 + * 3 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.ffi.impl.nodes; + +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.GetClassAttributeNode; +import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctionsFactory.GetClassAttributeNodeGen; +import com.oracle.truffle.r.runtime.data.RAttributable; +import com.oracle.truffle.r.runtime.nodes.RBaseNode; + +public abstract class IsObjectNode extends RBaseNode { + + public static IsObjectNode create() { + return IsObjectNodeGen.create(); + } + + @Child private GetClassAttributeNode getClassAttrNode = GetClassAttributeNodeGen.create(); + + public abstract int executeObject(Object x); + + @Specialization + int isObject(RAttributable x) { + return getClassAttrNode.isObject(x) ? 1 : 0; + } + +} diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MatchNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MatchNodes.java index 5a525bfac1d121cd21bfa47e572e8ec0c5c3420a..ff43e188084890727f3d94beb9fb6212507e8329 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MatchNodes.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MatchNodes.java @@ -32,6 +32,7 @@ import com.oracle.truffle.r.runtime.RError; import static com.oracle.truffle.r.runtime.RError.Message.MATCH_VECTOR_ARGS; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.data.CharSXPWrapper; import com.oracle.truffle.r.runtime.data.RTypes; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; @@ -71,6 +72,14 @@ public final class MatchNodes { return RRuntime.asLogical(s.getDataAt(0).equals(t.getDataAt(0))); } + @Specialization + Object match(CharSXPWrapper s, CharSXPWrapper t) { + if (s.getContents() == RRuntime.STRING_NA || t.getContents() == RRuntime.STRING_NA) { + return RRuntime.LOGICAL_FALSE; + } + return RRuntime.asLogical(s.getContents().equals(t.getContents())); + } + @Fallback @SuppressWarnings("unused") Object match(Object s, Object t) { diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RForceAndCallNode.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RForceAndCallNode.java new file mode 100644 index 0000000000000000000000000000000000000000..1f930fe7c9fe56c34a494c846399fdf76eb621fb --- /dev/null +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RForceAndCallNode.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2018, 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 3 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 3 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 + * 3 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.ffi.impl.nodes; + +import java.util.LinkedList; +import java.util.List; + +import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.nodes.ExplodeLoop; +import com.oracle.truffle.r.nodes.InlineCacheNode; +import com.oracle.truffle.r.nodes.InlineCacheNodeGen; +import com.oracle.truffle.r.nodes.function.PromiseHelperNode; +import com.oracle.truffle.r.nodes.function.RCallerHelper; +import com.oracle.truffle.r.runtime.ArgumentsSignature; +import com.oracle.truffle.r.runtime.RCaller; +import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.context.RContext; +import com.oracle.truffle.r.runtime.data.Closure; +import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; +import com.oracle.truffle.r.runtime.data.RDataFactory; +import com.oracle.truffle.r.runtime.data.RFunction; +import com.oracle.truffle.r.runtime.data.RNull; +import com.oracle.truffle.r.runtime.data.RPairList; +import com.oracle.truffle.r.runtime.data.RPromise; +import com.oracle.truffle.r.runtime.data.RSymbol; +import com.oracle.truffle.r.runtime.env.REnvironment; +import com.oracle.truffle.r.runtime.gnur.SEXPTYPE; +import com.oracle.truffle.r.runtime.nodes.RBaseNode; + +public abstract class RForceAndCallNode extends RBaseNode { + + public static RForceAndCallNode create() { + return RForceAndCallNodeGen.create(); + } + + @Child private InlineCacheNode closureEvalNode = InlineCacheNodeGen.create(10); + @Child private PromiseHelperNode promiseHelper = new PromiseHelperNode(); + + public abstract Object executeObject(Object e, Object f, int n, Object env); + + @Specialization + Object forceAndCall(Object e, RFunction fun, int n, REnvironment env) { + Object el = ((RPairList) e).cdr(); + List<Object> argValues = new LinkedList<>(); + RArgsValuesAndNames dotArgs = null; + while (el != RNull.instance) { + assert el instanceof RPairList; + Object arg = ((RPairList) el).car(); + Object argVal = null; + if (arg instanceof RSymbol) { + Object a = env.get(((RSymbol) arg).getName()); + if (a instanceof RArgsValuesAndNames) { + dotArgs = (RArgsValuesAndNames) a; + } else { + argVal = a; + } + + } else if (arg instanceof RPairList) { + RPairList argPL = (RPairList) arg; + argPL = RDataFactory.createPairList(argPL.car(), argPL.cdr(), argPL.getTag(), SEXPTYPE.LANGSXP); + final Closure argClosure = argPL.getClosure(); + argVal = closureEvalNode.execute(env.getFrame(), argClosure); + } + if (argVal != null) { + argValues.add(argVal); + } + el = ((RPairList) el).cdr(); + } + + final RArgsValuesAndNames argsAndNames; + if (dotArgs == null) { + argsAndNames = new RArgsValuesAndNames(argValues.toArray(), ArgumentsSignature.empty(argValues.size())); + } else { + argsAndNames = createArgsAndNames(argValues, dotArgs); + } + + if (!fun.isBuiltin()) { + flattenFirstArgs(env.getFrame(), n, argsAndNames); + } + + RCaller rCaller = RCaller.create(env.getFrame(), RCallerHelper.createFromArguments(fun, argsAndNames)); + return RContext.getEngine().evalFunction(fun, env.getFrame(), rCaller, false, argsAndNames.getSignature(), argsAndNames.getArguments()); + } + + private static RArgsValuesAndNames createArgsAndNames(List<Object> argValues, RArgsValuesAndNames dotArgs) { + final RArgsValuesAndNames argsAndNames; + Object[] argValuesEx = new Object[argValues.size() + dotArgs.getLength()]; + String[] argNamesEx = new String[argValues.size() + dotArgs.getLength()]; + System.arraycopy(argValues.toArray(), 0, argValuesEx, 0, argValues.size()); + System.arraycopy(dotArgs.getArguments(), 0, argValuesEx, argValues.size(), dotArgs.getLength()); + final String[] argNames = dotArgs.getSignature().getNames(); + if (argNames != null) { + System.arraycopy(argNames, 0, argNamesEx, argValues.size(), dotArgs.getLength()); + } + argsAndNames = new RArgsValuesAndNames(argValuesEx, ArgumentsSignature.get(argNamesEx)); + return argsAndNames; + } + + @ExplodeLoop + private void flattenFirstArgs(VirtualFrame frame, int n, RArgsValuesAndNames args) { + if (promiseHelper == null) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + promiseHelper = insert(new PromiseHelperNode()); + } + // In GnuR there appears to be no error checks on n > args.length + if (args.getLength() < n) { + CompilerDirectives.transferToInterpreter(); + throw RError.nyi(this, "callAndForce with insufficient arguments"); + } + for (int i = 0; i < n; i++) { + Object arg = args.getArgument(i); + if (arg instanceof RArgsValuesAndNames) { + CompilerDirectives.transferToInterpreter(); + throw RError.nyi(this, "callAndForce trying to force varargs"); + } + if (arg instanceof RPromise) { + promiseHelper.evaluate(frame, (RPromise) arg); + } + } + } + +} diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RNCharNode.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RNCharNode.java new file mode 100644 index 0000000000000000000000000000000000000000..651696fc20eba02b9702fc7d1019b7954f70ab43 --- /dev/null +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RNCharNode.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018, 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 3 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 3 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 + * 3 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.ffi.impl.nodes; + +import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.runtime.RRuntime; + +public abstract class RNCharNode extends FFIUpCallNode.Arg5 { + + public static RNCharNode create() { + return RNCharNodeGen.create(); + } + + private static boolean isNAKeptIn(int keepNAInArg, int typeId) { + if (RRuntime.isNA(keepNAInArg)) { + return typeId != 2; + } else { + return keepNAInArg == RRuntime.LOGICAL_TRUE; + } + } + + @Specialization + int handleString(String x, int type, @SuppressWarnings("unused") int allowNA, int keepNAIn, @SuppressWarnings("unused") String msgName, + @Cached("createBinaryProfile()") ConditionProfile keepNAProfile) { + boolean keepNA = keepNAProfile.profile(isNAKeptIn(keepNAIn, type)); + int result; + if (RRuntime.isNA(x)) { + result = keepNA ? RRuntime.INT_NA : 2; + } else { + result = x.length(); + } + + return result; + } +} diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java index 63c66d9a30d0935977d643cb7e2493f918e0ebf7..3fcf299653c409eee4b3620ba4d4fed000b241e8 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java @@ -41,6 +41,7 @@ import com.oracle.truffle.r.ffi.impl.nodes.DuplicateNodes.RfAnyDuplicated3; import com.oracle.truffle.r.ffi.impl.nodes.EnvNodes.LockBindingNode; import com.oracle.truffle.r.ffi.impl.nodes.EnvNodes.UnlockBindingNode; import com.oracle.truffle.r.ffi.impl.nodes.GetClassDefNode; +import com.oracle.truffle.r.ffi.impl.nodes.IsObjectNode; import com.oracle.truffle.r.ffi.impl.nodes.ListAccessNodes.CAARNode; import com.oracle.truffle.r.ffi.impl.nodes.ListAccessNodes.CAD4RNode; import com.oracle.truffle.r.ffi.impl.nodes.ListAccessNodes.CADDDRNode; @@ -61,9 +62,11 @@ import com.oracle.truffle.r.ffi.impl.nodes.MathFunctionsNodes; import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes; import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes.LENGTHNode; import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes.SetObjectNode; +import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes.TRUELENGTHNode; import com.oracle.truffle.r.ffi.impl.nodes.NewCustomConnectionNode; +import com.oracle.truffle.r.ffi.impl.nodes.RForceAndCallNode; import com.oracle.truffle.r.ffi.impl.nodes.RMakeExternalPtrNode; -import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes.TRUELENGTHNode; +import com.oracle.truffle.r.ffi.impl.nodes.RNCharNode; import com.oracle.truffle.r.ffi.impl.nodes.RandFunctionsNodes; import com.oracle.truffle.r.ffi.impl.nodes.RfEvalNode; import com.oracle.truffle.r.ffi.impl.nodes.Str2TypeNode; @@ -257,6 +260,8 @@ public interface StdUpCallsRFFI { int LEVELS(Object x); + void SETLEVELS(Object x, int gpbits); + void SET_VECTOR_ELT(Object x, long i, Object v); @RFFIUpCallNode(SetAttribNode.class) @@ -421,6 +426,8 @@ public interface StdUpCallsRFFI { Object ENCLOS(Object x); + void SET_ENCLOS(Object x, Object enc); + Object PRVALUE(Object x); Object R_ParseVector(Object text, int n, Object srcFile); @@ -908,4 +915,13 @@ public interface StdUpCallsRFFI { @RFFIUpCallNode(MiscNodes.RfPrintValueNode.class) void Rf_PrintValue(Object value); + + @RFFIUpCallNode(RNCharNode.class) + int R_nchar(@RFFICstring Object string, int type, int allowNA, int keepNA, @RFFICstring Object msgName); + + @RFFIUpCallNode(RForceAndCallNode.class) + Object R_forceAndCall(Object e, Object f, int n, Object args); + + @RFFIUpCallNode(IsObjectNode.class) + int Rf_isObject(Object x); } diff --git a/com.oracle.truffle.r.ffi.processor/src/com/oracle/truffle/r/ffi/processor/FFIProcessor.java b/com.oracle.truffle.r.ffi.processor/src/com/oracle/truffle/r/ffi/processor/FFIProcessor.java index ebf2d99ceae30e248f769ab94c685ec700a14c40..e946432cd5f2c37e84602b8b03bce5b8951e129d 100644 --- a/com.oracle.truffle.r.ffi.processor/src/com/oracle/truffle/r/ffi/processor/FFIProcessor.java +++ b/com.oracle.truffle.r.ffi.processor/src/com/oracle/truffle/r/ffi/processor/FFIProcessor.java @@ -149,6 +149,7 @@ public final class FFIProcessor extends AbstractProcessor { String canRunGc = m.getAnnotation(RFFIRunGC.class) == null ? "false" : "true"; String nodeClassName = null; TypeElement nodeClass = null; + boolean useFrame = false; String functionClassName = null; TypeElement functionClass = null; if (nodeAnnotation != null) { @@ -276,7 +277,16 @@ public final class FFIProcessor extends AbstractProcessor { for (Element element : nodeClass.getEnclosedElements()) { if (element.getKind() == ElementKind.METHOD && element.getModifiers().contains(Modifier.STATIC) && "create".equals(element.getSimpleName().toString())) { createFunction = true; - break; + } + if (element.getKind() == ElementKind.METHOD && element.getModifiers().contains(Modifier.ABSTRACT) && "executeObject".equals(element.getSimpleName().toString())) { + final List<? extends VariableElement> parameters = ((ExecutableElement) element).getParameters(); + if (!parameters.isEmpty()) { + final VariableElement first = parameters.get(0); + final TypeMirror parType = first.asType(); + if (parType.toString().equals("com.oracle.truffle.api.frame.VirtualFrame")) { + useFrame = true; + } + } } } if (createFunction) { @@ -326,7 +336,11 @@ public final class FFIProcessor extends AbstractProcessor { } else { w.append("((" + callName + ") ForeignAccess.getReceiver(frame)).upCallsImpl." + name); } - w.append("(" + arguments + ")"); + w.append("("); + if (useFrame) { + w.append("frame, "); + } + w.append(arguments).append(")"); if (needsReturnWrap) { w.append(");\n"); } else { diff --git a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h index e900136b91a89ea457e05f35c298f149b91bcbd7..68e849869fa823349b0484e9203867c86dbaf182 100644 --- a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h +++ b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h @@ -228,7 +228,7 @@ typedef double (*call_R_atof)(const char *str); typedef double (*call_R_strtod)(const char *c, char **end); typedef SEXP (*call_R_PromiseExpr)(SEXP x); typedef SEXP (*call_R_ClosureExpr)(SEXP x); -typedef SEXP (*call_R_forceAndCall)(SEXP e, int n, SEXP rho); +typedef SEXP (*call_R_forceAndCall)(SEXP e, SEXP f, int n, SEXP rho); typedef SEXP (*call_R_MakeExternalPtr)(void *p, SEXP tag, SEXP prot); typedef void *(*call_R_ExternalPtrAddr)(SEXP s); typedef SEXP (*call_R_ExternalPtrTag)(SEXP s); @@ -408,6 +408,7 @@ typedef SEXP (*call_getvar)(); typedef SEXP (*call_R_ParseVector)(SEXP text, int n, SEXP srcFile); typedef SEXPTYPE (*call_Rf_str2type)(const char *s); typedef SEXP (*call_octsize)(SEXP size); +typedef int (*call_R_nchar)(SEXP string, nchar_type type_, Rboolean allowNA, Rboolean keepNA, const char* msg_name); // connections diff --git a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h index efa5006b8a82b1496c3d88fdbc97ba5f16fdf837..6408fc8132a33f3037766adbbb8764bd6df9fdb3 100644 --- a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h +++ b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h @@ -79,249 +79,254 @@ #define R_do_new_object_x 73 #define R_do_slot_x 74 #define R_do_slot_assign_x 75 -#define R_getClassDef_x 76 -#define R_getContextCall_x 77 -#define R_getContextEnv_x 78 -#define R_getContextFun_x 79 -#define R_getContextSrcRef_x 80 -#define R_getGlobalFunctionContext_x 81 -#define R_getParentFunctionContext_x 82 -#define R_has_slot_x 83 -#define R_insideBrowser_x 84 -#define R_isEqual_x 85 -#define R_isGlobal_x 86 -#define R_lsInternal3_x 87 -#define R_new_custom_connection_x 88 -#define R_tryEval_x 89 -#define R_unLockBinding_x 90 -#define Rf_GetOption1_x 91 -#define Rf_NonNullStringMatch_x 92 -#define Rf_PairToVectorList_x 93 -#define Rf_PrintValue_x 94 -#define Rf_ScalarInteger_x 95 -#define Rf_ScalarLogical_x 96 -#define Rf_ScalarReal_x 97 -#define Rf_ScalarString_x 98 -#define Rf_VectorToPairList_x 99 -#define Rf_allocArray_x 100 -#define Rf_allocMatrix_x 101 -#define Rf_allocVector_x 102 -#define Rf_any_duplicated_x 103 -#define Rf_any_duplicated3_x 104 -#define Rf_asChar_x 105 -#define Rf_asCharacterFactor_x 106 -#define Rf_asInteger_x 107 -#define Rf_asLogical_x 108 -#define Rf_asReal_x 109 -#define Rf_bessel_i_x 110 -#define Rf_bessel_i_ex_x 111 -#define Rf_bessel_j_x 112 -#define Rf_bessel_j_ex_x 113 -#define Rf_bessel_k_x 114 -#define Rf_bessel_k_ex_x 115 -#define Rf_bessel_y_x 116 -#define Rf_bessel_y_ex_x 117 -#define Rf_beta_x 118 -#define Rf_choose_x 119 -#define Rf_classgets_x 120 -#define Rf_coerceVector_x 121 -#define Rf_cons_x 122 -#define Rf_copyListMatrix_x 123 -#define Rf_copyMatrix_x 124 -#define Rf_copyMostAttrib_x 125 -#define Rf_cospi_x 126 -#define Rf_dbeta_x 127 -#define Rf_dbinom_x 128 -#define Rf_dcauchy_x 129 -#define Rf_dchisq_x 130 -#define Rf_defineVar_x 131 -#define Rf_dexp_x 132 -#define Rf_df_x 133 -#define Rf_dgamma_x 134 -#define Rf_dgeom_x 135 -#define Rf_dhyper_x 136 -#define Rf_digamma_x 137 -#define Rf_dlnorm_x 138 -#define Rf_dlogis_x 139 -#define Rf_dnbeta_x 140 -#define Rf_dnbinom_x 141 -#define Rf_dnbinom_mu_x 142 -#define Rf_dnchisq_x 143 -#define Rf_dnf_x 144 -#define Rf_dnorm4_x 145 -#define Rf_dnt_x 146 -#define Rf_dpois_x 147 -#define Rf_dpsifn_x 148 -#define Rf_dsignrank_x 149 -#define Rf_dt_x 150 -#define Rf_dunif_x 151 -#define Rf_duplicate_x 152 -#define Rf_dweibull_x 153 -#define Rf_dwilcox_x 154 -#define Rf_error_x 155 -#define Rf_errorcall_x 156 -#define Rf_eval_x 157 -#define Rf_findFun_x 158 -#define Rf_findVar_x 159 -#define Rf_findVarInFrame_x 160 -#define Rf_findVarInFrame3_x 161 -#define Rf_fprec_x 162 -#define Rf_ftrunc_x 163 -#define Rf_gammafn_x 164 -#define Rf_getAttrib_x 165 -#define Rf_gsetVar_x 166 -#define Rf_inherits_x 167 -#define Rf_install_x 168 -#define Rf_installChar_x 169 -#define Rf_isNull_x 170 -#define Rf_isString_x 171 -#define Rf_lbeta_x 172 -#define Rf_lchoose_x 173 -#define Rf_lengthgets_x 174 -#define Rf_lgamma1p_x 175 -#define Rf_lgammafn_x 176 -#define Rf_lgammafn_sign_x 177 -#define Rf_log1pexp_x 178 -#define Rf_log1pmx_x 179 -#define Rf_logspace_add_x 180 -#define Rf_logspace_sub_x 181 -#define Rf_match_x 182 -#define Rf_mkCharLenCE_x 183 -#define Rf_namesgets_x 184 -#define Rf_ncols_x 185 -#define Rf_nrows_x 186 -#define Rf_pbeta_x 187 -#define Rf_pbinom_x 188 -#define Rf_pcauchy_x 189 -#define Rf_pchisq_x 190 -#define Rf_pentagamma_x 191 -#define Rf_pexp_x 192 -#define Rf_pf_x 193 -#define Rf_pgamma_x 194 -#define Rf_pgeom_x 195 -#define Rf_phyper_x 196 -#define Rf_plnorm_x 197 -#define Rf_plogis_x 198 -#define Rf_pnbeta_x 199 -#define Rf_pnbinom_x 200 -#define Rf_pnbinom_mu_x 201 -#define Rf_pnchisq_x 202 -#define Rf_pnf_x 203 -#define Rf_pnorm5_x 204 -#define Rf_pnorm_both_x 205 -#define Rf_pnt_x 206 -#define Rf_ppois_x 207 -#define Rf_protect_x 208 -#define Rf_psigamma_x 209 -#define Rf_psignrank_x 210 -#define Rf_pt_x 211 -#define Rf_ptukey_x 212 -#define Rf_punif_x 213 -#define Rf_pweibull_x 214 -#define Rf_pwilcox_x 215 -#define Rf_qbeta_x 216 -#define Rf_qbinom_x 217 -#define Rf_qcauchy_x 218 -#define Rf_qchisq_x 219 -#define Rf_qexp_x 220 -#define Rf_qf_x 221 -#define Rf_qgamma_x 222 -#define Rf_qgeom_x 223 -#define Rf_qhyper_x 224 -#define Rf_qlnorm_x 225 -#define Rf_qlogis_x 226 -#define Rf_qnbeta_x 227 -#define Rf_qnbinom_x 228 -#define Rf_qnbinom_mu_x 229 -#define Rf_qnchisq_x 230 -#define Rf_qnf_x 231 -#define Rf_qnorm5_x 232 -#define Rf_qnt_x 233 -#define Rf_qpois_x 234 -#define Rf_qsignrank_x 235 -#define Rf_qt_x 236 -#define Rf_qtukey_x 237 -#define Rf_qunif_x 238 -#define Rf_qweibull_x 239 -#define Rf_qwilcox_x 240 -#define Rf_rbeta_x 241 -#define Rf_rbinom_x 242 -#define Rf_rcauchy_x 243 -#define Rf_rchisq_x 244 -#define Rf_rexp_x 245 -#define Rf_rf_x 246 -#define Rf_rgamma_x 247 -#define Rf_rgeom_x 248 -#define Rf_rhyper_x 249 -#define Rf_rlnorm_x 250 -#define Rf_rlogis_x 251 -#define Rf_rmultinom_x 252 -#define Rf_rnbinom_x 253 -#define Rf_rnbinom_mu_x 254 -#define Rf_rnchisq_x 255 -#define Rf_rnorm_x 256 -#define Rf_rpois_x 257 -#define Rf_rsignrank_x 258 -#define Rf_rt_x 259 -#define Rf_runif_x 260 -#define Rf_rweibull_x 261 -#define Rf_rwilcox_x 262 -#define Rf_setAttrib_x 263 -#define Rf_sign_x 264 -#define Rf_sinpi_x 265 -#define Rf_str2type_x 266 -#define Rf_tanpi_x 267 -#define Rf_tetragamma_x 268 -#define Rf_trigamma_x 269 -#define Rf_unprotect_x 270 -#define Rf_unprotect_ptr_x 271 -#define Rf_warning_x 272 -#define Rf_warningcall_x 273 -#define Rprintf_x 274 -#define SETCAD4R_x 275 -#define SETCADDDR_x 276 -#define SETCADDR_x 277 -#define SETCADR_x 278 -#define SETCAR_x 279 -#define SETCDR_x 280 -#define SETLENGTH_x 281 -#define SETTRUELENGTH_x 282 -#define SET_ATTRIB_x 283 -#define SET_BODY_x 284 -#define SET_CLOENV_x 285 -#define SET_FORMALS_x 286 -#define SET_NAMED_FASTR_x 287 -#define SET_OBJECT_x 288 -#define SET_RDEBUG_x 289 -#define SET_RSTEP_x 290 -#define SET_S4_OBJECT_x 291 -#define SET_STRING_ELT_x 292 -#define SET_SYMVALUE_x 293 -#define SET_TAG_x 294 -#define SET_TYPEOF_x 295 -#define SET_VECTOR_ELT_x 296 -#define STRING_ELT_x 297 -#define SYMVALUE_x 298 -#define TAG_x 299 -#define TRUELENGTH_x 300 -#define TYPEOF_x 301 -#define UNSET_S4_OBJECT_x 302 -#define VECTOR_ELT_x 303 -#define forceSymbols_x 304 -#define getCCallable_x 305 -#define getConnectionClassString_x 306 -#define getEmbeddingDLLInfo_x 307 -#define getOpenModeString_x 308 -#define getSummaryDescription_x 309 -#define isSeekable_x 310 -#define octsize_x 311 -#define registerCCallable_x 312 -#define registerRoutines_x 313 -#define restoreHandlerStacks_x 314 -#define setDotSymbolValues_x 315 -#define unif_rand_x 316 -#define useDynamicSymbols_x 317 +#define R_forceAndCall_x 76 +#define R_getClassDef_x 77 +#define R_getContextCall_x 78 +#define R_getContextEnv_x 79 +#define R_getContextFun_x 80 +#define R_getContextSrcRef_x 81 +#define R_getGlobalFunctionContext_x 82 +#define R_getParentFunctionContext_x 83 +#define R_has_slot_x 84 +#define R_insideBrowser_x 85 +#define R_isEqual_x 86 +#define R_isGlobal_x 87 +#define R_lsInternal3_x 88 +#define R_nchar_x 89 +#define R_new_custom_connection_x 90 +#define R_tryEval_x 91 +#define R_unLockBinding_x 92 +#define Rf_GetOption1_x 93 +#define Rf_NonNullStringMatch_x 94 +#define Rf_PairToVectorList_x 95 +#define Rf_PrintValue_x 96 +#define Rf_ScalarInteger_x 97 +#define Rf_ScalarLogical_x 98 +#define Rf_ScalarReal_x 99 +#define Rf_ScalarString_x 100 +#define Rf_VectorToPairList_x 101 +#define Rf_allocArray_x 102 +#define Rf_allocMatrix_x 103 +#define Rf_allocVector_x 104 +#define Rf_any_duplicated_x 105 +#define Rf_any_duplicated3_x 106 +#define Rf_asChar_x 107 +#define Rf_asCharacterFactor_x 108 +#define Rf_asInteger_x 109 +#define Rf_asLogical_x 110 +#define Rf_asReal_x 111 +#define Rf_bessel_i_x 112 +#define Rf_bessel_i_ex_x 113 +#define Rf_bessel_j_x 114 +#define Rf_bessel_j_ex_x 115 +#define Rf_bessel_k_x 116 +#define Rf_bessel_k_ex_x 117 +#define Rf_bessel_y_x 118 +#define Rf_bessel_y_ex_x 119 +#define Rf_beta_x 120 +#define Rf_choose_x 121 +#define Rf_classgets_x 122 +#define Rf_coerceVector_x 123 +#define Rf_cons_x 124 +#define Rf_copyListMatrix_x 125 +#define Rf_copyMatrix_x 126 +#define Rf_copyMostAttrib_x 127 +#define Rf_cospi_x 128 +#define Rf_dbeta_x 129 +#define Rf_dbinom_x 130 +#define Rf_dcauchy_x 131 +#define Rf_dchisq_x 132 +#define Rf_defineVar_x 133 +#define Rf_dexp_x 134 +#define Rf_df_x 135 +#define Rf_dgamma_x 136 +#define Rf_dgeom_x 137 +#define Rf_dhyper_x 138 +#define Rf_digamma_x 139 +#define Rf_dlnorm_x 140 +#define Rf_dlogis_x 141 +#define Rf_dnbeta_x 142 +#define Rf_dnbinom_x 143 +#define Rf_dnbinom_mu_x 144 +#define Rf_dnchisq_x 145 +#define Rf_dnf_x 146 +#define Rf_dnorm4_x 147 +#define Rf_dnt_x 148 +#define Rf_dpois_x 149 +#define Rf_dpsifn_x 150 +#define Rf_dsignrank_x 151 +#define Rf_dt_x 152 +#define Rf_dunif_x 153 +#define Rf_duplicate_x 154 +#define Rf_dweibull_x 155 +#define Rf_dwilcox_x 156 +#define Rf_error_x 157 +#define Rf_errorcall_x 158 +#define Rf_eval_x 159 +#define Rf_findFun_x 160 +#define Rf_findVar_x 161 +#define Rf_findVarInFrame_x 162 +#define Rf_findVarInFrame3_x 163 +#define Rf_fprec_x 164 +#define Rf_ftrunc_x 165 +#define Rf_gammafn_x 166 +#define Rf_getAttrib_x 167 +#define Rf_gsetVar_x 168 +#define Rf_inherits_x 169 +#define Rf_install_x 170 +#define Rf_installChar_x 171 +#define Rf_isNull_x 172 +#define Rf_isObject_x 173 +#define Rf_isString_x 174 +#define Rf_lbeta_x 175 +#define Rf_lchoose_x 176 +#define Rf_lengthgets_x 177 +#define Rf_lgamma1p_x 178 +#define Rf_lgammafn_x 179 +#define Rf_lgammafn_sign_x 180 +#define Rf_log1pexp_x 181 +#define Rf_log1pmx_x 182 +#define Rf_logspace_add_x 183 +#define Rf_logspace_sub_x 184 +#define Rf_match_x 185 +#define Rf_mkCharLenCE_x 186 +#define Rf_namesgets_x 187 +#define Rf_ncols_x 188 +#define Rf_nrows_x 189 +#define Rf_pbeta_x 190 +#define Rf_pbinom_x 191 +#define Rf_pcauchy_x 192 +#define Rf_pchisq_x 193 +#define Rf_pentagamma_x 194 +#define Rf_pexp_x 195 +#define Rf_pf_x 196 +#define Rf_pgamma_x 197 +#define Rf_pgeom_x 198 +#define Rf_phyper_x 199 +#define Rf_plnorm_x 200 +#define Rf_plogis_x 201 +#define Rf_pnbeta_x 202 +#define Rf_pnbinom_x 203 +#define Rf_pnbinom_mu_x 204 +#define Rf_pnchisq_x 205 +#define Rf_pnf_x 206 +#define Rf_pnorm5_x 207 +#define Rf_pnorm_both_x 208 +#define Rf_pnt_x 209 +#define Rf_ppois_x 210 +#define Rf_protect_x 211 +#define Rf_psigamma_x 212 +#define Rf_psignrank_x 213 +#define Rf_pt_x 214 +#define Rf_ptukey_x 215 +#define Rf_punif_x 216 +#define Rf_pweibull_x 217 +#define Rf_pwilcox_x 218 +#define Rf_qbeta_x 219 +#define Rf_qbinom_x 220 +#define Rf_qcauchy_x 221 +#define Rf_qchisq_x 222 +#define Rf_qexp_x 223 +#define Rf_qf_x 224 +#define Rf_qgamma_x 225 +#define Rf_qgeom_x 226 +#define Rf_qhyper_x 227 +#define Rf_qlnorm_x 228 +#define Rf_qlogis_x 229 +#define Rf_qnbeta_x 230 +#define Rf_qnbinom_x 231 +#define Rf_qnbinom_mu_x 232 +#define Rf_qnchisq_x 233 +#define Rf_qnf_x 234 +#define Rf_qnorm5_x 235 +#define Rf_qnt_x 236 +#define Rf_qpois_x 237 +#define Rf_qsignrank_x 238 +#define Rf_qt_x 239 +#define Rf_qtukey_x 240 +#define Rf_qunif_x 241 +#define Rf_qweibull_x 242 +#define Rf_qwilcox_x 243 +#define Rf_rbeta_x 244 +#define Rf_rbinom_x 245 +#define Rf_rcauchy_x 246 +#define Rf_rchisq_x 247 +#define Rf_rexp_x 248 +#define Rf_rf_x 249 +#define Rf_rgamma_x 250 +#define Rf_rgeom_x 251 +#define Rf_rhyper_x 252 +#define Rf_rlnorm_x 253 +#define Rf_rlogis_x 254 +#define Rf_rmultinom_x 255 +#define Rf_rnbinom_x 256 +#define Rf_rnbinom_mu_x 257 +#define Rf_rnchisq_x 258 +#define Rf_rnorm_x 259 +#define Rf_rpois_x 260 +#define Rf_rsignrank_x 261 +#define Rf_rt_x 262 +#define Rf_runif_x 263 +#define Rf_rweibull_x 264 +#define Rf_rwilcox_x 265 +#define Rf_setAttrib_x 266 +#define Rf_sign_x 267 +#define Rf_sinpi_x 268 +#define Rf_str2type_x 269 +#define Rf_tanpi_x 270 +#define Rf_tetragamma_x 271 +#define Rf_trigamma_x 272 +#define Rf_unprotect_x 273 +#define Rf_unprotect_ptr_x 274 +#define Rf_warning_x 275 +#define Rf_warningcall_x 276 +#define Rprintf_x 277 +#define SETCAD4R_x 278 +#define SETCADDDR_x 279 +#define SETCADDR_x 280 +#define SETCADR_x 281 +#define SETCAR_x 282 +#define SETCDR_x 283 +#define SETLENGTH_x 284 +#define SETLEVELS_x 285 +#define SETTRUELENGTH_x 286 +#define SET_ATTRIB_x 287 +#define SET_BODY_x 288 +#define SET_CLOENV_x 289 +#define SET_ENCLOS_x 290 +#define SET_FORMALS_x 291 +#define SET_NAMED_FASTR_x 292 +#define SET_OBJECT_x 293 +#define SET_RDEBUG_x 294 +#define SET_RSTEP_x 295 +#define SET_S4_OBJECT_x 296 +#define SET_STRING_ELT_x 297 +#define SET_SYMVALUE_x 298 +#define SET_TAG_x 299 +#define SET_TYPEOF_x 300 +#define SET_VECTOR_ELT_x 301 +#define STRING_ELT_x 302 +#define SYMVALUE_x 303 +#define TAG_x 304 +#define TRUELENGTH_x 305 +#define TYPEOF_x 306 +#define UNSET_S4_OBJECT_x 307 +#define VECTOR_ELT_x 308 +#define forceSymbols_x 309 +#define getCCallable_x 310 +#define getConnectionClassString_x 311 +#define getEmbeddingDLLInfo_x 312 +#define getOpenModeString_x 313 +#define getSummaryDescription_x 314 +#define isSeekable_x 315 +#define octsize_x 316 +#define registerCCallable_x 317 +#define registerRoutines_x 318 +#define restoreHandlerStacks_x 319 +#define setDotSymbolValues_x 320 +#define unif_rand_x 321 +#define useDynamicSymbols_x 322 -#define UPCALLS_TABLE_SIZE 318 +#define UPCALLS_TABLE_SIZE 323 #endif // RFFI_UPCALLSINDEX_H diff --git a/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h b/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h index 97547fc7fcbf2540a5a62bc5f607dfbd0efefe08..3a431bcc4a8c7a16bdfb665c248f9a6465f7aac8 100644 --- a/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h +++ b/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h @@ -492,8 +492,9 @@ Rboolean Rf_inherits(SEXP x, const char * klass) { Rboolean Rf_isObject(SEXP s) { TRACE0(); - unimplemented("Rf_isObject"); - return FALSE; + Rboolean result = (Rboolean) ((call_Rf_isObject) callbacks[Rf_isObject_x])(s); + checkExitCall(); + return result; } void Rf_PrintValue(SEXP x) { @@ -918,6 +919,12 @@ SEXP ENCLOS(SEXP x) { return result; } +void SET_ENCLOS(SEXP x, SEXP v) { + TRACE0(); + ((call_SET_ENCLOS) callbacks[SET_ENCLOS_x])(x, v); + checkExitCall(); +} + SEXP HASHTAB(SEXP x) { TRACE0(); return unimplemented("HASHTAB"); @@ -939,11 +946,6 @@ void SET_FRAME(SEXP x, SEXP v) { unimplemented("SET_FRAME"); } -void SET_ENCLOS(SEXP x, SEXP v) { - TRACE0(); - unimplemented("SET_ENCLOS"); -} - void SET_HASHTAB(SEXP x, SEXP v) { TRACE0(); unimplemented("SET_HASHTAB"); @@ -1035,10 +1037,10 @@ int LEVELS(SEXP x) { return ((call_LEVELS) callbacks[LEVELS_x])(x); } -int SETLEVELS(SEXP x, int v) { +int SETLEVELS(SEXP x, int gpbits) { TRACE0(); - unimplemented("SETLEVELS"); - return 0; + ((call_SETLEVELS) callbacks[SETLEVELS_x])(x, gpbits); + return gpbits; } int *FASTR_DATAPTR(SEXP x) { @@ -1430,7 +1432,21 @@ SEXP R_ClosureExpr(SEXP x) { SEXP R_forceAndCall(SEXP e, int n, SEXP rho) { TRACE0(); - return unimplemented("R_forceAndCall"); + + SEXP fun; + if (TYPEOF(CAR(e)) == SYMSXP) { + PROTECT(fun = findFun(CAR(e), rho)); + } else { + PROTECT(fun = eval(CAR(e), rho)); + } + + SEXP res = ((call_R_forceAndCall) callbacks[R_forceAndCall_x])(e, fun, n, rho); + + UNPROTECT(1); + + checkExitCall(); + + return res; } SEXP R_MakeExternalPtr(void *p, SEXP tag, SEXP prot) { @@ -1441,7 +1457,6 @@ SEXP R_MakeExternalPtr(void *p, SEXP tag, SEXP prot) { } void *R_ExternalPtrAddr(SEXP s) { - TRACE0(); SEXP result = ((call_R_ExternalPtrAddr) callbacks[R_ExternalPtrAddr_x])(s); checkExitCall(); @@ -1752,3 +1767,10 @@ DL_FUNC R_FindSymbol(char const *name, char const *pkg, R_RegisteredNativeSymbol TRACE0(); return unimplemented("R_FindSymbol"); } + +int R_nchar(SEXP string, nchar_type type_, Rboolean allowNA, Rboolean keepNA, const char* msg_name) { + TRACE0(); + int res = ((call_R_nchar) callbacks[R_nchar_x])(string, type_, allowNA, keepNA, msg_name); + checkExitCall(); + return res; +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatMult.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatMult.java index 02246e6530af77f0ce1bb6d79e4b49fe4f122fa2..de78ec1785b013fe37357624627872c3a9a1a29f 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatMult.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatMult.java @@ -27,6 +27,8 @@ import static com.oracle.truffle.r.runtime.RDispatch.OPS_GROUP_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.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; @@ -343,6 +345,25 @@ public abstract class MatMult extends RBuiltinNode.Arg2 { } return doubleMatrixMultiply(a, b, aRows, aCols, bRows, bCols); } else { + if (a.getLength() == 1) { + na.enable(a); + na.enable(b); + double aValue = a.getDataAt(0); + double[] result = new double[b.getLength()]; + if (na.check(aValue)) { + Arrays.fill(result, RRuntime.DOUBLE_NA); + } else { + for (int k = 0; k < b.getLength(); k++) { + double bValue = b.getDataAt(k); + if (na.check(bValue)) { + result[k] = RRuntime.DOUBLE_NA; + } else { + result[k] = mult.applyDouble(aValue, bValue); + } + } + } + return RDataFactory.createDoubleVector(result, na.neverSeenNA(), new int[]{1, b.getLength()}); + } if (a.getLength() != b.getLength()) { throw error(RError.Message.NON_CONFORMABLE_ARGS); } @@ -475,6 +496,23 @@ public abstract class MatMult extends RBuiltinNode.Arg2 { return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{a.getLength(), bCols}); } } else { + if (a.getLength() == 1) { + na.enable(a); + na.enable(b); + RComplex aValue = a.getDataAt(0); + double[] result = new double[2 * b.getLength()]; + if (na.check(aValue)) { + Arrays.fill(result, RRuntime.DOUBLE_NA); + } else { + for (int k = 0; k < b.getLength(); k++) { + RComplex res = mult.applyComplex(aValue, b.getDataAt(k)); + result[2 * k] = res.getRealPart(); + result[2 * k + 1] = res.getImaginaryPart(); + } + } + return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{1, b.getLength()}); + } + if (a.getLength() != b.getLength()) { throw error(RError.Message.NON_CONFORMABLE_ARGS); } @@ -597,6 +635,26 @@ public abstract class MatMult extends RBuiltinNode.Arg2 { return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{a.getLength(), bCols}); } } else { + if (a.getLength() == 1) { + na.enable(a); + na.enable(b); + int aValue = a.getDataAt(0); + int[] result = new int[b.getLength()]; + if (na.check(aValue)) { + Arrays.fill(result, RRuntime.INT_NA); + } else { + for (int k = 0; k < b.getLength(); k++) { + int bValue = b.getDataAt(k); + if (na.check(bValue)) { + result[k] = RRuntime.INT_NA; + } else { + result[k] = mult.applyInteger(aValue, bValue); + } + } + } + return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{1, b.getLength()}); + } + if (a.getLength() != b.getLength()) { throw error(RError.Message.NON_CONFORMABLE_ARGS); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/LocalReadVariableNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/LocalReadVariableNode.java index d163252a676ea5a9c8375a8e9bcf6611daebca76..c739628c0e6806973e59f730dbe23ba968f37b4a 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/LocalReadVariableNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/variables/LocalReadVariableNode.java @@ -84,7 +84,7 @@ public final class LocalReadVariableNode extends Node { public Object execute(VirtualFrame frame, Frame variableFrame) { Frame profiledVariableFrame = frameProfile.profile(variableFrame); - if (frameSlot == null && notInFrame == null) { + if (frameSlot == null && notInFrame == null || (frameSlot != null && frameSlot.getFrameDescriptor() != variableFrame.getFrameDescriptor())) { CompilerDirectives.transferToInterpreterAndInvalidate(); if (identifier.toString().isEmpty()) { throw RError.error(RError.NO_CALLER, RError.Message.ZERO_LENGTH_VARIABLE); diff --git a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g index da733337d217cabbf01617a086e51e9d8f740925..f4080f884755303c03605a955cd8ad6b875910f3 100644 --- a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g +++ b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g @@ -596,7 +596,7 @@ add_operator returns [Token v] ; mult_operator returns [Token v] - : op=(MULT | DIV | MOD ) { $v = $op; } + : op=(MULT | DIV) { $v = $op; } ; power_operator returns [Token v] @@ -667,7 +667,6 @@ NOT : '!' ; QM : '?' ; PLUS : '+' ; MULT : '*' ; -MOD : '%%' ; DIV : '/' ; MINUS : '-' ; @@ -727,7 +726,7 @@ ID | '`' BACKTICK_NAME ; -OP : '%' (~('%' | '\n' | '\r' | '\f'))+ '%' ; +OP : '%' (~('%' | '\n' | '\r' | '\f'))* '%' ; fragment BACKTICK_NAME @init { final StringBuilder buf = new StringBuilder(); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ArgumentsSignature.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ArgumentsSignature.java index 9a78d180f73a0cefa24823e239116683dba783ed..75da2c99bf675b743c41b7a06b6794bec4a5bf20 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ArgumentsSignature.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ArgumentsSignature.java @@ -45,7 +45,7 @@ public final class ArgumentsSignature implements Iterable<String> { * * Note we intentionally use invalid argument name. */ - public static final String UNMATCHED = "^"; + public static final String UNMATCHED = "<<UNMATCHED>>"; public static final String VARARG_NAME = "..."; public static final int[] EMPTY_VARARGS_INDEXES = new int[0]; public static final int NO_VARARG = -1; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DCF.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DCF.java index 5058b639b7eb6e126621226928f797ec8fae0f31..34d1283008964920a7f3999a89bdd619d1b6b7e3 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DCF.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DCF.java @@ -61,8 +61,9 @@ public class DCF { if (line.startsWith("#")) { continue; } - if (isContinuation(line)) { - fieldContent.append(line.substring(1)); + final int wsLen = getWhiteSpaceHeadLength(line); + if (wsLen > 0) { + fieldContent.append('\n').append(line.substring(wsLen)); } else { // should start a field, finish off any current one if (fieldName != null) { @@ -108,12 +109,11 @@ public class DCF { return paragraphs; } - private static boolean isContinuation(String line) { - if (line.length() == 0) { - return false; + private static int getWhiteSpaceHeadLength(String line) { + int i; + for (i = 0; i < line.length() && (line.charAt(i) == ' ' || line.charAt(i) == '\t'); i++) { } - char ch = line.charAt(0); - return ch == ' ' || ch == '\t'; + return i; } private static boolean endOfParagraph(String line) { diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matmul.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matmul.java index 4b27eb0fb9e9d808afaaf09261ccdabc3633ee11..bbbd0eda572fae16f2afdee2e6b2de2f842e0bf0 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matmul.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matmul.java @@ -33,5 +33,12 @@ public class TestBuiltin_matmul extends TestBase { assertEval("x <- matrix(c(1,1,1,1,2,3), 3, 2); dimnames(x) <- list(c(1,2,3),c('','x')); coeff <- c(0,1); names(coeff) <- c('a', 'b'); x %*% coeff; "); assertEval("m1 <- matrix(1:6,3,2,dimnames=list(c('a','b','c'),c('c1','c2')));m2 <- matrix(c(3,4),2,1,dimnames=list(c('a2','b2'),c('col'))); m1 %*% m2; "); assertEval("vec <- c(1,2); names(vec) <- c('a','b'); mat <- matrix(c(8,3),1,2,dimnames=list('row',c('c1','c2'))); vec %*% mat; "); + + assertEval("NA %*% c(3,4,5,6)"); + assertEval("3 %*% c(3,4,5,6)"); + assertEval("NA %*% c(3L,4L,5L,6L)"); + assertEval("3L %*% c(3L,4L,5L,6L)"); + assertEval("c(NA+2i) %*% c(3,4,5,6)"); + assertEval("c(1+2i) %*% c(3,4,5,6)"); } } 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 ffc52410a91a71f0bfd651898fd2ab8c8d1c232b..3723255c2abe6ab33de28647d3fa6cf720b5b233 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 @@ -2071,4 +2071,9 @@ public class TestBuiltin_operators extends TestBase { assertEval("{ list(1, NULL) < c(1, 1) }"); assertEval("{ c(1, 1) < list(1, NULL) }"); } + + @Test + public void testPrecedence() { + assertEval("{ 3 %% 2 %in% 1}"); + } }