Skip to content
Snippets Groups Projects
Commit 65a9188e authored by stepan's avatar stepan
Browse files

RFFI: implement Rf_str2type

parent a8501738
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
......@@ -1446,4 +1447,49 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI {
return REnvironment.getRegisteredNamespace("methods");
}
private HashMap<String, Integer> name2typeTable;
@Override
@TruffleBoundary
public int Rf_str2type(Object name) {
if (name == null) {
return -1;
}
initName2typeTable();
Integer result = name2typeTable.get(name);
return result != null ? result : -1;
}
private void initName2typeTable() {
if (name2typeTable != null) {
return;
}
name2typeTable = new HashMap<>(26);
name2typeTable.put("NULL", SEXPTYPE.NILSXP.code); /* real types */
name2typeTable.put("symbol", SEXPTYPE.SYMSXP.code);
name2typeTable.put("pairlist", SEXPTYPE.LISTSXP.code);
name2typeTable.put("closure", SEXPTYPE.CLOSXP.code);
name2typeTable.put("environment", SEXPTYPE.ENVSXP.code);
name2typeTable.put("promise", SEXPTYPE.PROMSXP.code);
name2typeTable.put("language", SEXPTYPE.LANGSXP.code);
name2typeTable.put("special", SEXPTYPE.SPECIALSXP.code);
name2typeTable.put("builtin", SEXPTYPE.BUILTINSXP.code);
name2typeTable.put("char", SEXPTYPE.CHARSXP.code);
name2typeTable.put("logical", SEXPTYPE.LGLSXP.code);
name2typeTable.put("integer", SEXPTYPE.INTSXP.code);
name2typeTable.put("double", SEXPTYPE.REALSXP.code); /*- "real", for R <= 0.61.x */
name2typeTable.put("complex", SEXPTYPE.CPLXSXP.code);
name2typeTable.put("character", SEXPTYPE.STRSXP.code);
name2typeTable.put("...", SEXPTYPE.DOTSXP.code);
name2typeTable.put("any", SEXPTYPE.ANYSXP.code);
name2typeTable.put("expression", SEXPTYPE.EXPRSXP.code);
name2typeTable.put("list", SEXPTYPE.VECSXP.code);
name2typeTable.put("externalptr", SEXPTYPE.EXTPTRSXP.code);
name2typeTable.put("bytecode", SEXPTYPE.BCODESXP.code);
name2typeTable.put("weakref", SEXPTYPE.WEAKREFSXP.code);
name2typeTable.put("raw", SEXPTYPE.RAWSXP.code);
name2typeTable.put("S4", SEXPTYPE.S4SXP.code);
name2typeTable.put("numeric", SEXPTYPE.REALSXP.code);
name2typeTable.put("name", SEXPTYPE.SYMSXP.code);
}
}
......@@ -825,4 +825,9 @@ final class TracingUpCallsRFFIImpl implements UpCallsRFFI {
return delegate.R_MethodsNamespace();
}
@Override
public int Rf_str2type(Object name) {
RFFIUtils.traceUpCall("Rf_str2type");
return delegate.Rf_str2type(name);
}
}
......@@ -288,4 +288,6 @@ public interface StdUpCallsRFFI {
Object R_MethodsNamespace();
int Rf_str2type(@RFFICstring Object name);
}
......@@ -110,32 +110,33 @@
#define Rf_ncols_x 105
#define Rf_nrows_x 106
#define Rf_setAttrib_x 107
#define Rf_warning_x 108
#define Rf_warningcall_x 109
#define Rprintf_x 110
#define SETCADR_x 111
#define SETCAR_x 112
#define SETCDR_x 113
#define SET_RDEBUG_x 114
#define SET_RSTEP_x 115
#define SET_S4_OBJECT_x 116
#define SET_STRING_ELT_x 117
#define SET_SYMVALUE_x 118
#define SET_TAG_x 119
#define SET_TYPEOF_FASTR_x 120
#define SET_VECTOR_ELT_x 121
#define STRING_ELT_x 122
#define SYMVALUE_x 123
#define TAG_x 124
#define TYPEOF_x 125
#define UNSET_S4_OBJECT_x 126
#define VECTOR_ELT_x 127
#define getConnectionClassString_x 128
#define getOpenModeString_x 129
#define getSummaryDescription_x 130
#define isSeekable_x 131
#define unif_rand_x 132
#define Rf_str2type_x 108
#define Rf_warning_x 109
#define Rf_warningcall_x 110
#define Rprintf_x 111
#define SETCADR_x 112
#define SETCAR_x 113
#define SETCDR_x 114
#define SET_RDEBUG_x 115
#define SET_RSTEP_x 116
#define SET_S4_OBJECT_x 117
#define SET_STRING_ELT_x 118
#define SET_SYMVALUE_x 119
#define SET_TAG_x 120
#define SET_TYPEOF_FASTR_x 121
#define SET_VECTOR_ELT_x 122
#define STRING_ELT_x 123
#define SYMVALUE_x 124
#define TAG_x 125
#define TYPEOF_x 126
#define UNSET_S4_OBJECT_x 127
#define VECTOR_ELT_x 128
#define getConnectionClassString_x 129
#define getOpenModeString_x 130
#define getSummaryDescription_x 131
#define isSeekable_x 132
#define unif_rand_x 133
#define UPCALLS_TABLE_SIZE 133
#define UPCALLS_TABLE_SIZE 134
#endif // RFFI_UPCALLSINDEX_H
......@@ -95,6 +95,7 @@ static jmethodID LENGTH_MethodID;
static jmethodID R_do_slot_MethodID;
static jmethodID R_do_slot_assign_MethodID;
static jmethodID R_MethodsNamespaceMethodID;
static jmethodID Rf_str2type_MethodID;
static jmethodID Rf_asIntegerMethodID;
static jmethodID Rf_asRealMethodID;
static jmethodID Rf_asCharMethodID;
......@@ -212,6 +213,7 @@ void init_internals(JNIEnv *env) {
R_do_slot_MethodID = checkGetMethodID(env, UpCallsRFFIClass, "R_do_slot", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 0);
R_do_slot_assign_MethodID = checkGetMethodID(env, UpCallsRFFIClass, "R_do_slot_assign", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 0);
R_MethodsNamespaceMethodID = checkGetMethodID(env, UpCallsRFFIClass, "R_MethodsNamespace", "()Ljava/lang/Object;", 0);
Rf_str2type_MethodID = checkGetMethodID(env, UpCallsRFFIClass, "Rf_str2type", "(Ljava/lang/Object;)I", 0);
Rf_asIntegerMethodID = checkGetMethodID(env, UpCallsRFFIClass, "Rf_asInteger", "(Ljava/lang/Object;)I", 0);
Rf_asRealMethodID = checkGetMethodID(env, UpCallsRFFIClass, "Rf_asReal", "(Ljava/lang/Object;)D", 0);
Rf_asCharMethodID = checkGetMethodID(env, UpCallsRFFIClass, "Rf_asChar", "(Ljava/lang/Object;)Ljava/lang/Object;", 0);
......@@ -1537,6 +1539,12 @@ SEXP R_do_new_object(SEXP class_def) {
return checkRef(thisenv, result);
}
SEXPTYPE Rf_str2type(const char *name) {
JNIEnv *thisenv = getEnv();
jstring jsName = (*thisenv)->NewStringUTF(thisenv, name);
return (*thisenv)->CallObjectMethod(thisenv, UpCallsRFFIObject, Rf_str2type_MethodID, jsName);
}
static SEXP jniGetMethodsNamespace() {
JNIEnv *thisenv = getEnv();
return (*thisenv)->CallObjectMethod(thisenv, UpCallsRFFIObject, R_MethodsNamespaceMethodID);
......
26
27
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