Skip to content
Snippets Groups Projects
Commit c776ab80 authored by Zbynek Slajchrt's avatar Zbynek Slajchrt
Browse files

Enabling package stringi

parent fb7462f3
Branches
No related tags found
No related merge requests found
Showing
with 112 additions and 34 deletions
...@@ -54,9 +54,9 @@ import com.oracle.truffle.r.runtime.context.RContext; ...@@ -54,9 +54,9 @@ import com.oracle.truffle.r.runtime.context.RContext;
* Rf_mainloop(); * Rf_mainloop();
* </pre> * </pre>
* *
* {@code Rf_initialize_R} invokes {@link #initializeR(String[])}, which creates new polyglot * {@code Rf_initialize_R} invokes {@link #initializeR(String[], boolean)}, which creates new
* {@link Context}. The call to {@code R_SetParams} adjusts the values stored in the * polyglot {@link Context}. The call to {@code R_SetParams} adjusts the values stored in the
* {@link RStartParams} object and then {@code Rf_mainloop}, which calls {@link #setupRmainloop()} * {@link RStartParams} object and then {@code Rf_mainloop}, which calls {@code #setupRmainloop()}
* and then {@link #runRmainloop()}, which will complete the FastR initialization and enter the * and then {@link #runRmainloop()}, which will complete the FastR initialization and enter the
* read-eval-print loop. * read-eval-print loop.
*/ */
......
...@@ -1935,7 +1935,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { ...@@ -1935,7 +1935,7 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI {
NativeDataAccess.setNativeWrapper((RObject) vector, this); NativeDataAccess.setNativeWrapper((RObject) vector, this);
} }
static Object get(TruffleObject x) { public static Object get(TruffleObject x) {
assert x instanceof RObject; assert x instanceof RObject;
Object wrapper = NativeDataAccess.getNativeWrapper((RObject) x); Object wrapper = NativeDataAccess.getNativeWrapper((RObject) x);
if (wrapper != null) { if (wrapper != null) {
......
...@@ -27,6 +27,8 @@ import com.oracle.truffle.api.interop.MessageResolution; ...@@ -27,6 +27,8 @@ import com.oracle.truffle.api.interop.MessageResolution;
import com.oracle.truffle.api.interop.Resolve; import com.oracle.truffle.api.interop.Resolve;
import com.oracle.truffle.api.interop.TruffleObject; import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.ffi.impl.common.JavaUpCallsRFFIImpl.VectorWrapper;
import com.oracle.truffle.r.runtime.data.CharSXPWrapper;
import com.oracle.truffle.r.runtime.ffi.DLL; import com.oracle.truffle.r.runtime.ffi.DLL;
import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo; import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo;
import com.oracle.truffle.r.runtime.interop.RObjectNativeWrapper; import com.oracle.truffle.r.runtime.interop.RObjectNativeWrapper;
...@@ -47,4 +49,25 @@ public class DLLInfoMR { ...@@ -47,4 +49,25 @@ public class DLLInfoMR {
return new RObjectNativeWrapper((DLLInfo) receiver); return new RObjectNativeWrapper((DLLInfo) receiver);
} }
} }
@Resolve(message = "READ")
public abstract static class ReadNode extends Node {
public Object access(Object receiver, Object index) {
DLLInfo dllInfo = (DLLInfo) receiver;
int i = ((Number) index).intValue();
CharSXPWrapper res;
switch (i) {
case 0:
res = dllInfo.pathSXP;
break;
case 1:
res = dllInfo.nameSXP;
break;
default:
throw new IndexOutOfBoundsException("Index can be 0 or 1");
}
return VectorWrapper.get(res);
}
}
} }
...@@ -163,12 +163,12 @@ final class TruffleLLVM_Call implements CallRFFI { ...@@ -163,12 +163,12 @@ final class TruffleLLVM_Call implements CallRFFI {
@Specialization @Specialization
protected static Object convert(int value) { protected static Object convert(int value) {
return RDataFactory.createIntVector(new int[]{value}, !RRuntime.isNA(value)); return RDataFactory.createIntVectorFromScalar(value);
} }
@Specialization @Specialization
protected static Object convert(double value) { protected static Object convert(double value) {
return RDataFactory.createDoubleVector(new double[]{value}, !RRuntime.isNA(value)); return RDataFactory.createDoubleVectorFromScalar(value);
} }
@Specialization @Specialization
...@@ -183,12 +183,12 @@ final class TruffleLLVM_Call implements CallRFFI { ...@@ -183,12 +183,12 @@ final class TruffleLLVM_Call implements CallRFFI {
@Specialization @Specialization
protected static Object convert(byte value) { protected static Object convert(byte value) {
return RDataFactory.createLogicalVector(new byte[]{value}, !RRuntime.isNA(value)); return RDataFactory.createLogicalVectorFromScalar(value);
} }
@Specialization @Specialization
protected static Object convert(String value) { protected static Object convert(String value) {
return RDataFactory.createStringVector(new String[]{value}, !RRuntime.isNA(value)); return RDataFactory.createStringVectorFromScalar(value).makeSharedPermanent();
} }
@Fallback @Fallback
......
...@@ -42,7 +42,7 @@ import com.oracle.truffle.r.runtime.nodes.RBaseNode; ...@@ -42,7 +42,7 @@ import com.oracle.truffle.r.runtime.nodes.RBaseNode;
import com.oracle.truffle.r.runtime.rng.RRNG; import com.oracle.truffle.r.runtime.rng.RRNG;
/** /**
* Implements the vectorization of {@link RMultinom}. * Implements the vectorization of {@link RMultinomNode}.
*/ */
public abstract class RMultinomNode extends RExternalBuiltinNode.Arg3 { public abstract class RMultinomNode extends RExternalBuiltinNode.Arg3 {
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// TODO: this file can likely be removed, using the NFI version instead
#define T_MEM_TABLE_INITIAL_SIZE 0 #define T_MEM_TABLE_INITIAL_SIZE 0
// The table of transient objects that have been allocated dur the current FFI call // The table of transient objects that have been allocated dur the current FFI call
static void **tMemTable; static void **tMemTable;
......
...@@ -44,10 +44,22 @@ else ...@@ -44,10 +44,22 @@ else
llvm_args="-stdlib=libc++ -I/usr/include/libcxxabi $llvm_args" llvm_args="-stdlib=libc++ -I/usr/include/libcxxabi $llvm_args"
fi fi
runit $llvm_tool_bin $llvm_args runit $llvm_tool_bin $llvm_args
ecode=$?
if [[ $ecode -ne 0 ]]; then
exit $ecode
fi
# the llvm_ir_file is empty if the result is sent to stdout # the llvm_ir_file is empty if the result is sent to stdout
if [ -n "$llvm_ir_file" ]; then if [ -n "$llvm_ir_file" ]; then
mem2reg_opt mem2reg_opt
ecode=$?
if [[ $ecode -ne 0 ]]; then
exit $ecode
fi
fake_obj fake_obj
ecode=$?
if [[ $ecode -ne 0 ]]; then
exit $ecode
fi
fi fi
fi fi
...@@ -40,9 +40,22 @@ else ...@@ -40,9 +40,22 @@ else
llvm_tool=clang llvm_tool=clang
get_llvm_tool get_llvm_tool
runit $llvm_tool_bin $llvm_args runit $llvm_tool_bin $llvm_args
ecode=$?
if [[ $ecode -ne 0 ]]; then
exit $ecode
fi
# the llvm_ir_file is empty if the result is sent to stdout # the llvm_ir_file is empty if the result is sent to stdout
if [ -n "$llvm_ir_file" ]; then if [ -n "$llvm_ir_file" ]; then
mem2reg_opt mem2reg_opt
ecode=$?
if [[ $ecode -ne 0 ]]; then
exit $ecode
fi
fake_obj fake_obj
ecode=$?
if [[ $ecode -ne 0 ]]; then
exit $ecode
fi
fi fi
fi fi
...@@ -53,41 +53,66 @@ function analyze_args() { ...@@ -53,41 +53,66 @@ function analyze_args() {
llvm_args="-g " llvm_args="-g "
if [ $fortran -eq 1 ] if [ $fortran -eq 1 ]
then then
llvm_args+='-S '
llvm_file_ext='.ll' llvm_file_ext='.ll'
else else
llvm_file_ext='.bc' llvm_file_ext='.bc'
llvm_args+='-emit-llvm '
fi fi
is_link=0 is_link=0
out_file_opt=""
llvm_ir_file="" llvm_ir_file=""
llvm_ir_file_opt=""
c_opt_found=0
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
llvm_args+="$1 "
case $1 in case $1 in
-c)
c_opt_found=1
llvm_args+="$1 "
;;
-o) -o)
shift shift
p=$1 p=$1
f=`basename $p` f=`basename $p`
d=`dirname $p` d=`dirname $p`
ext=${f##*.} ext=${f##*.}
if [ $ext == 'so' ] || [ $ext == 'dylib' ] if [ $ext == 'so' ] || [ $ext == 'dylib' ]
then then
is_link=1 is_link=1
elif [ $ext == 'o' ] elif [ $ext == 'o' ]
then then
llvm_ir_file=${d}/${f%%.*} llvm_ir_file=${d}/${f%%.*}
llvm_ir_file+=$llvm_file_ext llvm_ir_file="${llvm_ir_file}${llvm_file_ext}"
llvm_args+="$llvm_ir_file " llvm_ir_file_opt="-o ${llvm_ir_file}"
fi else
out_file_opt="-o $p"
fi
;;
*)
llvm_args+="$1 "
;; ;;
*)
;;
esac esac
shift shift
done done
if [ $fortran -eq 1 ]
then
if [ $c_opt_found -eq 1 ]
then
llvm_args="-S $llvm_ir_file_opt $llvm_args "
else
llvm_args="$out_file_opt $llvm_args "
fi
else
if [ $c_opt_found -eq 1 ]
then
llvm_args="-emit-llvm $llvm_ir_file_opt $llvm_args "
else
llvm_args="$out_file_opt $llvm_args "
fi
fi
} }
# Input arguments: # Input arguments:
......
...@@ -39,6 +39,7 @@ import com.oracle.truffle.r.runtime.context.RContext; ...@@ -39,6 +39,7 @@ import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.context.RContext.ContextKind; import com.oracle.truffle.r.runtime.context.RContext.ContextKind;
import com.oracle.truffle.r.runtime.context.RContext.ContextState; import com.oracle.truffle.r.runtime.context.RContext.ContextState;
import com.oracle.truffle.r.runtime.data.NativeDataAccess.CustomNativeMirror; import com.oracle.truffle.r.runtime.data.NativeDataAccess.CustomNativeMirror;
import com.oracle.truffle.r.runtime.data.CharSXPWrapper;
import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RExternalPtr; import com.oracle.truffle.r.runtime.data.RExternalPtr;
import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RList;
...@@ -191,8 +192,16 @@ public class DLL { ...@@ -191,8 +192,16 @@ public class DLL {
private static final String DLLINFO_CLASS = "DLLInfo"; private static final String DLLINFO_CLASS = "DLLInfo";
private final int id; private final int id;
public final String name; public final String name;
public final String path; public final String path;
/**
* The CharSXPWrapper fields maintain the wrapped strings that are returned as a response to
* the READ message sent to this Truffle object. See {@code DLLInfoMR}.
*/
public final CharSXPWrapper nameSXP;
public final CharSXPWrapper pathSXP;
public final Object handle; public final Object handle;
private boolean dynamicLookup; private boolean dynamicLookup;
private boolean forceSymbols; private boolean forceSymbols;
...@@ -203,7 +212,9 @@ public class DLL { ...@@ -203,7 +212,9 @@ public class DLL {
private DLLInfo(String name, String path, boolean dynamicLookup, Object handle) { private DLLInfo(String name, String path, boolean dynamicLookup, Object handle) {
this.id = ID.getAndIncrement(); this.id = ID.getAndIncrement();
this.name = name; this.name = name;
this.nameSXP = CharSXPWrapper.create(name);
this.path = path; this.path = path;
this.pathSXP = CharSXPWrapper.create(path);
this.dynamicLookup = dynamicLookup; this.dynamicLookup = dynamicLookup;
this.handle = handle; this.handle = handle;
} }
......
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
*/ */
package com.oracle.truffle.r.runtime.ffi; package com.oracle.truffle.r.runtime.ffi;
import java.util.Arrays;
import java.util.stream.Stream;
import com.oracle.truffle.r.runtime.REnvVars; import com.oracle.truffle.r.runtime.REnvVars;
import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.TempPathName; import com.oracle.truffle.r.runtime.TempPathName;
...@@ -33,12 +30,11 @@ import com.oracle.truffle.r.runtime.data.CharSXPWrapper; ...@@ -33,12 +30,11 @@ import com.oracle.truffle.r.runtime.data.CharSXPWrapper;
import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RMissing; import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RSymbol;
import com.oracle.truffle.r.runtime.data.RUnboundValue; import com.oracle.truffle.r.runtime.data.RUnboundValue;
import com.oracle.truffle.r.runtime.env.REnvironment; import com.oracle.truffle.r.runtime.env.REnvironment;
/** /**
* Note: regenerate the C glue code upon any change in this enum, use {@link #main(String[])}. * Note: regenerate the C glue code upon any change in this enum.
*/ */
public enum RFFIVariables { public enum RFFIVariables {
R_Home("dummy string"), R_Home("dummy string"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment