Branch data Line data Source code
1 : : #ifndef FLISP_H
2 : : #define FLISP_H
3 : :
4 : : #include <setjmp.h>
5 : : #include <stdint.h>
6 : :
7 : : #include "platform.h"
8 : : #include "libsupport.h"
9 : : #include "utils.h"
10 : : #include "bitvector.h"
11 : : #include "timefuncs.h"
12 : : #include "strtod.h"
13 : : #include "dirpath.h"
14 : : #include "hashing.h"
15 : : #include "ptrhash.h"
16 : : #include "htable.h"
17 : : #include "uv.h"
18 : :
19 : : //#define MEMDEBUG
20 : : //#define MEMDEBUG2
21 : :
22 : : typedef uintptr_t value_t;
23 : : typedef int_t fixnum_t;
24 : : #if NBITS==64
25 : : #define T_FIXNUM T_INT64
26 : : #define labs llabs
27 : : #else
28 : : #define T_FIXNUM T_INT32
29 : : #endif
30 : :
31 : : #ifdef __cplusplus
32 : : extern "C" {
33 : : #endif
34 : : typedef struct _fl_context_t fl_context_t;
35 : : typedef struct {
36 : : value_t car;
37 : : value_t cdr;
38 : : } cons_t;
39 : :
40 : : typedef struct _symbol_t {
41 : : uintptr_t flags;
42 : : value_t binding; // global value binding
43 : : struct _fltype_t *type;
44 : : uint32_t hash;
45 : : void *dlcache; // dlsym address
46 : : // below fields are private
47 : : struct _symbol_t *left;
48 : : struct _symbol_t *right;
49 : : JL_ATTRIBUTE_ALIGN_PTRSIZE(char name[]);
50 : : } symbol_t;
51 : :
52 : : typedef struct {
53 : : value_t isconst;
54 : : value_t binding; // global value binding
55 : : struct _fltype_t *type;
56 : : uint32_t id;
57 : : } gensym_t;
58 : :
59 : : #define TAG_NUM 0x0
60 : : #define TAG_CPRIM 0x1
61 : : #define TAG_FUNCTION 0x2
62 : : #define TAG_VECTOR 0x3
63 : : #define TAG_NUM1 0x4
64 : : #define TAG_CVALUE 0x5
65 : : #define TAG_SYM 0x6
66 : : #define TAG_CONS 0x7
67 : : #define UNBOUND ((value_t)0x1) // an invalid value
68 : : #define TAG_FWD UNBOUND
69 : : #define tag(x) ((x)&0x7)
70 : : #define ptr(x) ((void*)((x)&(~(value_t)0x7)))
71 : : #define tagptr(p,t) (((value_t)(p)) | (t))
72 : : #define fixnum(x) ((value_t)(((uintptr_t)(x))<<2))
73 : : #define numval(x) (((fixnum_t)(x))>>2)
74 : : #if NBITS==64
75 : : #define fits_fixnum(x) (((x)>>61) == 0 || (~((x)>>61)) == 0)
76 : : #else
77 : : #define fits_fixnum(x) (((x)>>29) == 0 || (~((x)>>29)) == 0)
78 : : #endif
79 : : #define fits_bits(x,b) (((x)>>(b-1)) == 0 || (~((x)>>(b-1))) == 0)
80 : : #define uintval(x) (((unsigned int)(x))>>3)
81 : : #define builtin(n) tagptr((((int)n)<<3), TAG_FUNCTION)
82 : : #define iscons(x) (tag(x) == TAG_CONS)
83 : : #define issymbol(x) (tag(x) == TAG_SYM)
84 : : #define isfixnum(x) (((x)&3) == TAG_NUM)
85 : : #define bothfixnums(x,y) ((((x)|(y))&3) == TAG_NUM)
86 : : #define isbuiltin(x) ((tag(x) == TAG_FUNCTION) && uintval(x) <= OP_ASET)
87 : : #define isvector(x) (tag(x) == TAG_VECTOR)
88 : : #define iscvalue(x) (tag(x) == TAG_CVALUE)
89 : : #define iscprim(x) (tag(x) == TAG_CPRIM)
90 : : #define selfevaluating(x) (tag(x)<6)
91 : : // comparable with ==
92 : : #define eq_comparable(a,b) (!(((a)|(b))&1))
93 : : #define eq_comparablep(a) (!((a)&1))
94 : : // doesn't lead to other values
95 : : #define leafp(a) (((a)&3) != 3)
96 : :
97 : : #define isforwarded(v) (((value_t*)ptr(v))[0] == TAG_FWD)
98 : : #define forwardloc(v) (((value_t*)ptr(v))[1])
99 : : #define forward(v,to) do { (((value_t*)ptr(v))[0] = TAG_FWD); \
100 : : (((value_t*)ptr(v))[1] = to); } while (0)
101 : :
102 : : #define vector_size(v) (((size_t*)ptr(v))[0]>>2)
103 : : #define vector_setsize(v,n) (((size_t*)ptr(v))[0] = ((n)<<2))
104 : : #define vector_elt(v,i) (((value_t*)ptr(v))[1+(i)])
105 : : #define vector_grow_amt(x) ((x)<8 ? 5 : 6*((x)>>3))
106 : : // functions ending in _ are unsafe, faster versions
107 : : #define car_(v) (((cons_t*)ptr(v))->car)
108 : : #define cdr_(v) (((cons_t*)ptr(v))->cdr)
109 : : #define car(fl_ctx, v) (tocons(fl_ctx, (v),"car")->car)
110 : : #define cdr(fl_ctx, v) (tocons(fl_ctx, (v),"cdr")->cdr)
111 : : #define fn_bcode(f) (((value_t*)ptr(f))[0])
112 : : #define fn_vals(f) (((value_t*)ptr(f))[1])
113 : : #define fn_env(f) (((value_t*)ptr(f))[2])
114 : : #define fn_name(f) (((value_t*)ptr(f))[3])
115 : :
116 : : #define set(s, v) (((symbol_t*)ptr(s))->binding = (v))
117 : : #define setc(s, v) do { ((symbol_t*)ptr(s))->flags |= 1; \
118 : : ((symbol_t*)ptr(s))->binding = (v); } while (0)
119 : : #define isconstant(s) ((s)->flags&0x1)
120 : : #define iskeyword(s) ((s)->flags&0x2)
121 : : #define symbol_value(s) (((symbol_t*)ptr(s))->binding)
122 : : #ifdef MEMDEBUG2
123 : : #define ismanaged(ctx, v) (!issymbol(v) && !isfixnum(v) && ((v)>(N_OPCODES<<3)) && !iscbuiltin(ctx, v))
124 : : #else
125 : : #define ismanaged(ctx, v) ((((unsigned char*)ptr(v)) >= ctx->fromspace) && \
126 : : (((unsigned char*)ptr(v)) < ctx->fromspace + ctx->heapsize))
127 : : #endif
128 : : #define isgensym(ctx, x) (issymbol(x) && ismanaged(ctx, x))
129 : :
130 : : #define isfunction(x) (tag(x) == TAG_FUNCTION && (x) > (N_BUILTINS<<3))
131 : : #define isclosure(x) isfunction(x)
132 : : #define iscbuiltin(ctx, x) (iscvalue(x) && (cv_class((cvalue_t*)ptr(x))==ctx->builtintype))
133 : :
134 : : void fl_gc_handle(fl_context_t *fl_ctx, value_t *pv) JL_NOTSAFEPOINT;
135 : : void fl_free_gc_handles(fl_context_t *fl_ctx, uint32_t n) JL_NOTSAFEPOINT;
136 : :
137 : : #include "opcodes.h"
138 : :
139 : : // utility for iterating over all arguments in a builtin
140 : : // i=index, i0=start index, arg = var for each arg, args = arg array
141 : : // assumes "nargs" is the argument count
142 : : #define FOR_ARGS(i, i0, arg, args) \
143 : : for(i=i0; ((size_t)i)<nargs && ((arg=args[i]) || 1); i++)
144 : :
145 : : #define N_BUILTINS ((int)N_OPCODES)
146 : :
147 : : #define FL_UNSPECIFIED(fl_ctx) fl_ctx->T
148 : :
149 : : /* read, eval, print main entry points */
150 : : value_t fl_read_sexpr(fl_context_t *fl_ctx, value_t f);
151 : : void fl_print(fl_context_t *fl_ctx, ios_t *f, value_t v);
152 : : value_t fl_toplevel_eval(fl_context_t *fl_ctx, value_t expr);
153 : : value_t fl_apply(fl_context_t *fl_ctx, value_t f, value_t l) JL_NOTSAFEPOINT;
154 : : value_t fl_applyn(fl_context_t *fl_ctx, uint32_t n, value_t f, ...) JL_NOTSAFEPOINT;
155 : :
156 : : /* object model manipulation */
157 : : value_t fl_cons(fl_context_t *fl_ctx, value_t a, value_t b) JL_NOTSAFEPOINT;
158 : : value_t fl_list2(fl_context_t *fl_ctx, value_t a, value_t b) JL_NOTSAFEPOINT;
159 : : value_t fl_listn(fl_context_t *fl_ctx, size_t n, ...) JL_NOTSAFEPOINT;
160 : : value_t symbol(fl_context_t *fl_ctx, const char *str) JL_NOTSAFEPOINT;
161 : : char *symbol_name(fl_context_t *fl_ctx, value_t v);
162 : : int fl_is_keyword_name(const char *str, size_t len);
163 : : value_t alloc_vector(fl_context_t *fl_ctx, size_t n, int init);
164 : : size_t llength(value_t v);
165 : : value_t fl_compare(fl_context_t *fl_ctx, value_t a, value_t b); // -1, 0, or 1
166 : : value_t fl_equal(fl_context_t *fl_ctx, value_t a, value_t b); // T or nil
167 : : int equal_lispvalue(fl_context_t *fl_ctx, value_t a, value_t b);
168 : : uintptr_t hash_lispvalue(fl_context_t *fl_ctx, value_t a);
169 : : int isnumtok_base(fl_context_t *fl_ctx, char *tok, value_t *pval, int base);
170 : :
171 : : /* safe casts */
172 : : cons_t *tocons(fl_context_t *fl_ctx, value_t v, const char *fname);
173 : : symbol_t *tosymbol(fl_context_t *fl_ctx, value_t v, const char *fname);
174 : : fixnum_t tofixnum(fl_context_t *fl_ctx, value_t v, const char *fname);
175 : : char *tostring(fl_context_t *fl_ctx, value_t v, const char *fname);
176 : :
177 : : /* error handling */
178 : : #if defined(_OS_WINDOWS_)
179 : : #define fl_jmp_buf jmp_buf
180 : : #if defined(_COMPILER_GCC_)
181 : : int __attribute__ ((__nothrow__,__returns_twice__)) (jl_setjmp)(jmp_buf _Buf);
182 : : __declspec(noreturn) __attribute__ ((__nothrow__)) void (jl_longjmp)(jmp_buf _Buf, int _Value);
183 : : #else
184 : : int (jl_setjmp)(jmp_buf _Buf);
185 : : void (jl_longjmp)(jmp_buf _Buf, int _Value);
186 : : #endif
187 : : #define fl_setjmp(a) (jl_setjmp)((a))
188 : : #define fl_longjmp(a, b) (jl_longjmp)((a), (b))
189 : : #else // !_OS_WINDOWS_
190 : : #define fl_jmp_buf sigjmp_buf
191 : : #define fl_setjmp(a) sigsetjmp((a), 0)
192 : : #define fl_longjmp(a, b) siglongjmp((a), (b))
193 : : #endif
194 : :
195 : : typedef struct _ectx_t {
196 : : fl_jmp_buf buf;
197 : : uint32_t sp;
198 : : uint32_t frame;
199 : : uint32_t ngchnd;
200 : : void *rdst;
201 : : struct _ectx_t *prev;
202 : : } fl_exception_context_t;
203 : :
204 : : #define FL_TRY_EXTERN(fl_ctx) \
205 : : fl_exception_context_t _ctx; int l__tr, l__ca; \
206 : : fl_savestate(fl_ctx, &_ctx); fl_ctx->exc_ctx = &_ctx; \
207 : : if (!fl_setjmp(_ctx.buf)) \
208 : : for (l__tr=1; l__tr; l__tr=0, (void)(fl_ctx->exc_ctx=fl_ctx->exc_ctx->prev))
209 : :
210 : : #define FL_CATCH_EXTERN(fl_ctx) \
211 : : else \
212 : : for(l__ca=1; l__ca; l__ca=0, fl_restorestate(fl_ctx, &_ctx))
213 : :
214 : : #if defined(_OS_WINDOWS_)
215 : : __declspec(noreturn) void lerrorf(fl_context_t *fl_ctx, value_t e, const char *format, ...) JL_NOTSAFEPOINT;
216 : : __declspec(noreturn) void lerror(fl_context_t *fl_ctx, value_t e, const char *msg) JL_NOTSAFEPOINT;
217 : : __declspec(noreturn) void fl_raise(fl_context_t *fl_ctx, value_t e);
218 : : __declspec(noreturn) void type_error(fl_context_t *fl_ctx, const char *fname, const char *expected, value_t got);
219 : : __declspec(noreturn) void bounds_error(fl_context_t *fl_ctx, const char *fname, value_t arr, value_t ind);
220 : : #else
221 : : void lerrorf(fl_context_t *fl_ctx, value_t e, const char *format, ...) __attribute__ ((__noreturn__)) JL_NOTSAFEPOINT;
222 : : void lerror(fl_context_t *fl_ctx, value_t e, const char *msg) __attribute__((__noreturn__)) JL_NOTSAFEPOINT;
223 : : void fl_raise(fl_context_t *fl_ctx, value_t e) __attribute__ ((__noreturn__));
224 : : void type_error(fl_context_t *fl_ctx, const char *fname, const char *expected, value_t got) __attribute__ ((__noreturn__));
225 : : void bounds_error(fl_context_t *fl_ctx, const char *fname, value_t arr, value_t ind) __attribute__ ((__noreturn__));
226 : : #endif
227 : :
228 : : void fl_savestate(fl_context_t *fl_ctx, fl_exception_context_t *_ctx);
229 : : void fl_restorestate(fl_context_t *fl_ctx, fl_exception_context_t *_ctx);
230 : :
231 : : typedef struct {
232 : : void (*print)(fl_context_t *fl_ctx, value_t self, ios_t *f);
233 : : void (*relocate)(fl_context_t *fl_ctx, value_t oldv, value_t newv);
234 : : void (*finalize)(fl_context_t *fl_ctx, value_t self);
235 : : void (*print_traverse)(fl_context_t *fl_ctx, value_t self);
236 : : } cvtable_t;
237 : :
238 : : /* functions needed to implement the value interface (cvtable_t) */
239 : : value_t relocate_lispvalue(fl_context_t *fl_ctx, value_t v);
240 : : void print_traverse(fl_context_t *fl_ctx, value_t v);
241 : : void fl_print_chr(fl_context_t *fl_ctx, char c, ios_t *f);
242 : : void fl_print_str(fl_context_t *fl_ctx, const char *s, ios_t *f);
243 : : void fl_print_child(fl_context_t *fl_ctx, ios_t *f, value_t v);
244 : :
245 : : typedef int (*cvinitfunc_t)(fl_context_t *fl_ctx, struct _fltype_t*, value_t, void*);
246 : :
247 : : typedef struct _fltype_t {
248 : : value_t type;
249 : : numerictype_t numtype;
250 : : size_t size;
251 : : size_t elsz;
252 : : const cvtable_t *vtable;
253 : : struct _fltype_t *eltype; // for arrays
254 : : struct _fltype_t *artype; // (array this)
255 : : int marked;
256 : : cvinitfunc_t init;
257 : : } fltype_t;
258 : :
259 : : JL_EXTENSION typedef struct {
260 : : fltype_t *type;
261 : : void *data;
262 : : size_t len; // length of *data in bytes
263 : : union {
264 : : value_t parent; // optional
265 : : char _space[1]; // variable size
266 : : };
267 : : } cvalue_t;
268 : :
269 : : #define CVALUE_NWORDS 4
270 : :
271 : : typedef struct {
272 : : fltype_t *type;
273 : : char _space[1];
274 : : } cprim_t;
275 : :
276 : : typedef struct {
277 : : value_t bcode;
278 : : value_t vals;
279 : : value_t env;
280 : : value_t name;
281 : : } function_t;
282 : :
283 : : #define CPRIM_NWORDS 2
284 : : #define MAX_INL_SIZE 384
285 : :
286 : : #define CV_OWNED_BIT 0x1
287 : : #define CV_PARENT_BIT 0x2
288 : : #define owned(cv) ((uintptr_t)(cv)->type & CV_OWNED_BIT)
289 : : #define hasparent(cv) ((uintptr_t)(cv)->type & CV_PARENT_BIT)
290 : : #define isinlined(cv) ((cv)->data == &(cv)->_space[0])
291 : : #define cv_class(cv) ((fltype_t*)(((uintptr_t)(cv)->type)&~3))
292 : : #define cv_len(cv) ((cv)->len)
293 : : #define cv_type(cv) (cv_class(cv)->type)
294 : : #define cv_data(cv) ((cv)->data)
295 : : #define cv_isstr(fl_ctx, cv) (cv_class(cv)->eltype == fl_ctx->bytetype)
296 : : #define cv_isPOD(cv) (cv_class(cv)->init != NULL)
297 : :
298 : : #define cvalue_data(v) cv_data((cvalue_t*)ptr(v))
299 : : #define cvalue_len(v) cv_len((cvalue_t*)ptr(v))
300 : : #define value2c(type, v) ((type)cv_data((cvalue_t*)ptr(v)))
301 : :
302 : : #define valid_numtype(v) ((v) < N_NUMTYPES)
303 : : #define cp_class(cp) ((cp)->type)
304 : : #define cp_type(cp) (cp_class(cp)->type)
305 : : #define cp_numtype(cp) (cp_class(cp)->numtype)
306 : : #define cp_data(cp) (&(cp)->_space[0])
307 : :
308 : : // WARNING: multiple evaluation!
309 : : #define cptr(v) \
310 : : (iscprim(v) ? cp_data((cprim_t*)ptr(v)) : cv_data((cvalue_t*)ptr(v)))
311 : :
312 : : /* C type names corresponding to cvalues type names */
313 : : typedef int8_t fl_int8_t;
314 : : typedef uint8_t fl_uint8_t;
315 : : typedef int16_t fl_int16_t;
316 : : typedef uint16_t fl_uint16_t;
317 : : typedef int32_t fl_int32_t;
318 : : typedef uint32_t fl_uint32_t;
319 : : typedef int64_t fl_int64_t;
320 : : typedef uint64_t fl_uint64_t;
321 : : typedef char fl_char_t;
322 : : typedef char char_t;
323 : : typedef ptrdiff_t fl_ptrdiff_t;
324 : : typedef size_t fl_size_t;
325 : : typedef double fl_double_t;
326 : : typedef float fl_float_t;
327 : :
328 : : typedef value_t (*builtin_t)(fl_context_t*, value_t*, uint32_t);
329 : :
330 : : value_t cvalue(fl_context_t *fl_ctx, fltype_t *type, size_t sz) JL_NOTSAFEPOINT;
331 : : void add_finalizer(fl_context_t *fl_ctx, cvalue_t *cv);
332 : : void cv_autorelease(fl_context_t *fl_ctx, cvalue_t *cv);
333 : : void cv_pin(fl_context_t *fl_ctx, cvalue_t *cv);
334 : : size_t ctype_sizeof(fl_context_t *fl_ctx, value_t type, int *palign);
335 : : value_t cvalue_copy(fl_context_t *fl_ctx, value_t v);
336 : : value_t cvalue_from_data(fl_context_t *fl_ctx, fltype_t *type, void *data, size_t sz);
337 : : value_t cvalue_from_ref(fl_context_t *fl_ctx, fltype_t *type, void *ptr, size_t sz, value_t parent);
338 : : value_t cbuiltin(fl_context_t *fl_ctx, const char *name, builtin_t f);
339 : : size_t cvalue_arraylen(value_t v);
340 : : value_t size_wrap(fl_context_t *fl_ctx, size_t sz);
341 : : size_t tosize(fl_context_t *fl_ctx, value_t n, const char *fname);
342 : : value_t cvalue_string(fl_context_t *fl_ctx, size_t sz);
343 : : value_t cvalue_static_cstrn(fl_context_t *fl_ctx, const char *str, size_t n);
344 : : value_t cvalue_static_cstring(fl_context_t *fl_ctx, const char *str);
345 : : value_t string_from_cstr(fl_context_t *fl_ctx, char *str);
346 : : value_t string_from_cstrn(fl_context_t *fl_ctx, char *str, size_t n);
347 : : int fl_isstring(fl_context_t *fl_ctx, value_t v) JL_NOTSAFEPOINT;
348 : : int fl_isnumber(fl_context_t *fl_ctx, value_t v) JL_NOTSAFEPOINT;
349 : : int fl_isgensym(fl_context_t *fl_ctx, value_t v) JL_NOTSAFEPOINT;
350 : : int fl_isiostream(fl_context_t *fl_ctx, value_t v) JL_NOTSAFEPOINT;
351 : : ios_t *fl_toiostream(fl_context_t *fl_ctx, value_t v, const char *fname);
352 : : value_t cvalue_compare(value_t a, value_t b);
353 : : int numeric_compare(fl_context_t *fl_ctx, value_t a, value_t b, int eq, int eqnans, char *fname);
354 : :
355 : : void to_sized_ptr(fl_context_t *fl_ctx, value_t v, const char *fname, char **pdata, size_t *psz);
356 : :
357 : : fltype_t *get_type(fl_context_t *fl_ctx, value_t t);
358 : : fltype_t *get_array_type(fl_context_t *fl_ctx, value_t eltype);
359 : : fltype_t *define_opaque_type(value_t sym, size_t sz, const cvtable_t *vtab,
360 : : cvinitfunc_t init) JL_NOTSAFEPOINT;
361 : :
362 : : value_t mk_double(fl_context_t *fl_ctx, fl_double_t n);
363 : : value_t mk_float(fl_context_t *fl_ctx, fl_float_t n);
364 : : value_t mk_uint32(fl_context_t *fl_ctx, uint32_t n);
365 : : value_t mk_uint64(fl_context_t *fl_ctx, uint64_t n);
366 : : value_t mk_wchar(fl_context_t *fl_ctx, int32_t n);
367 : : value_t return_from_uint64(fl_context_t *fl_ctx, uint64_t Uaccum);
368 : : value_t return_from_int64(fl_context_t *fl_ctx, int64_t Saccum);
369 : :
370 : : typedef struct {
371 : : const char *name;
372 : : builtin_t fptr;
373 : : } builtinspec_t;
374 : :
375 : : void assign_global_builtins(fl_context_t *fl_ctx, const builtinspec_t *b) JL_NOTSAFEPOINT;
376 : :
377 : : /* builtins */
378 : : value_t fl_hash(fl_context_t *fl_ctx, value_t *args, uint32_t nargs);
379 : : value_t cvalue_byte(fl_context_t *fl_ctx, value_t *args, uint32_t nargs);
380 : : value_t cvalue_wchar(fl_context_t *fl_ctx, value_t *args, uint32_t nargs);
381 : :
382 : : void fl_init(fl_context_t *fl_ctx, size_t initial_heapsize) JL_NOTSAFEPOINT;
383 : : int fl_load_system_image(fl_context_t *fl_ctx, value_t ios);
384 : : int fl_load_system_image_str(fl_context_t *fl_ctx, char* str, size_t len) JL_NOTSAFEPOINT;
385 : :
386 : : /* julia extensions */
387 : : JL_DLLEXPORT int jl_id_char(uint32_t wc);
388 : : JL_DLLEXPORT int jl_id_start_char(uint32_t wc);
389 : : JL_DLLEXPORT int jl_op_suffix_char(uint32_t wc);
390 : :
391 : : struct _fl_context_t {
392 : : symbol_t *symtab;
393 : : value_t NIL, T, F, FL_EOF, QUOTE;
394 : : value_t int8sym, uint8sym, int16sym, uint16sym, int32sym, uint32sym;
395 : : value_t int64sym, uint64sym;
396 : :
397 : : value_t ptrdiffsym, sizesym, bytesym, wcharsym;
398 : : value_t floatsym, doublesym;
399 : : value_t stringtypesym, wcstringtypesym;
400 : : value_t emptystringsym;
401 : :
402 : : value_t arraysym, cfunctionsym, voidsym, pointersym;
403 : :
404 : : htable_t TypeTable;
405 : : htable_t reverse_dlsym_lookup_table;
406 : :
407 : : fltype_t *int8type, *uint8type;
408 : : fltype_t *int16type, *uint16type;
409 : : fltype_t *int32type, *uint32type;
410 : : fltype_t *int64type, *uint64type;
411 : : fltype_t *ptrdifftype, *sizetype;
412 : : fltype_t *floattype, *doubletype;
413 : : fltype_t *bytetype, *wchartype;
414 : : fltype_t *stringtype, *wcstringtype;
415 : : fltype_t *builtintype;
416 : :
417 : : htable_t equal_eq_hashtable;
418 : :
419 : : value_t tablesym;
420 : : fltype_t *tabletype;
421 : : cvtable_t table_vtable;
422 : :
423 : : uint32_t readtoktype;
424 : : value_t readtokval;
425 : : char readbuf[256];
426 : :
427 : : htable_t printconses;
428 : : uint32_t printlabel;
429 : : int print_pretty;
430 : : int print_princ;
431 : : fixnum_t print_length;
432 : : fixnum_t print_level;
433 : : fixnum_t P_LEVEL;
434 : : int SCR_WIDTH;
435 : : int HPOS, VPOS;
436 : :
437 : : value_t iostreamsym, rdsym, wrsym, apsym, crsym, truncsym;
438 : : value_t instrsym, outstrsym;
439 : : fltype_t *iostreamtype;
440 : :
441 : : size_t malloc_pressure;
442 : : cvalue_t **Finalizers;
443 : : size_t nfinalizers;
444 : : size_t maxfinalizers;
445 : :
446 : : uint32_t N_STACK;
447 : : value_t *Stack;
448 : : uint32_t SP;
449 : : uint32_t curr_frame;
450 : :
451 : : #define FL_N_GC_HANDLES 8192
452 : : value_t *GCHandleStack[FL_N_GC_HANDLES];
453 : : uint32_t N_GCHND;
454 : :
455 : : value_t IOError, ParseError, TypeError, ArgError, UnboundError, KeyError;
456 : : value_t OutOfMemoryError, DivideError, BoundsError, EnumerationError;
457 : : value_t printwidthsym, printreadablysym, printprettysym, printlengthsym;
458 : : value_t printlevelsym, builtins_table_sym;
459 : :
460 : : value_t LAMBDA, IF, TRYCATCH;
461 : : value_t BACKQUOTE, COMMA, COMMAAT, COMMADOT, FUNCTION;
462 : :
463 : : value_t pairsym, symbolsym, fixnumsym, vectorsym, builtinsym, vu8sym;
464 : : value_t definesym, defmacrosym, forsym, setqsym;
465 : : value_t tsym, Tsym, fsym, Fsym, booleansym, nullsym, evalsym, fnsym;
466 : : // for reading characters
467 : : value_t nulsym, alarmsym, backspacesym, tabsym, linefeedsym, newlinesym;
468 : : value_t vtabsym, pagesym, returnsym, escsym, spacesym, deletesym;
469 : :
470 : : struct _fl_readstate_t *readstate;
471 : :
472 : : unsigned char *fromspace;
473 : : unsigned char *tospace;
474 : : unsigned char *curheap;
475 : : unsigned char *lim;
476 : : size_t heapsize;//bytes
477 : : uint32_t *consflags;
478 : :
479 : : // error utilities --------------------------------------------------
480 : :
481 : : // saved execution state for an unwind target
482 : : fl_exception_context_t *exc_ctx;
483 : : uint32_t throwing_frame; // active frame when exception was thrown
484 : : value_t lasterror;
485 : :
486 : : uint32_t gensym_ctr;
487 : : // two static buffers for gensym printing so there can be two
488 : : // gensym names available at a time, mostly for compare()
489 : : char gsname[2][16];
490 : : int gsnameno;
491 : :
492 : : void *tochain;
493 : : long long n_allocd;
494 : :
495 : : value_t the_empty_vector;
496 : : value_t memory_exception_value;
497 : :
498 : : int gc_grew;
499 : : cons_t *apply_c;
500 : : value_t *apply_pv;
501 : : int64_t apply_accum;
502 : : value_t apply_func, apply_v, apply_e;
503 : :
504 : : value_t jl_sym;
505 : : value_t jl_char_sym;
506 : : // persistent buffer (avoid repeated malloc/free)
507 : : // for julia_extensions.c: normalize
508 : : size_t jlbuflen;
509 : : void *jlbuf;
510 : : };
511 : :
512 : 6722 : static inline void argcount(fl_context_t *fl_ctx, const char *fname, uint32_t nargs, uint32_t c) JL_NOTSAFEPOINT
513 : : {
514 [ - + ]: 6722 : if (__unlikely(nargs != c))
515 [ # # ]: 0 : lerrorf(fl_ctx, fl_ctx->ArgError,"%s: too %s arguments", fname, nargs<c ? "few":"many");
516 : 6722 : }
517 : :
518 : : #ifdef __cplusplus
519 : : }
520 : : #endif
521 : :
522 : : #endif
|