-
Notifications
You must be signed in to change notification settings - Fork 309
/
Defn.h
1525 lines (1354 loc) · 50.2 KB
/
Defn.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1998--2020 The R Core Team.
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, a copy is available at
* https://www.R-project.org/Licenses/
*/
/* Internal header, not installed */
#ifndef DEFN_H_
#define DEFN_H_
/* seems unused */
#define COUNTING
#define BYTECODE
/* probably no longer needed */
#define NEW_CONDITION_HANDLING
/* To test the write barrier used by the generational collector,
define TESTING_WRITE_BARRIER. This makes the internal structure of
SEXPRECs visible only inside of files that explicitly define
USE_RINTERNALS, and all uses of SEXPREC fields that do not go
through the appropriate functions or macros will become compilation
errors. Since this does impose a small but noticable performance
penalty, code that includes Defn.h (or code that explicitly defines
USE_RINTERNALS) can access a SEXPREC's fields directly. */
#ifndef TESTING_WRITE_BARRIER
# define USE_RINTERNALS
#endif
#ifdef HAVE_VISIBILITY_ATTRIBUTE
# define attribute_visible __attribute__ ((visibility ("default")))
# define attribute_hidden __attribute__ ((visibility ("hidden")))
#else
# define attribute_visible
# define attribute_hidden
#endif
#ifdef __MAIN__
# define extern0 attribute_hidden
#else
# define extern0 extern
#endif
#define MAXELTSIZE 8192 /* Used as a default for string buffer sizes,
and occasionally as a limit. */
#include <R_ext/Complex.h>
void Rf_CoercionWarning(int);/* warning code */
int Rf_LogicalFromInteger(int, int*);
int Rf_LogicalFromReal(double, int*);
int Rf_LogicalFromComplex(Rcomplex, int*);
int Rf_IntegerFromLogical(int, int*);
int Rf_IntegerFromReal(double, int*);
int Rf_IntegerFromComplex(Rcomplex, int*);
double Rf_RealFromLogical(int, int*);
double Rf_RealFromInteger(int, int*);
double Rf_RealFromComplex(Rcomplex, int*);
Rcomplex Rf_ComplexFromLogical(int, int*);
Rcomplex Rf_ComplexFromInteger(int, int*);
Rcomplex Rf_ComplexFromReal(double, int*);
#define CALLED_FROM_DEFN_H 1
#include <Rinternals.h> /*-> Arith.h, Boolean.h, Complex.h, Error.h,
Memory.h, PrtUtil.h, Utils.h */
#undef CALLED_FROM_DEFN_H
const char * Rf_translateCharFP(SEXP);
const char * Rf_translateCharFP2(SEXP);
const char * Rf_trCharUTF8(SEXP);
extern0 SEXP R_CommentSymbol; /* "comment" */
extern0 SEXP R_DotEnvSymbol; /* ".Environment" */
extern0 SEXP R_ExactSymbol; /* "exact" */
extern0 SEXP R_RecursiveSymbol; /* "recursive" */
extern0 SEXP R_WholeSrcrefSymbol; /* "wholeSrcref" */
extern0 SEXP R_TmpvalSymbol; /* "*tmp*" */
extern0 SEXP R_UseNamesSymbol; /* "use.names" */
extern0 SEXP R_ColonSymbol; /* ":" */
//extern0 SEXP R_DoubleColonSymbol; /* "::" */
//extern0 SEXP R_TripleColonSymbol; /* ":::" */
extern0 SEXP R_ConnIdSymbol; /* "conn_id" */
extern0 SEXP R_DevicesSymbol; /* ".Devices" */
extern0 SEXP R_dot_Methods; /* ".Methods" */
extern0 SEXP R_dot_Group; /* ".Group" */
extern0 SEXP R_dot_Class; /* ".Class" */
extern0 SEXP R_dot_GenericCallEnv; /* ".GenericCallEnv" */
extern0 SEXP R_dot_GenericDefEnv; /* ".GenericDefEnv" */
extern0 SEXP R_StringHash; /* Global hash of CHARSXPs */
/* writable char access for R internal use only */
#define CHAR_RW(x) ((char *) CHAR(x))
/* CHARSXP charset bits */
#define BYTES_MASK (1<<1)
#define LATIN1_MASK (1<<2)
#define UTF8_MASK (1<<3)
/* (1<<4) is taken by S4_OBJECT_MASK */
#define CACHED_MASK (1<<5)
#define ASCII_MASK (1<<6)
#define HASHASH_MASK 1
/**** HASHASH uses the first bit -- see HASHASH_MASK defined below */
#ifdef USE_RINTERNALS
# define IS_BYTES(x) ((x)->sxpinfo.gp & BYTES_MASK)
# define SET_BYTES(x) (((x)->sxpinfo.gp) |= BYTES_MASK)
# define IS_LATIN1(x) ((x)->sxpinfo.gp & LATIN1_MASK)
# define SET_LATIN1(x) (((x)->sxpinfo.gp) |= LATIN1_MASK)
# define IS_ASCII(x) ((x)->sxpinfo.gp & ASCII_MASK)
# define SET_ASCII(x) (((x)->sxpinfo.gp) |= ASCII_MASK)
# define IS_UTF8(x) ((x)->sxpinfo.gp & UTF8_MASK)
# define SET_UTF8(x) (((x)->sxpinfo.gp) |= UTF8_MASK)
# define ENC_KNOWN(x) ((x)->sxpinfo.gp & (LATIN1_MASK | UTF8_MASK))
# define SET_CACHED(x) (((x)->sxpinfo.gp) |= CACHED_MASK)
# define IS_CACHED(x) (((x)->sxpinfo.gp) & CACHED_MASK)
#else
/* Needed only for write-barrier testing */
int IS_BYTES(SEXP x);
void SET_BYTES(SEXP x);
int IS_LATIN1(SEXP x);
void SET_LATIN1(SEXP x);
int IS_ASCII(SEXP x);
void SET_ASCII(SEXP x);
int IS_UTF8(SEXP x);
void SET_UTF8(SEXP x);
int ENC_KNOWN(SEXP x);
int SET_CACHED(SEXP x);
int IS_CACHED(SEXP x);
#endif
/* macros and declarations for managing CHARSXP cache */
# define CXHEAD(x) (x)
# define CXTAIL(x) ATTRIB(x)
SEXP (SET_CXTAIL)(SEXP x, SEXP y);
#include "Errormsg.h"
extern void R_ProcessEvents(void);
#ifdef Win32
extern void R_WaitEvent(void);
#endif
#ifdef R_USE_SIGNALS
#ifdef Win32
# include <psignal.h>
#else
# include <signal.h>
# include <setjmp.h>
#endif
#endif
#ifdef Unix
# define OSTYPE "unix"
# define FILESEP "/"
#endif /* Unix */
#ifdef Win32
# define OSTYPE "windows"
# define FILESEP "/"
#endif /* Win32 */
#ifdef HAVE_F77_UNDERSCORE
# define F77_SYMBOL(x) x ## _
# define F77_QSYMBOL(x) #x "_"
#else
# define F77_SYMBOL(x) x
# define F77_QSYMBOL(x) #x
#endif
/* Heap and Pointer Protection Stack Sizes. */
/* These headers are all required by C99.
However, we use types below such as uintptr_t which are optional in C11.
And on some older systems they were in inttypes.h but not stdint.h.
Up to 2.11.1 (r52035, May 2010) we had
#if !defined(HAVE_INTPTR_T) && !defined(intptr_t)
typedef long intptr_t;
#endif
#if !defined(HAVE_UINTPTR_T) && !defined(uintptr_t)
typedef unsigned long uintptr_t;
#endif
but size_t might be better.
*/
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
/* According to POSIX inttypes.h should include stdint.h,
but let's be sure. */
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#if defined HAVE_DECL_SIZE_MAX && HAVE_DECL_SIZE_MAX
typedef size_t R_size_t;
# define R_SIZE_T_MAX SIZE_MAX
#else
# error SIZE_MAX is required for C99
#endif
#define Mega 1048576. /* 1 Mega Byte := 2^20 (= 1048576) Bytes */
#define Giga 1073741824. /* 1 Giga Byte := 2^30 Bytes */
/* R_PPSSIZE The pointer protection stack size */
/* R_NSIZE The number of cons cells */
/* R_VSIZE The vector heap size in bytes */
/* These values are defaults and can be overridden in config.h
The maxima and minima are in ../main/startup.c */
#ifndef R_PPSSIZE
#define R_PPSSIZE 50000L
#endif
#ifndef R_NSIZE
#define R_NSIZE 350000L
#endif
#ifndef R_VSIZE
#define R_VSIZE 67108864L
#endif
/* some commonly needed headers */
#include <math.h>
#include <stdlib.h>
#include <string.h>
/* declare substitutions */
#if !defined(strdup) && defined(HAVE_DECL_STRDUP) && !HAVE_DECL_STRDUP
extern char *strdup(const char *s1);
#endif
#if !defined(strncascmp) && defined(HAVE_DECL_STRNCASECMP) && !HAVE_DECL_STRNCASECMP
extern int strncasecmp(const char *s1, const char *s2, size_t n);
#endif
/* Glibc manages to not define this in -pedantic -ansi */
#if defined(HAVE_PUTENV) && !defined(putenv) && defined(HAVE_DECL_PUTENV) && !HAVE_DECL_PUTENV
extern int putenv(char *string);
#endif
/* Maximal length in bytes of an entire path name.
POSIX has required this to be at least 255/256, and X/Open at least 1024.
Solaris has 1024, Linux glibc has 4192.
File names are limited to FILENAME_MAX bytes (usually the same as PATH_MAX)
or NAME_MAX (often 255/256).
*/
#if !defined(PATH_MAX)
# if defined(HAVE_SYS_PARAM_H)
# include <sys/param.h>
# endif
# if !defined(PATH_MAX)
# if defined(MAXPATHLEN)
/* Try BSD name */
# define PATH_MAX MAXPATHLEN
# elif defined(Win32)
/* seems this is now defined by MinGW to be 259, whereas FILENAME_MAX
and MAX_PATH are 260. It is not clear that this really is in bytes,
but might be chars for the Unicode interfaces.
260 is d:\ plus 256 chars plus nul. Some but not all API calls
allow filepaths of the form \\?\D:\very_long_path .
*/
# define PATH_MAX 260
# else
/* quite possibly unlimited, so we make this large, and test when used */
# define PATH_MAX 5000
# endif
# endif
#endif
#ifdef R_USE_SIGNALS
#ifdef HAVE_POSIX_SETJMP
# define SIGJMP_BUF sigjmp_buf
# define SIGSETJMP(x,s) sigsetjmp(x,s)
# define SIGLONGJMP(x,i) siglongjmp(x,i)
# define JMP_BUF sigjmp_buf
# define SETJMP(x) sigsetjmp(x,0)
# define LONGJMP(x,i) siglongjmp(x,i)
#else
# define SIGJMP_BUF jmp_buf
# define SIGSETJMP(x,s) setjmp(x)
# define SIGLONGJMP(x,i) longjmp(x,i)
# define JMP_BUF jmp_buf
# define SETJMP(x) setjmp(x)
# define LONGJMP(x,i) longjmp(x,i)
#endif
#endif
#define HSIZE 49157 /* The size of the hash table for symbols */
#define MAXIDSIZE 10000 /* Largest symbol size,
in bytes excluding terminator.
Was 256 prior to 2.13.0, now just a sanity check.
*/
/* The type of the do_xxxx functions. */
/* These are the built-in R functions. */
typedef SEXP (*CCODE)(SEXP, SEXP, SEXP, SEXP);
/* Information for Deparsing Expressions */
typedef enum {
PP_INVALID = 0,
PP_ASSIGN = 1,
PP_ASSIGN2 = 2,
PP_BINARY = 3,
PP_BINARY2 = 4,
PP_BREAK = 5,
PP_CURLY = 6,
PP_FOR = 7,
PP_FUNCALL = 8,
PP_FUNCTION = 9,
PP_IF = 10,
PP_NEXT = 11,
PP_PAREN = 12,
PP_RETURN = 13,
PP_SUBASS = 14,
PP_SUBSET = 15,
PP_WHILE = 16,
PP_UNARY = 17,
PP_DOLLAR = 18,
PP_FOREIGN = 19,
PP_REPEAT = 20
} PPkind;
typedef enum {
PREC_FN = 0,
PREC_EQ = 1,
PREC_LEFT = 2,
PREC_RIGHT = 3,
PREC_TILDE = 4,
PREC_OR = 5,
PREC_AND = 6,
PREC_NOT = 7,
PREC_COMPARE = 8,
PREC_SUM = 9,
PREC_PROD = 10,
PREC_PERCENT = 11,
PREC_COLON = 12,
PREC_SIGN = 13,
PREC_POWER = 14,
PREC_SUBSET = 15,
PREC_DOLLAR = 16,
PREC_NS = 17
} PPprec;
typedef struct {
PPkind kind; /* deparse kind */
PPprec precedence; /* operator precedence */
unsigned int rightassoc; /* right associative? */
} PPinfo;
/* The type definitions for the table of built-in functions. */
/* This table can be found in ../main/names.c */
typedef struct {
char *name; /* print name */
CCODE cfun; /* c-code address */
int code; /* offset within c-code */
int eval; /* evaluate args? */
int arity; /* function arity */
PPinfo gram; /* pretty-print info */
} FUNTAB;
#ifdef USE_RINTERNALS
/* There is much more in Rinternals.h, including function versions
* of the Promise and Hashing groups.
*/
/* Primitive Access Macros */
#define PRIMOFFSET(x) ((x)->u.primsxp.offset)
#define SET_PRIMOFFSET(x,v) (((x)->u.primsxp.offset)=(v))
#define PRIMFUN(x) (R_FunTab[(x)->u.primsxp.offset].cfun)
#define PRIMNAME(x) (R_FunTab[(x)->u.primsxp.offset].name)
#define PRIMVAL(x) (R_FunTab[(x)->u.primsxp.offset].code)
#define PRIMARITY(x) (R_FunTab[(x)->u.primsxp.offset].arity)
#define PPINFO(x) (R_FunTab[(x)->u.primsxp.offset].gram)
#define PRIMPRINT(x) (((R_FunTab[(x)->u.primsxp.offset].eval)/100)%10)
#define PRIMINTERNAL(x) (((R_FunTab[(x)->u.primsxp.offset].eval)%100)/10)
/* Promise Access Macros */
#define PRCODE(x) ((x)->u.promsxp.expr)
#define PRENV(x) ((x)->u.promsxp.env)
#define PRVALUE(x) ((x)->u.promsxp.value)
#define PRSEEN(x) ((x)->sxpinfo.gp)
#define SET_PRSEEN(x,v) (((x)->sxpinfo.gp)=(v))
/* Hashing Macros */
#define HASHASH(x) ((x)->sxpinfo.gp & HASHASH_MASK)
#define HASHVALUE(x) ((int) TRUELENGTH(x))
#define SET_HASHASH(x,v) ((v) ? (((x)->sxpinfo.gp) |= HASHASH_MASK) : \
(((x)->sxpinfo.gp) &= (~HASHASH_MASK)))
#define SET_HASHVALUE(x,v) SET_TRUELENGTH(x, ((int) (v)))
/* Vector Heap Structure */
typedef struct {
union {
SEXP backpointer;
double align;
} u;
} VECREC, *VECP;
/* Vector Heap Macros */
#define BACKPOINTER(v) ((v).u.backpointer)
#define BYTE2VEC(n) (((n)>0)?(((n)-1)/sizeof(VECREC)+1):0)
#define INT2VEC(n) (((n)>0)?(((n)*sizeof(int)-1)/sizeof(VECREC)+1):0)
#define FLOAT2VEC(n) (((n)>0)?(((n)*sizeof(double)-1)/sizeof(VECREC)+1):0)
#define COMPLEX2VEC(n) (((n)>0)?(((n)*sizeof(Rcomplex)-1)/sizeof(VECREC)+1):0)
#define PTR2VEC(n) (((n)>0)?(((n)*sizeof(SEXP)-1)/sizeof(VECREC)+1):0)
/* Bindings */
/* use the same bits (15 and 14) in symbols and bindings */
#define ACTIVE_BINDING_MASK (1<<15)
#define BINDING_LOCK_MASK (1<<14)
#define SPECIAL_BINDING_MASK (ACTIVE_BINDING_MASK | BINDING_LOCK_MASK)
#define IS_ACTIVE_BINDING(b) ((b)->sxpinfo.gp & ACTIVE_BINDING_MASK)
#define BINDING_IS_LOCKED(b) ((b)->sxpinfo.gp & BINDING_LOCK_MASK)
#define SET_ACTIVE_BINDING_BIT(b) ((b)->sxpinfo.gp |= ACTIVE_BINDING_MASK)
#define LOCK_BINDING(b) do { \
SEXP lb__b__ = b; \
if (! IS_ACTIVE_BINDING(lb__b__)) { \
if (TYPEOF(lb__b__) == SYMSXP) \
MARK_NOT_MUTABLE(SYMVALUE(lb__b__)); \
else \
MARK_NOT_MUTABLE(CAR(lb__b__)); \
} \
((lb__b__))->sxpinfo.gp |= BINDING_LOCK_MASK; \
} while (0)
#define UNLOCK_BINDING(b) ((b)->sxpinfo.gp &= (~BINDING_LOCK_MASK))
#define BASE_SYM_CACHED_MASK (1<<13)
#define SET_BASE_SYM_CACHED(b) ((b)->sxpinfo.gp |= BASE_SYM_CACHED_MASK)
#define UNSET_BASE_SYM_CACHED(b) ((b)->sxpinfo.gp &= (~BASE_SYM_CACHED_MASK))
#define BASE_SYM_CACHED(b) ((b)->sxpinfo.gp & BASE_SYM_CACHED_MASK)
#define SPECIAL_SYMBOL_MASK (1<<12)
#define SET_SPECIAL_SYMBOL(b) ((b)->sxpinfo.gp |= SPECIAL_SYMBOL_MASK)
#define UNSET_SPECIAL_SYMBOL(b) ((b)->sxpinfo.gp &= (~SPECIAL_SYMBOL_MASK))
#define IS_SPECIAL_SYMBOL(b) ((b)->sxpinfo.gp & SPECIAL_SYMBOL_MASK)
#define SET_NO_SPECIAL_SYMBOLS(b) ((b)->sxpinfo.gp |= SPECIAL_SYMBOL_MASK)
#define UNSET_NO_SPECIAL_SYMBOLS(b) ((b)->sxpinfo.gp &= (~SPECIAL_SYMBOL_MASK))
#define NO_SPECIAL_SYMBOLS(b) ((b)->sxpinfo.gp & SPECIAL_SYMBOL_MASK)
#else /* USE_RINTERNALS */
typedef struct VECREC *VECP;
int (PRIMOFFSET)(SEXP x);
void (SET_PRIMOFFSET)(SEXP x, int v);
#define PRIMFUN(x) (R_FunTab[PRIMOFFSET(x)].cfun)
#define PRIMNAME(x) (R_FunTab[PRIMOFFSET(x)].name)
#define PRIMVAL(x) (R_FunTab[PRIMOFFSET(x)].code)
#define PRIMARITY(x) (R_FunTab[PRIMOFFSET(x)].arity)
#define PPINFO(x) (R_FunTab[PRIMOFFSET(x)].gram)
#define PRIMPRINT(x) (((R_FunTab[PRIMOFFSET(x)].eval)/100)%10)
#define PRIMINTERNAL(x) (((R_FunTab[PRIMOFFSET(x)].eval)%100)/10)
Rboolean (IS_ACTIVE_BINDING)(SEXP b);
Rboolean (BINDING_IS_LOCKED)(SEXP b);
void (SET_ACTIVE_BINDING_BIT)(SEXP b);
void (LOCK_BINDING)(SEXP b);
void (UNLOCK_BINDING)(SEXP b);
void (SET_BASE_SYM_CACHED)(SEXP b);
void (UNSET_BASE_SYM_CACHED)(SEXP b);
Rboolean (BASE_SYM_CACHED)(SEXP b);
void (SET_SPECIAL_SYMBOL)(SEXP b);
void (UNSET_SPECIAL_SYMBOL)(SEXP b);
Rboolean (IS_SPECIAL_SYMBOL)(SEXP b);
void (SET_NO_SPECIAL_SYMBOLS)(SEXP b);
void (UNSET_NO_SPECIAL_SYMBOLS)(SEXP b);
Rboolean (NO_SPECIAL_SYMBOLS)(SEXP b);
#endif /* USE_RINTERNALS */
/* The byte code engine uses a typed stack. The typed stack's entries
consist of a tag and a union. An entry can represent a standard
SEXP value (tag = 0) or an unboxed scalar value. For now real,
integer, and logical values are supported. It would in principle be
possible to support complex scalars and short scalar strings, but
it isn't clear if this is worth while.
In addition to unboxed values the typed stack can hold partially
evaluated or incomplete allocated values. For now this is only used
for holding a short representation of an integer sequence as produce
by the colon operator, seq_len, or seq_along, and as consumed by
compiled 'for' loops. This could be used more extensively in the
future, though the ALTREP framework may be a better choice.
Allocating on the stack memory is also supported; this is currently
used for jump buffers.
*/
typedef struct {
int tag;
int flags;
union {
int ival;
double dval;
SEXP sxpval;
} u;
} R_bcstack_t;
# define PARTIALSXP_MASK (~255)
# define IS_PARTIAL_SXP_TAG(x) ((x) & PARTIALSXP_MASK)
# define RAWMEM_TAG 254
# define CACHESZ_TAG 253
#ifdef R_USE_SIGNALS
/* Stack entry for pending promises */
typedef struct RPRSTACK {
SEXP promise;
struct RPRSTACK *next;
} RPRSTACK;
/* Evaluation Context Structure */
typedef struct RCNTXT {
struct RCNTXT *nextcontext; /* The next context up the chain */
int callflag; /* The context "type" */
JMP_BUF cjmpbuf; /* C stack and register information */
int cstacktop; /* Top of the pointer protection stack */
int evaldepth; /* evaluation depth at inception */
SEXP promargs; /* Promises supplied to closure */
SEXP callfun; /* The closure called */
SEXP sysparent; /* environment the closure was called from */
SEXP call; /* The call that effected this context*/
SEXP cloenv; /* The environment */
SEXP conexit; /* Interpreted "on.exit" code */
void (*cend)(void *); /* C "on.exit" thunk */
void *cenddata; /* data for C "on.exit" thunk */
void *vmax; /* top of R_alloc stack */
int intsusp; /* interrupts are suspended */
int gcenabled; /* R_GCEnabled value */
int bcintactive; /* R_BCIntActive value */
SEXP bcbody; /* R_BCbody value */
void* bcpc; /* R_BCpc value */
SEXP handlerstack; /* condition handler stack */
SEXP restartstack; /* stack of available restarts */
struct RPRSTACK *prstack; /* stack of pending promises */
R_bcstack_t *nodestack;
R_bcstack_t *bcprottop;
SEXP srcref; /* The source line in effect */
int browserfinish; /* should browser finish this context without
stopping */
SEXP returnValue; /* only set during on.exit calls */
struct RCNTXT *jumptarget; /* target for a continuing jump */
int jumpmask; /* associated LONGJMP argument */
} RCNTXT, *context;
/* The Various Context Types.
* In general the type is a bitwise OR of the values below.
* Note that CTXT_LOOP is already the or of CTXT_NEXT and CTXT_BREAK.
* Only functions should have the third bit turned on;
* this allows us to move up the context stack easily
* with either RETURN's or GENERIC's or RESTART's.
* If you add a new context type for functions make sure
* CTXT_NEWTYPE & CTXT_FUNCTION > 0
*/
enum {
CTXT_TOPLEVEL = 0,
CTXT_NEXT = 1,
CTXT_BREAK = 2,
CTXT_LOOP = 3, /* break OR next target */
CTXT_FUNCTION = 4,
CTXT_CCODE = 8,
CTXT_RETURN = 12,
CTXT_BROWSER = 16,
CTXT_GENERIC = 20,
CTXT_RESTART = 32,
CTXT_BUILTIN = 64, /* used in profiling */
CTXT_UNWIND = 128
};
/*
TOP 0 0 0 0 0 0 = 0
NEX 1 0 0 0 0 0 = 1
BRE 0 1 0 0 0 0 = 2
LOO 1 1 0 0 0 0 = 3
FUN 0 0 1 0 0 0 = 4
CCO 0 0 0 1 0 0 = 8
BRO 0 0 0 0 1 0 = 16
RET 0 0 1 1 0 0 = 12
GEN 0 0 1 0 1 0 = 20
RES 0 0 0 0 0 0 1 = 32
BUI 0 0 0 0 0 0 0 1 = 64
*/
#define IS_RESTART_BIT_SET(flags) ((flags) & CTXT_RESTART)
#define SET_RESTART_BIT_ON(flags) (flags |= CTXT_RESTART)
#define SET_RESTART_BIT_OFF(flags) (flags &= ~CTXT_RESTART)
#endif
/* Miscellaneous Definitions */
#define streql(s, t) (!strcmp((s), (t)))
/* Arithmetic and Relation Operators */
typedef enum {
PLUSOP = 1,
MINUSOP,
TIMESOP,
DIVOP,
POWOP,
MODOP,
IDIVOP
} ARITHOP_TYPE;
typedef enum {
EQOP = 1,
NEOP,
LTOP,
LEOP,
GEOP,
GTOP
} RELOP_TYPE;
typedef enum {
MATPROD_DEFAULT = 1,
MATPROD_INTERNAL,
MATPROD_BLAS,
MATPROD_DEFAULT_SIMD /* experimental */
} MATPROD_TYPE;
/* File Handling */
/*
#define R_EOF 65535
*/
#define R_EOF -1
/*--- Global Variables ---------------------------------------------------- */
/* Defined and initialized in names.c (not main.c) :*/
#ifndef __R_Names__
extern
#endif
FUNTAB R_FunTab[]; /* Built in functions */
#include <R_ext/libextern.h>
#ifdef __MAIN__
# define INI_as(v) = v
#define extern0 attribute_hidden
#else
# define INI_as(v)
#define extern0 extern
#endif
LibExtern SEXP R_SrcfileSymbol; /* "srcfile" */
LibExtern SEXP R_SrcrefSymbol; /* "srcref" */
LibExtern Rboolean R_interrupts_suspended INI_as(FALSE);
LibExtern int R_interrupts_pending INI_as(0);
/* R Home Directory */
LibExtern char *R_Home; /* Root of the R tree */
/* Memory Management */
extern0 R_size_t R_NSize INI_as(R_NSIZE);/* Size of cons cell heap */
extern0 R_size_t R_VSize INI_as(R_VSIZE);/* Size of the vector heap */
extern0 int R_GCEnabled INI_as(1);
extern0 int R_in_gc INI_as(0);
extern0 int R_BCIntActive INI_as(0); /* bcEval called more recently than
eval */
extern0 void* R_BCpc INI_as(NULL);/* current byte code instruction */
extern0 SEXP R_BCbody INI_as(NULL); /* current byte code object */
extern0 SEXP R_NHeap; /* Start of the cons cell heap */
extern0 SEXP R_FreeSEXP; /* Cons cell free list */
extern0 R_size_t R_Collected; /* Number of free cons cells (after gc) */
extern0 int R_Is_Running; /* for Windows memory manager */
/* The Pointer Protection Stack */
LibExtern int R_PPStackSize INI_as(R_PPSSIZE); /* The stack size (elements) */
LibExtern int R_PPStackTop; /* The top of the stack */
LibExtern SEXP* R_PPStack; /* The pointer protection stack */
/* Evaluation Environment */
extern0 SEXP R_CurrentExpr; /* Currently evaluating expression */
extern0 SEXP R_ReturnedValue; /* Slot for return-ing values */
extern0 SEXP* R_SymbolTable; /* The symbol table */
#ifdef R_USE_SIGNALS
extern0 RCNTXT R_Toplevel; /* Storage for the toplevel context */
extern0 RCNTXT* R_ToplevelContext; /* The toplevel context */
LibExtern RCNTXT* R_GlobalContext; /* The global context */
extern0 RCNTXT* R_SessionContext; /* The session toplevel context */
extern0 RCNTXT* R_ExitContext; /* The active context for on.exit processing */
#endif
extern Rboolean R_Visible; /* Value visibility flag */
extern0 int R_EvalDepth INI_as(0); /* Evaluation recursion depth */
extern0 int R_BrowseLines INI_as(0); /* lines/per call in browser :
* options(deparse.max.lines) */
extern0 int R_Expressions INI_as(5000); /* options(expressions) */
extern0 int R_Expressions_keep INI_as(5000);/* options(expressions) */
extern0 Rboolean R_KeepSource INI_as(FALSE); /* options(keep.source) */
extern0 Rboolean R_CBoundsCheck INI_as(FALSE); /* options(CBoundsCheck) */
extern0 MATPROD_TYPE R_Matprod INI_as(MATPROD_DEFAULT); /* options(matprod) */
extern0 int R_WarnLength INI_as(1000); /* Error/warning max length */
extern0 int R_nwarnings INI_as(50);
/* C stack checking */
extern uintptr_t R_CStackLimit INI_as((uintptr_t)-1); /* C stack limit */
extern uintptr_t R_OldCStackLimit INI_as((uintptr_t)0); /* Old value while
handling overflow */
extern uintptr_t R_CStackStart INI_as((uintptr_t)-1); /* Initial stack address */
/* Default here is for Windows: set from configure in src/unix/system.c */
extern int R_CStackDir INI_as(1); /* C stack direction */
#ifdef R_USE_SIGNALS
extern0 struct RPRSTACK *R_PendingPromises INI_as(NULL); /* Pending promise stack */
#endif
/* File Input/Output */
LibExtern Rboolean R_Interactive INI_as(TRUE); /* TRUE during interactive use*/
extern0 Rboolean R_Quiet INI_as(FALSE); /* Be as quiet as possible */
extern Rboolean R_NoEcho INI_as(FALSE); /* do not echo R code */
extern0 Rboolean R_Verbose INI_as(FALSE); /* Be verbose */
/* extern int R_Console; */ /* Console active flag */
/* IoBuffer R_ConsoleIob; : --> ./IOStuff.h */
/* R_Consolefile is used in the internet module */
extern FILE* R_Consolefile INI_as(NULL); /* Console output file */
extern FILE* R_Outputfile INI_as(NULL); /* Output file */
extern0 int R_ErrorCon INI_as(2); /* Error connection */
LibExtern char *R_TempDir INI_as(NULL); /* Name of per-session dir */
extern0 char *Sys_TempDir INI_as(NULL); /* Name of per-session dir
if set by R itself */
extern0 char R_StdinEnc[31] INI_as(""); /* Encoding assumed for stdin */
/* Objects Used In Parsing */
LibExtern int R_ParseError INI_as(0); /* Line where parse error occurred */
extern0 int R_ParseErrorCol; /* Column of start of token where parse error occurred */
extern0 SEXP R_ParseErrorFile; /* Source file where parse error was seen. Either a
STRSXP or (when keeping srcrefs) a SrcFile ENVSXP */
#define PARSE_ERROR_SIZE 256 /* Parse error messages saved here */
LibExtern char R_ParseErrorMsg[PARSE_ERROR_SIZE] INI_as("");
#define PARSE_CONTEXT_SIZE 256 /* Recent parse context kept in a circular buffer */
LibExtern char R_ParseContext[PARSE_CONTEXT_SIZE] INI_as("");
LibExtern int R_ParseContextLast INI_as(0); /* last character in context buffer */
LibExtern int R_ParseContextLine; /* Line in file of the above */
/* Image Dump/Restore */
extern int R_DirtyImage INI_as(0); /* Current image dirty */
/* History */
LibExtern char *R_HistoryFile; /* Name of the history file */
LibExtern int R_HistorySize; /* Size of the history file */
LibExtern int R_RestoreHistory; /* restore the history file? */
extern void R_setupHistory(void);
/* Warnings/Errors */
extern0 int R_CollectWarnings INI_as(0); /* the number of warnings */
extern0 SEXP R_Warnings; /* the warnings and their calls */
extern0 int R_ShowErrorMessages INI_as(1); /* show error messages? */
extern0 SEXP R_HandlerStack; /* Condition handler stack */
extern0 SEXP R_RestartStack; /* Stack of available restarts */
extern0 Rboolean R_warn_partial_match_args INI_as(FALSE);
extern0 Rboolean R_warn_partial_match_dollar INI_as(FALSE);
extern0 Rboolean R_warn_partial_match_attr INI_as(FALSE);
extern0 Rboolean R_ShowWarnCalls INI_as(FALSE);
extern0 Rboolean R_ShowErrorCalls INI_as(FALSE);
extern0 int R_NShowCalls INI_as(50);
LibExtern Rboolean utf8locale INI_as(FALSE); /* is this a UTF-8 locale? */
LibExtern Rboolean mbcslocale INI_as(FALSE); /* is this a MBCS locale? */
extern0 Rboolean latin1locale INI_as(FALSE); /* is this a Latin-1 locale? */
#ifdef Win32
LibExtern unsigned int localeCP INI_as(1252); /* the locale's codepage */
LibExtern unsigned int systemCP INI_as(437); /* the ANSI codepage, GetACP */
extern0 Rboolean WinUTF8out INI_as(FALSE); /* Use UTF-8 for output */
extern0 void WinCheckUTF8(void);
#endif
extern char* OutDec INI_as("."); /* decimal point used for output */
extern0 Rboolean R_DisableNLinBrowser INI_as(FALSE);
extern0 char R_BrowserLastCommand INI_as('n');
/* Initialization of the R environment when it is embedded */
extern int Rf_initEmbeddedR(int argc, char **argv);
/* GUI type */
extern char *R_GUIType INI_as("unknown");
extern Rboolean R_isForkedChild INI_as(FALSE); /* was this forked? */
extern0 double cpuLimit INI_as(-1.0);
extern0 double cpuLimit2 INI_as(-1.0);
extern0 double cpuLimitValue INI_as(-1.0);
extern0 double elapsedLimit INI_as(-1.0);
extern0 double elapsedLimit2 INI_as(-1.0);
extern0 double elapsedLimitValue INI_as(-1.0);
void resetTimeLimits(void);
#define R_BCNODESTACKSIZE 200000
LibExtern R_bcstack_t *R_BCNodeStackTop, *R_BCNodeStackEnd;
extern0 R_bcstack_t *R_BCNodeStackBase;
extern0 R_bcstack_t *R_BCProtTop;
extern0 int R_jit_enabled INI_as(0); /* has to be 0 during R startup */
extern0 int R_compile_pkgs INI_as(0);
extern0 int R_check_constants INI_as(0);
extern0 int R_disable_bytecode INI_as(0);
extern SEXP R_cmpfun1(SEXP); /* unconditional fresh compilation */
extern void R_init_jit_enabled(void);
extern void R_initAssignSymbols(void);
#ifdef R_USE_SIGNALS
extern SEXP R_findBCInterpreterSrcref(RCNTXT*);
#endif
extern SEXP R_getCurrentSrcref();
extern SEXP R_getBCInterpreterExpression();
void R_BCProtReset(R_bcstack_t *);
LibExtern int R_num_math_threads INI_as(1);
LibExtern int R_max_num_math_threads INI_as(1);
/* Pointer type and utilities for dispatch in the methods package */
typedef SEXP (*R_stdGen_ptr_t)(SEXP, SEXP, SEXP); /* typedef */
//R_stdGen_ptr_t R_get_standardGeneric_ptr(void); /* get method */
R_stdGen_ptr_t R_set_standardGeneric_ptr(R_stdGen_ptr_t, SEXP); /* set method */
LibExtern SEXP R_MethodsNamespace;
SEXP R_deferred_default_method(void);
SEXP R_set_prim_method(SEXP fname, SEXP op, SEXP code_vec, SEXP fundef,
SEXP mlist);
SEXP do_set_prim_method(SEXP op, const char *code_string, SEXP fundef,
SEXP mlist);
void R_set_quick_method_check(R_stdGen_ptr_t);
SEXP R_primitive_methods(SEXP op);
SEXP R_primitive_generic(SEXP op);
/* smallest decimal exponent, needed in format.c, set in Init_R_Machine */
extern0 int R_dec_min_exponent INI_as(-308);
/* structure for caching machine accuracy values */
typedef struct {
int ibeta, it, irnd, ngrd, machep, negep, iexp, minexp, maxexp;
double eps, epsneg, xmin, xmax;
} AccuracyInfo;
LibExtern AccuracyInfo R_AccuracyInfo;
extern unsigned int max_contour_segments INI_as(25000);
/* used in package utils */
extern Rboolean known_to_be_latin1 INI_as(FALSE);
extern0 Rboolean known_to_be_utf8 INI_as(FALSE);
/* pre-allocated boolean values */
LibExtern SEXP R_TrueValue INI_as(NULL);
LibExtern SEXP R_FalseValue INI_as(NULL);
LibExtern SEXP R_LogicalNAValue INI_as(NULL);
/* for PCRE as from R 3.4.0 */
extern0 Rboolean R_PCRE_use_JIT INI_as(TRUE);
#ifdef HAVE_PCRE2
extern0 int R_PCRE_study INI_as(-2);
#else
extern0 int R_PCRE_study INI_as(10);
#endif
extern0 int R_PCRE_limit_recursion;
#ifdef __MAIN__
# undef extern
# undef extern0
# undef LibExtern
#endif
#undef INI_as
#define checkArity(a,b) Rf_checkArityCall(a,b,call)
/*--- FUNCTIONS ------------------------------------------------------ */
# define allocCharsxp Rf_allocCharsxp
# define asVecSize Rf_asVecSize
# define asXLength Rf_asXLength
# define begincontext Rf_begincontext
# define BindDomain Rf_BindDomain
# define check_stack_balance Rf_check_stack_balance
# define check1arg Rf_check1arg
# define CheckFormals Rf_CheckFormals
# define CleanEd Rf_CleanEd
# define CoercionWarning Rf_CoercionWarning
# define ComplexFromInteger Rf_ComplexFromInteger
# define ComplexFromLogical Rf_ComplexFromLogical
# define ComplexFromReal Rf_ComplexFromReal
# define ComplexFromString Rf_ComplexFromString
# define copyMostAttribNoTs Rf_copyMostAttribNoTs
# define createS3Vars Rf_createS3Vars
# define currentTime Rf_currentTime
# define CustomPrintValue Rf_CustomPrintValue
# define DataFrameClass Rf_DataFrameClass
# define ddfindVar Rf_ddfindVar
# define deparse1 Rf_deparse1
# define deparse1m Rf_deparse1m
# define deparse1w Rf_deparse1w
# define deparse1line Rf_deparse1line
# define deparse1s Rf_deparse1s
# define DispatchGroup Rf_DispatchGroup
# define DispatchOrEval Rf_DispatchOrEval
# define DispatchAnyOrEval Rf_DispatchAnyOrEval
# define dynamicfindVar Rf_dynamicfindVar
# define EncodeChar Rf_EncodeChar
# define EncodeRaw Rf_EncodeRaw
# define EncodeReal2 Rf_EncodeReal2
# define EncodeString Rf_EncodeString
# define EnsureString Rf_EnsureString
# define endcontext Rf_endcontext
# define errorcall_cpy Rf_errorcall_cpy
# define ErrorMessage Rf_ErrorMessage
# define evalList Rf_evalList
# define evalListKeepMissing Rf_evalListKeepMissing
# define factorsConform Rf_factorsConform
# define findcontext Rf_findcontext
# define findVar1 Rf_findVar1
# define FrameClassFix Rf_FrameClassFix
# define framedepth Rf_framedepth
# define frameSubscript Rf_frameSubscript
# define get1index Rf_get1index
# define GetOptionCutoff Rf_GetOptionCutoff
# define getVar Rf_getVar
# define getVarInFrame Rf_getVarInFrame
# define InitArithmetic Rf_InitArithmetic
# define InitConnections Rf_InitConnections
# define InitEd Rf_InitEd
# define InitFunctionHashing Rf_InitFunctionHashing
# define InitBaseEnv Rf_InitBaseEnv
# define InitGlobalEnv Rf_InitGlobalEnv
# define InitGraphics Rf_InitGraphics
# define InitMemory Rf_InitMemory
# define InitNames Rf_InitNames
# define InitOptions Rf_InitOptions
# define InitStringHash Rf_InitStringHash
# define InitS3DefaultTypes Rf_InitS3DefaultTypes
# define InitTempDir Rf_InitTempDir
# define InitTypeTables Rf_InitTypeTables
# define initStack Rf_initStack
# define IntegerFromComplex Rf_IntegerFromComplex
# define IntegerFromLogical Rf_IntegerFromLogical
# define IntegerFromReal Rf_IntegerFromReal
# define IntegerFromString Rf_IntegerFromString
# define internalTypeCheck Rf_internalTypeCheck
# define isValidName Rf_isValidName
//# define installTrChar Rf_installTrChar
# define ItemName Rf_ItemName
# define jump_to_toplevel Rf_jump_to_toplevel
# define KillAllDevices Rf_KillAllDevices
# define levelsgets Rf_levelsgets
# define LogicalFromComplex Rf_LogicalFromComplex
# define LogicalFromInteger Rf_LogicalFromInteger
# define LogicalFromReal Rf_LogicalFromReal
# define LogicalFromString Rf_LogicalFromString
# define mainloop Rf_mainloop
# define makeSubscript Rf_makeSubscript
# define markKnown Rf_markKnown
# define mat2indsub Rf_mat2indsub
# define matchArg Rf_matchArg
# define matchArgExact Rf_matchArgExact
# define matchArgs_NR Rf_matchArgs_NR
# define matchArgs_RC Rf_matchArgs_RC
# define matchPar Rf_matchPar
# define Mbrtowc Rf_mbrtowc
# define mbtoucs Rf_mbtoucs
# define mbcsToUcs2 Rf_mbcsToUcs2
# define memtrace_report Rf_memtrace_report
# define mkCLOSXP Rf_mkCLOSXP
# define mkFalse Rf_mkFalse
# define mkPROMISE Rf_mkPROMISE
# define mkQUOTE Rf_mkQUOTE
# define mkSYMSXP Rf_mkSYMSXP
# define mkTrue Rf_mkTrue
# define NewEnvironment Rf_NewEnvironment
# define OneIndex Rf_OneIndex
# define onintr Rf_onintr
# define onintrNoResume Rf_onintrNoResume
# define onsigusr1 Rf_onsigusr1
# define onsigusr2 Rf_onsigusr2
# define parse Rf_parse
# define patchArgsByActuals Rf_patchArgsByActuals
# define PrintInit Rf_PrintInit
# define PrintDefaults Rf_PrintDefaults