-
Notifications
You must be signed in to change notification settings - Fork 0
/
r.h
123 lines (104 loc) · 3.35 KB
/
r.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef RIR_R_H
#define RIR_R_H
#include "common.h"
#include <R.h>
#include <Rinterface.h>
#define USE_RINTERNALS
#include <Rinternals.h>
// r print statement
#include <R_ext/Print.h>
#undef error
#undef TRUE
#undef FALSE
#undef length
#undef eval
#undef cons
#undef isNull
inline bool isNull(SEXP s) { return TYPEOF(s) == NILSXP; }
#undef isComplex
inline bool isComplex(SEXP s) { return TYPEOF(s) == CPLXSXP; }
#undef isString
inline bool isString(SEXP s) { return TYPEOF(s) == STRSXP; }
#undef isObject
inline bool isObject(SEXP s) { return OBJECT(s) != 0; }
#undef isVector
#undef PI
#undef PREXPR
inline SEXP PREXPR(SEXP pr) {
// bypassing PREXPR from Gnur, which causes code objects to be converted to
// AST
SLOWASSERT(TYPEOF(pr) == PROMSXP);
auto res = pr->u.promsxp.expr;
if (TYPEOF(res) == BCODESXP)
return R_PromiseExpr(pr);
return res;
}
extern "C" {
extern SEXP R_TrueValue;
extern SEXP R_FalseValue;
extern SEXP R_LogicalNAValue;
};
// Performance critical stuff copied from Rinlinedfun.h
#ifdef ENABLE_SLOWASSERT
inline void CHKVEC(SEXP x) {
switch (TYPEOF(x)) {
case CHARSXP:
case LGLSXP:
case INTSXP:
case REALSXP:
case CPLXSXP:
case STRSXP:
case VECSXP:
case EXPRSXP:
case RAWSXP:
case WEAKREFSXP:
case EXTERNALSXP: // added by RIR
break;
default:
assert(false);
}
}
#else
#define CHKVEC(x) \
do { \
} while (0)
#endif
inline void* DATAPTR(SEXP x) {
CHKVEC(x);
if (ALTREP(x))
return ALTVEC_DATAPTR(x);
#ifdef CATCH_ZERO_LENGTH_ACCESS
/* Attempts to read or write elements of a zero length vector will
result in a segfault, rather than read and write random memory.
Returning NULL would be more natural, but Matrix seems to assume
that even zero-length vectors have non-NULL data pointers, so
return (void *) 1 instead. Zero-length CHARSXP objects still
have a trailing zero byte so they are not handled. */
else if (STDVEC_LENGTH(x) == 0 && TYPEOF(x) != CHARSXP)
return (void*)1;
#endif
else
return STDVEC_DATAPTR(x);
}
inline R_xlen_t XLENGTH_EX(SEXP x) {
return ALTREP(x) ? ALTREP_LENGTH(x) : STDVEC_LENGTH(x);
}
typedef struct {
int ibeta, it, irnd, ngrd, machep, negep, iexp, minexp, maxexp;
double eps, epsneg, xmin, xmax;
} AccuracyInfo;
LibExtern AccuracyInfo R_AccuracyInfo;
extern int R_PPStackTop;
#define CLEAR_ATTRIB(x) \
do { \
SEXP __x__ = (x); \
if (ATTRIB(__x__) != R_NilValue) { \
SET_ATTRIB(__x__, R_NilValue); \
if (OBJECT(__x__)) \
SET_OBJECT(__x__, 0); \
if (IS_S4_OBJECT(__x__)) \
UNSET_S4_OBJECT(__x__); \
} \
} while (0)
#endif
#undef R_CheckStack