yap4r
This commit is contained in:
@@ -1,68 +1,64 @@
|
||||
#include <Rembedded.h>
|
||||
#include <R.h>
|
||||
#include <Rinternals.h>
|
||||
#include <Rdefines.h>
|
||||
#include <R_ext/Parse.h>
|
||||
|
||||
/**
|
||||
* @file real.h
|
||||
* @date Sat May 19 13:44:04 2018
|
||||
*
|
||||
* @brief Prolog to R interface
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <YapInterface.h>
|
||||
#include <c_interface.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
bool R_isNull(SEXP sexp);
|
||||
|
||||
#define BUFSIZE 256
|
||||
#if DEBUG_MEMORY
|
||||
#define PROTECT_AND_COUNT(EXP) \
|
||||
{ \
|
||||
extern int R_PPStackTop; \
|
||||
PROTECT(EXP); \
|
||||
nprotect++; \
|
||||
printf("%s:%d +%d=%d\n", __FUNCTION__, __LINE__, nprotect, R_PPStackTop); \
|
||||
}
|
||||
#define Ureturn \
|
||||
{ \
|
||||
extern int R_PPStackTop; \
|
||||
printf("%s:%d -%d=%d\n", __FUNCTION__, __LINE__, nprotect, \
|
||||
R_PPStackTop - nprotect); \
|
||||
} \
|
||||
unprotect(nprotect); \
|
||||
return
|
||||
#else
|
||||
#define PROTECT_AND_COUNT(EXP) \
|
||||
{ \
|
||||
PROTECT(EXP); \
|
||||
nprotect++; \
|
||||
}
|
||||
#define Ureturn \
|
||||
unprotect(nprotect); \
|
||||
return
|
||||
#endif
|
||||
|
||||
typedef unsigned int PL_Type;
|
||||
// #define PL_free(v)
|
||||
|
||||
#define PL_Nil 0
|
||||
#define PL_Var 1
|
||||
#define PL_Atom 2
|
||||
#define PL_Appl 3
|
||||
#define PL_Pair 4
|
||||
#define PL_Int 5
|
||||
#define PL_Float 6
|
||||
#define PL_DbRef 7
|
||||
#define PL_Unknown 8
|
||||
static inline SEXP protected_tryEval(SEXP expr, SEXP env, int *errp) {
|
||||
SEXP o;
|
||||
o = R_tryEval(expr, env, errp);
|
||||
return o ? o : expr;
|
||||
}
|
||||
|
||||
|
||||
#ifndef term_t
|
||||
#define term_t YAP_Int
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
r_undefined,
|
||||
r_double,
|
||||
r_int,
|
||||
r_character
|
||||
} r_basic_types;
|
||||
|
||||
extern bool sexp_to_pl(term_t t, SEXP s);
|
||||
extern SEXP term_to_sexp(term_t t, bool eval);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
r_basic_types type;
|
||||
union {
|
||||
int int_val;
|
||||
double double_val;
|
||||
char *char_val;
|
||||
} real_u;
|
||||
} list_cell;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int size;
|
||||
int nDims;
|
||||
int dims[BUFSIZE];
|
||||
list_cell values[BUFSIZE];
|
||||
} list;
|
||||
|
||||
#define real_Int 1
|
||||
#define real_Float 2
|
||||
#define real_Char 3
|
||||
#define real_Bool 4
|
||||
|
||||
#define real_ty_Vector 1
|
||||
#define real_ty_Matrix 2
|
||||
#define real_ty_List 3
|
||||
#define real_ty_Array 4 //not used, yet
|
||||
|
||||
extern void init_R(void);
|
||||
extern void end_R(void);
|
||||
extern void send_command(char * expression);
|
||||
extern int set_list_values(void);
|
||||
extern int set_vec_values(void);
|
||||
extern int set_array_values(void);
|
||||
extern SEXP process_expression(char * expression);
|
||||
extern YAP_Term sexp_pl(SEXP s);
|
||||
|
Reference in New Issue
Block a user