Skip to content
Snippets Groups Projects
Commit cb913b9e authored by Mick Jordan's avatar Mick Jordan Committed by Lukas Stadler
Browse files

cast pipelines: HiddenInternalFunctions

parent 43c42a06
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
*/
package com.oracle.truffle.r.nodes.builtin.base;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*;
import static com.oracle.truffle.r.runtime.RVisibility.OFF;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE;
......@@ -40,8 +41,6 @@ import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.nodes.builtin.base.EvalFunctions.Eval;
import com.oracle.truffle.r.nodes.function.PromiseHelperNode;
import com.oracle.truffle.r.nodes.function.RCallNode;
import com.oracle.truffle.r.nodes.unary.CastIntegerNode;
import com.oracle.truffle.r.nodes.unary.CastIntegerNodeGen;
import com.oracle.truffle.r.runtime.RArguments;
import com.oracle.truffle.r.runtime.RCaller;
import com.oracle.truffle.r.runtime.RCompression;
......@@ -55,13 +54,11 @@ import com.oracle.truffle.r.runtime.SubstituteVirtualFrame;
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RDoubleVector;
import com.oracle.truffle.r.runtime.data.RExternalPtr;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RIntVector;
import com.oracle.truffle.r.runtime.data.RLanguage;
import com.oracle.truffle.r.runtime.data.RList;
import com.oracle.truffle.r.runtime.data.RLogicalVector;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RPromise;
import com.oracle.truffle.r.runtime.data.RPromise.Closure;
......@@ -81,7 +78,7 @@ public class HiddenInternalFunctions {
/**
* Transcribed from GnuR {@code do_makeLazy} in src/main/builtin.c.
*/
@RBuiltin(name = "makeLazy", visibility = OFF, kind = INTERNAL, parameterNames = {"names", "values", "expr", "eenv", "aenv"}, behavior = COMPLEX)
@RBuiltin(name = "makeLazy", visibility = OFF, kind = INTERNAL, parameterNames = {"names", "values", "expr", "eval.env", "assign.env"}, behavior = COMPLEX)
public abstract static class MakeLazy extends RBuiltinNode {
@Child private Eval eval;
......@@ -92,6 +89,13 @@ public class HiddenInternalFunctions {
}
}
@Override
protected void createCasts(CastBuilder casts) {
casts.arg("names").mustBe(stringValue()).asStringVector();
casts.arg("eval.env").mustBe(instanceOf(REnvironment.class));
casts.arg("assign.env").mustBe(instanceOf(REnvironment.class));
}
/**
* {@code expr} has the value {@code lazyLoadDBfetch(key, datafile, compressed, envhook)},
* see {@code base/lazyLoad.R}. All the arguments except {@code key} are defined in the
......@@ -138,8 +142,16 @@ public class HiddenInternalFunctions {
* This function copies values of variables from one environment to another environment,
* possibly with different names. Promises are not forced and active bindings are preserved.
*/
@RBuiltin(name = "importIntoEnv", kind = INTERNAL, parameterNames = {"impEnv", "impNames", "expEnv", "expNames"}, behavior = COMPLEX)
@RBuiltin(name = "importIntoEnv", kind = INTERNAL, parameterNames = {"impenv", "impnames", "expenv", "expnames"}, behavior = COMPLEX)
public abstract static class ImportIntoEnv extends RBuiltinNode {
@Override
protected void createCasts(CastBuilder casts) {
casts.arg("impenv").mustBe(nullValue().not(), RError.Message.USE_NULL_ENV_DEFUNCT).mustBe(instanceOf(REnvironment.class), RError.Message.BAD_ENVIRONMENT, "import");
casts.arg("expenv").mustBe(nullValue().not(), RError.Message.USE_NULL_ENV_DEFUNCT).mustBe(instanceOf(REnvironment.class), RError.Message.BAD_ENVIRONMENT, "import");
casts.arg("impnames").mustBe(stringValue(), RError.Message.INVALID_ARGUMENT, "names").asStringVector();
casts.arg("expnames").mustBe(stringValue(), RError.Message.INVALID_ARGUMENT, "names").asStringVector();
}
@Specialization
@TruffleBoundary
protected RNull importIntoEnv(REnvironment impEnv, RAbstractStringVector impNames, REnvironment expEnv, RAbstractStringVector expNames) {
......@@ -176,32 +188,18 @@ public class HiddenInternalFunctions {
public abstract static class LazyLoadDBFetch extends RBuiltinNode {
@Child private CallInlineCacheNode callCache = CallInlineCacheNodeGen.create();
@Child private CastIntegerNode castIntNode;
private void initCast() {
if (castIntNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
castIntNode = insert(CastIntegerNodeGen.create(false, false, false));
}
@Override
protected void createCasts(CastBuilder casts) {
casts.arg("compressed").asIntegerVector().findFirst();
}
/**
* No error checking here as this called by trusted library code.
*/
@Specialization
protected Object lazyLoadDBFetch(VirtualFrame frame, RIntVector key, RStringVector datafile, RIntVector compressed, RFunction envhook) {
return lazyLoadDBFetchInternal(frame.materialize(), key, datafile, compressed.getDataAt(0), envhook);
}
@Specialization
protected Object lazyLoadDBFetch(VirtualFrame frame, RIntVector key, RStringVector datafile, RDoubleVector compressed, RFunction envhook) {
return lazyLoadDBFetchInternal(frame.materialize(), key, datafile, (int) compressed.getDataAt(0), envhook);
}
@Specialization
protected Object lazyLoadDBFetch(VirtualFrame frame, RIntVector key, RStringVector datafile, RLogicalVector compressed, RFunction envhook) {
initCast();
return lazyLoadDBFetch(frame, key, datafile, castIntNode.doLogicalVector(compressed), envhook);
protected Object lazyLoadDBFetch(VirtualFrame frame, RIntVector key, RStringVector datafile, int compressed, RFunction envhook) {
return lazyLoadDBFetchInternal(frame.materialize(), key, datafile, compressed, envhook);
}
@TruffleBoundary
......@@ -362,7 +360,6 @@ public class HiddenInternalFunctions {
@Override
protected void createCasts(CastBuilder casts) {
// TODO: not sure if the behavior is 100% compliant
casts.arg("ascii").asIntegerVector().findFirst();
casts.arg("compsxp").asIntegerVector().findFirst();
}
......
......@@ -704,6 +704,7 @@ public final class RError extends RuntimeException {
INVALID_STRING_IN_WARNING(" [invalid string in warning(.)]"),
ERR_MSG_MUST_BE_STRING("error message must be a character string"),
ERR_MSG_BAD("bad error message"),
BAD_ENVIRONMENT("bad %s environment argument"),
CANNOT_BE_LENGTH("'%s' cannot be of length %d");
public final String message;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment