2019-08-09 14:07:16 -04:00
|
|
|
typedef uintptr_t value_t;
|
2019-08-09 14:04:19 -04:00
|
|
|
typedef uintptr_t ufixnum_t;
|
2019-08-09 14:11:40 -04:00
|
|
|
typedef intptr_t fixnum_t;
|
2008-06-30 21:54:22 -04:00
|
|
|
#ifdef BITS64
|
|
|
|
#define T_FIXNUM T_INT64
|
|
|
|
#else
|
|
|
|
#define T_FIXNUM T_INT32
|
|
|
|
#endif
|
|
|
|
|
2019-08-09 12:28:14 -04:00
|
|
|
struct cons {
|
2008-06-30 21:54:22 -04:00
|
|
|
value_t car;
|
|
|
|
value_t cdr;
|
2019-08-09 12:28:14 -04:00
|
|
|
};
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2019-08-09 12:30:15 -04:00
|
|
|
struct symbol {
|
2019-08-09 14:07:16 -04:00
|
|
|
uintptr_t flags;
|
2019-08-09 07:02:02 -04:00
|
|
|
value_t binding; // global value binding
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *type;
|
2008-11-23 02:12:37 -05:00
|
|
|
uint32_t hash;
|
2019-08-09 07:02:02 -04:00
|
|
|
void *dlcache; // dlsym address
|
2008-06-30 21:54:22 -04:00
|
|
|
// below fields are private
|
2019-08-09 12:30:15 -04:00
|
|
|
struct symbol *left;
|
|
|
|
struct symbol *right;
|
2008-06-30 21:54:22 -04:00
|
|
|
union {
|
|
|
|
char name[1];
|
2019-08-09 07:02:02 -04:00
|
|
|
void *_pad; // ensure field aligned to pointer size
|
2008-06-30 21:54:22 -04:00
|
|
|
};
|
2019-08-09 12:30:15 -04:00
|
|
|
};
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2019-08-09 12:26:33 -04:00
|
|
|
struct gensym {
|
2010-05-04 20:00:37 -04:00
|
|
|
value_t isconst;
|
2019-08-09 07:02:02 -04:00
|
|
|
value_t binding; // global value binding
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *type;
|
2010-05-04 20:00:37 -04:00
|
|
|
uint32_t id;
|
2019-08-09 12:26:33 -04:00
|
|
|
};
|
2010-05-04 20:00:37 -04:00
|
|
|
|
2019-08-09 07:02:02 -04:00
|
|
|
#define TAG_NUM 0x0
|
|
|
|
#define TAG_CPRIM 0x1
|
2009-04-28 00:10:18 -04:00
|
|
|
#define TAG_FUNCTION 0x2
|
2019-08-09 07:02:02 -04:00
|
|
|
#define TAG_VECTOR 0x3
|
|
|
|
#define TAG_NUM1 0x4
|
|
|
|
#define TAG_CVALUE 0x5
|
|
|
|
#define TAG_SYM 0x6
|
|
|
|
#define TAG_CONS 0x7
|
|
|
|
#define UNBOUND ((value_t)0x1) // an invalid value
|
|
|
|
#define TAG_FWD UNBOUND
|
2008-08-04 21:43:12 -04:00
|
|
|
#define tag(x) ((x)&0x7)
|
2019-08-09 07:02:02 -04:00
|
|
|
#define ptr(x) ((void *)((x) & (~(value_t)0x7)))
|
|
|
|
#define tagptr(p, t) (((value_t)(p)) | (t))
|
2019-08-09 07:06:36 -04:00
|
|
|
#define fixnum(x) ((value_t)(((ufixnum_t)(fixnum_t)(x)) << 2))
|
2019-08-09 07:02:02 -04:00
|
|
|
#define numval(x) (((fixnum_t)(x)) >> 2)
|
2008-08-04 21:43:12 -04:00
|
|
|
#ifdef BITS64
|
2019-08-09 07:02:02 -04:00
|
|
|
#define fits_fixnum(x) (((x) >> 61) == 0 || (~((x) >> 61)) == 0)
|
2008-08-04 21:43:12 -04:00
|
|
|
#else
|
2019-08-09 07:02:02 -04:00
|
|
|
#define fits_fixnum(x) (((x) >> 29) == 0 || (~((x) >> 29)) == 0)
|
2008-08-04 21:43:12 -04:00
|
|
|
#endif
|
2019-08-09 07:02:02 -04:00
|
|
|
#define fits_bits(x, b) (((x) >> (b - 1)) == 0 || (~((x) >> (b - 1))) == 0)
|
|
|
|
#define uintval(x) (((unsigned int)(x)) >> 3)
|
|
|
|
#define builtin(n) tagptr((((int)n) << 3), TAG_FUNCTION)
|
|
|
|
#define iscons(x) (tag(x) == TAG_CONS)
|
|
|
|
#define issymbol(x) (tag(x) == TAG_SYM)
|
|
|
|
#define isfixnum(x) (((x)&3) == TAG_NUM)
|
|
|
|
#define bothfixnums(x, y) ((((x) | (y)) & 3) == TAG_NUM)
|
2009-08-09 14:04:03 -04:00
|
|
|
#define isbuiltin(x) ((tag(x) == TAG_FUNCTION) && uintval(x) <= OP_ASET)
|
2008-08-04 21:43:12 -04:00
|
|
|
#define isvector(x) (tag(x) == TAG_VECTOR)
|
|
|
|
#define iscvalue(x) (tag(x) == TAG_CVALUE)
|
2019-08-09 07:02:02 -04:00
|
|
|
#define iscprim(x) (tag(x) == TAG_CPRIM)
|
|
|
|
#define selfevaluating(x) (tag(x) < 6)
|
2008-08-02 12:18:39 -04:00
|
|
|
// comparable with ==
|
2019-08-09 07:02:02 -04:00
|
|
|
#define eq_comparable(a, b) (!(((a) | (b)) & 1))
|
2008-09-06 18:19:51 -04:00
|
|
|
#define eq_comparablep(a) (!((a)&1))
|
2008-08-04 21:43:12 -04:00
|
|
|
// doesn't lead to other values
|
|
|
|
#define leafp(a) (((a)&3) != 3)
|
|
|
|
|
2019-08-09 07:02:02 -04:00
|
|
|
#define isforwarded(v) (((value_t *)ptr(v))[0] == TAG_FWD)
|
|
|
|
#define forwardloc(v) (((value_t *)ptr(v))[1])
|
|
|
|
#define forward(v, to) \
|
|
|
|
do { \
|
|
|
|
(((value_t *)ptr(v))[0] = TAG_FWD); \
|
|
|
|
(((value_t *)ptr(v))[1] = to); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define vector_size(v) (((size_t *)ptr(v))[0] >> 2)
|
|
|
|
#define vector_setsize(v, n) (((size_t *)ptr(v))[0] = ((n) << 2))
|
|
|
|
#define vector_elt(v, i) (((value_t *)ptr(v))[1 + (i)])
|
|
|
|
#define vector_grow_amt(x) ((x) < 8 ? 5 : 6 * ((x) >> 3))
|
2008-06-30 21:54:22 -04:00
|
|
|
// functions ending in _ are unsafe, faster versions
|
2019-08-09 12:28:14 -04:00
|
|
|
#define car_(v) (((struct cons *)ptr(v))->car)
|
|
|
|
#define cdr_(v) (((struct cons *)ptr(v))->cdr)
|
2019-08-09 07:02:02 -04:00
|
|
|
#define car(v) (tocons((v), "car")->car)
|
|
|
|
#define cdr(v) (tocons((v), "cdr")->cdr)
|
|
|
|
#define fn_bcode(f) (((value_t *)ptr(f))[0])
|
|
|
|
#define fn_vals(f) (((value_t *)ptr(f))[1])
|
|
|
|
#define fn_env(f) (((value_t *)ptr(f))[2])
|
|
|
|
#define fn_name(f) (((value_t *)ptr(f))[3])
|
|
|
|
|
2019-08-09 12:30:15 -04:00
|
|
|
#define set(s, v) (((struct symbol *)ptr(s))->binding = (v))
|
|
|
|
#define setc(s, v) \
|
|
|
|
do { \
|
|
|
|
((struct symbol *)ptr(s))->flags |= 1; \
|
|
|
|
((struct symbol *)ptr(s))->binding = (v); \
|
2019-08-09 07:02:02 -04:00
|
|
|
} while (0)
|
|
|
|
#define isconstant(s) ((s)->flags & 0x1)
|
|
|
|
#define iskeyword(s) ((s)->flags & 0x2)
|
2019-08-09 12:30:15 -04:00
|
|
|
#define symbol_value(s) (((struct symbol *)ptr(s))->binding)
|
2019-08-09 07:02:02 -04:00
|
|
|
#define ismanaged(v) \
|
|
|
|
((((unsigned char *)ptr(v)) >= fromspace) && \
|
|
|
|
(((unsigned char *)ptr(v)) < fromspace + heapsize))
|
|
|
|
#define isgensym(x) (issymbol(x) && ismanaged(x))
|
|
|
|
|
|
|
|
#define isfunction(x) (tag(x) == TAG_FUNCTION && (x) > (N_BUILTINS << 3))
|
2009-04-28 00:10:18 -04:00
|
|
|
#define isclosure(x) isfunction(x)
|
2019-08-09 07:02:02 -04:00
|
|
|
#define iscbuiltin(x) \
|
2019-08-09 12:36:20 -04:00
|
|
|
(iscvalue(x) && (cv_class((struct cvalue *)ptr(x)) == builtintype))
|
2009-04-19 18:22:17 -04:00
|
|
|
|
2009-05-18 22:54:56 -04:00
|
|
|
void fl_gc_handle(value_t *pv);
|
2009-08-02 00:06:07 -04:00
|
|
|
void fl_free_gc_handles(uint32_t n);
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2009-03-26 23:06:55 -04:00
|
|
|
// utility for iterating over all arguments in a builtin
|
|
|
|
// i=index, i0=start index, arg = var for each arg, args = arg array
|
|
|
|
// assumes "nargs" is the argument count
|
2019-08-09 07:02:02 -04:00
|
|
|
#define FOR_ARGS(i, i0, arg, args) \
|
|
|
|
for (i = i0; ((size_t)i) < nargs && ((arg = args[i]) || 1); i++)
|
2009-03-26 23:06:55 -04:00
|
|
|
|
2009-04-24 16:43:56 -04:00
|
|
|
#define N_BUILTINS ((int)N_OPCODES)
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2009-08-09 14:04:03 -04:00
|
|
|
extern value_t FL_NIL, FL_T, FL_F, FL_EOF;
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2010-01-06 13:27:28 -05:00
|
|
|
#define FL_UNSPECIFIED FL_T
|
|
|
|
|
2008-06-30 21:54:22 -04:00
|
|
|
/* read, eval, print main entry points */
|
2010-04-29 14:01:26 -04:00
|
|
|
value_t fl_read_sexpr(value_t f);
|
2019-08-09 12:26:20 -04:00
|
|
|
void fl_print(struct ios *f, value_t v);
|
2010-04-29 14:01:26 -04:00
|
|
|
value_t fl_toplevel_eval(value_t expr);
|
|
|
|
value_t fl_apply(value_t f, value_t l);
|
|
|
|
value_t fl_applyn(uint32_t n, value_t f, ...);
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2009-05-05 00:01:06 -04:00
|
|
|
extern value_t printprettysym, printreadablysym, printwidthsym;
|
|
|
|
|
2008-06-30 21:54:22 -04:00
|
|
|
/* object model manipulation */
|
|
|
|
value_t fl_cons(value_t a, value_t b);
|
2010-04-29 14:01:26 -04:00
|
|
|
value_t fl_list2(value_t a, value_t b);
|
|
|
|
value_t fl_listn(size_t n, ...);
|
2019-08-09 17:30:20 -04:00
|
|
|
value_t symbol(const char *str);
|
2008-06-30 21:54:22 -04:00
|
|
|
char *symbol_name(value_t v);
|
2019-08-09 17:30:20 -04:00
|
|
|
int fl_is_keyword_name(const char *str, size_t len);
|
2008-06-30 21:54:22 -04:00
|
|
|
value_t alloc_vector(size_t n, int init);
|
|
|
|
size_t llength(value_t v);
|
2010-04-29 14:01:26 -04:00
|
|
|
value_t fl_compare(value_t a, value_t b); // -1, 0, or 1
|
|
|
|
value_t fl_equal(value_t a, value_t b); // T or nil
|
2008-11-28 16:44:59 -05:00
|
|
|
int equal_lispvalue(value_t a, value_t b);
|
2019-08-09 14:07:16 -04:00
|
|
|
uintptr_t hash_lispvalue(value_t a);
|
2009-03-23 15:49:08 -04:00
|
|
|
int isnumtok_base(char *tok, value_t *pval, int base);
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
/* safe casts */
|
2019-08-09 12:28:14 -04:00
|
|
|
struct cons *tocons(value_t v, char *fname);
|
2019-08-09 12:30:15 -04:00
|
|
|
struct symbol *tosymbol(value_t v, char *fname);
|
2008-06-30 21:54:22 -04:00
|
|
|
fixnum_t tofixnum(value_t v, char *fname);
|
|
|
|
char *tostring(value_t v, char *fname);
|
|
|
|
|
|
|
|
/* error handling */
|
2019-08-09 12:26:42 -04:00
|
|
|
struct fl_readstate {
|
2019-08-09 12:26:09 -04:00
|
|
|
struct htable backrefs;
|
|
|
|
struct htable gensyms;
|
2010-05-02 14:17:47 -04:00
|
|
|
value_t source;
|
2019-08-09 12:26:42 -04:00
|
|
|
struct fl_readstate *prev;
|
|
|
|
};
|
2010-05-02 14:17:47 -04:00
|
|
|
|
2019-08-09 12:18:27 -04:00
|
|
|
struct fl_exception_context {
|
2010-05-02 14:17:47 -04:00
|
|
|
jmp_buf buf;
|
|
|
|
uint32_t sp;
|
|
|
|
uint32_t frame;
|
|
|
|
uint32_t ngchnd;
|
2019-08-09 12:26:42 -04:00
|
|
|
struct fl_readstate *rdst;
|
2019-08-09 12:18:27 -04:00
|
|
|
struct fl_exception_context *prev;
|
|
|
|
};
|
2010-05-02 14:17:47 -04:00
|
|
|
|
2019-08-09 12:18:27 -04:00
|
|
|
extern struct fl_exception_context *fl_ctx;
|
2010-05-02 14:17:47 -04:00
|
|
|
extern uint32_t fl_throwing_frame;
|
|
|
|
extern value_t fl_lasterror;
|
|
|
|
|
2019-08-09 12:18:27 -04:00
|
|
|
#define FL_TRY_EXTERN \
|
|
|
|
struct fl_exception_context _ctx; \
|
|
|
|
int l__tr, l__ca; \
|
|
|
|
fl_savestate(&_ctx); \
|
|
|
|
fl_ctx = &_ctx; \
|
|
|
|
if (!setjmp(_ctx.buf)) \
|
2019-08-09 07:02:02 -04:00
|
|
|
for (l__tr = 1; l__tr; l__tr = 0, (void)(fl_ctx = fl_ctx->prev))
|
2010-05-02 14:17:47 -04:00
|
|
|
|
|
|
|
#define FL_CATCH_EXTERN \
|
2019-08-09 07:02:02 -04:00
|
|
|
else for (l__ca = 1; l__ca; l__ca = 0, fl_restorestate(&_ctx))
|
2010-05-02 14:17:47 -04:00
|
|
|
|
2019-08-17 17:07:46 -04:00
|
|
|
EXTERN_NORETURN(void, lerrorf(value_t e, char *format, ...));
|
|
|
|
EXTERN_NORETURN(void, lerror(value_t e, const char *msg));
|
2019-08-09 12:18:27 -04:00
|
|
|
void fl_savestate(struct fl_exception_context *_ctx);
|
|
|
|
void fl_restorestate(struct fl_exception_context *_ctx);
|
2019-08-17 17:07:46 -04:00
|
|
|
EXTERN_NORETURN(void, fl_raise(value_t e));
|
|
|
|
EXTERN_NORETURN(void, type_error(char *fname, char *expected, value_t got));
|
|
|
|
EXTERN_NORETURN(void, bounds_error(char *fname, value_t arr, value_t ind));
|
2009-03-21 22:05:26 -04:00
|
|
|
extern value_t ArgError, IOError, KeyError, MemoryError, EnumerationError;
|
2009-04-17 10:41:15 -04:00
|
|
|
extern value_t UnboundError;
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2019-08-09 12:21:55 -04:00
|
|
|
struct cvtable {
|
2019-08-09 12:26:20 -04:00
|
|
|
void (*print)(value_t self, struct ios *f);
|
2008-11-28 16:44:59 -05:00
|
|
|
void (*relocate)(value_t oldv, value_t newv);
|
2008-09-06 18:19:51 -04:00
|
|
|
void (*finalize)(value_t self);
|
|
|
|
void (*print_traverse)(value_t self);
|
2019-08-09 12:21:55 -04:00
|
|
|
};
|
2008-09-06 18:19:51 -04:00
|
|
|
|
2019-08-09 12:21:55 -04:00
|
|
|
/* functions needed to implement the value interface (struct cvtable) */
|
2019-08-09 07:02:02 -04:00
|
|
|
typedef enum {
|
|
|
|
T_INT8,
|
|
|
|
T_UINT8,
|
|
|
|
T_INT16,
|
|
|
|
T_UINT16,
|
|
|
|
T_INT32,
|
|
|
|
T_UINT32,
|
|
|
|
T_INT64,
|
|
|
|
T_UINT64,
|
|
|
|
T_FLOAT,
|
|
|
|
T_DOUBLE
|
|
|
|
} numerictype_t;
|
|
|
|
|
|
|
|
#define N_NUMTYPES ((int)T_DOUBLE + 1)
|
2012-02-17 23:59:45 -05:00
|
|
|
|
|
|
|
#ifdef BITS64
|
2019-08-09 07:02:02 -04:00
|
|
|
#define T_LONG T_INT64
|
|
|
|
#define T_ULONG T_UINT64
|
2012-02-17 23:59:45 -05:00
|
|
|
#else
|
2019-08-09 07:02:02 -04:00
|
|
|
#define T_LONG T_INT32
|
|
|
|
#define T_ULONG T_UINT32
|
2012-02-17 23:59:45 -05:00
|
|
|
#endif
|
|
|
|
|
2008-12-20 01:16:00 -05:00
|
|
|
value_t relocate_lispvalue(value_t v);
|
|
|
|
void print_traverse(value_t v);
|
2019-08-09 12:26:20 -04:00
|
|
|
void fl_print_chr(char c, struct ios *f);
|
|
|
|
void fl_print_str(char *s, struct ios *f);
|
|
|
|
void fl_print_child(struct ios *f, value_t v);
|
2008-12-20 01:16:00 -05:00
|
|
|
|
2019-08-09 12:33:04 -04:00
|
|
|
typedef int (*cvinitfunc_t)(struct fltype *, value_t, void *);
|
2008-12-10 23:04:17 -05:00
|
|
|
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype {
|
2008-12-10 23:04:17 -05:00
|
|
|
value_t type;
|
|
|
|
numerictype_t numtype;
|
|
|
|
size_t size;
|
|
|
|
size_t elsz;
|
2019-08-09 12:21:55 -04:00
|
|
|
struct cvtable *vtable;
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *eltype; // for arrays
|
|
|
|
struct fltype *artype; // (array this)
|
2008-12-10 23:04:17 -05:00
|
|
|
int marked;
|
|
|
|
cvinitfunc_t init;
|
2019-08-09 12:33:04 -04:00
|
|
|
};
|
2008-12-10 23:04:17 -05:00
|
|
|
|
2019-08-09 12:36:20 -04:00
|
|
|
struct cvalue {
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *type;
|
2008-12-10 23:04:17 -05:00
|
|
|
void *data;
|
2019-08-09 07:02:02 -04:00
|
|
|
size_t len; // length of *data in bytes
|
2008-06-30 21:54:22 -04:00
|
|
|
union {
|
2019-08-09 07:02:02 -04:00
|
|
|
value_t parent; // optional
|
|
|
|
char _space[1]; // variable size
|
2008-06-30 21:54:22 -04:00
|
|
|
};
|
2019-08-09 12:36:20 -04:00
|
|
|
};
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2008-12-10 23:04:17 -05:00
|
|
|
#define CVALUE_NWORDS 4
|
2008-09-06 18:19:51 -04:00
|
|
|
|
2019-08-09 12:25:43 -04:00
|
|
|
struct cprim {
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *type;
|
2008-12-10 23:04:17 -05:00
|
|
|
char _space[1];
|
2019-08-09 12:25:43 -04:00
|
|
|
};
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2019-08-09 12:23:30 -04:00
|
|
|
struct function {
|
2009-04-19 18:22:17 -04:00
|
|
|
value_t bcode;
|
|
|
|
value_t vals;
|
|
|
|
value_t env;
|
2009-07-10 00:17:39 -04:00
|
|
|
value_t name;
|
2019-08-09 12:23:30 -04:00
|
|
|
};
|
2009-04-19 18:22:17 -04:00
|
|
|
|
2008-12-10 23:04:17 -05:00
|
|
|
#define CPRIM_NWORDS 2
|
2009-05-29 00:38:50 -04:00
|
|
|
#define MAX_INL_SIZE 384
|
2008-09-06 18:19:51 -04:00
|
|
|
|
2019-08-09 07:02:02 -04:00
|
|
|
#define CV_OWNED_BIT 0x1
|
2008-12-10 23:04:17 -05:00
|
|
|
#define CV_PARENT_BIT 0x2
|
2019-08-09 14:07:16 -04:00
|
|
|
#define owned(cv) ((uintptr_t)(cv)->type & CV_OWNED_BIT)
|
|
|
|
#define hasparent(cv) ((uintptr_t)(cv)->type & CV_PARENT_BIT)
|
2019-08-09 07:02:02 -04:00
|
|
|
#define isinlined(cv) ((cv)->data == &(cv)->_space[0])
|
2019-08-09 14:07:16 -04:00
|
|
|
#define cv_class(cv) ((struct fltype *)(((uintptr_t)(cv)->type) & ~3))
|
2019-08-09 07:02:02 -04:00
|
|
|
#define cv_len(cv) ((cv)->len)
|
|
|
|
#define cv_type(cv) (cv_class(cv)->type)
|
|
|
|
#define cv_data(cv) ((cv)->data)
|
|
|
|
#define cv_isstr(cv) (cv_class(cv)->eltype == bytetype)
|
|
|
|
#define cv_isPOD(cv) (cv_class(cv)->init != NULL)
|
|
|
|
|
2019-08-09 12:36:20 -04:00
|
|
|
#define cvalue_data(v) cv_data((struct cvalue *)ptr(v))
|
|
|
|
#define cvalue_len(v) cv_len((struct cvalue *)ptr(v))
|
|
|
|
#define value2c(type, v) ((type)cv_data((struct cvalue *)ptr(v)))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
#define valid_numtype(v) ((v) < N_NUMTYPES)
|
2019-08-09 07:02:02 -04:00
|
|
|
#define cp_class(cp) ((cp)->type)
|
|
|
|
#define cp_type(cp) (cp_class(cp)->type)
|
2009-01-02 18:00:21 -05:00
|
|
|
#define cp_numtype(cp) (cp_class(cp)->numtype)
|
2019-08-09 07:02:02 -04:00
|
|
|
#define cp_data(cp) (&(cp)->_space[0])
|
2009-01-02 18:00:21 -05:00
|
|
|
|
|
|
|
// WARNING: multiple evaluation!
|
2019-08-09 12:25:43 -04:00
|
|
|
#define cptr(v) \
|
|
|
|
(iscprim(v) ? cp_data((struct cprim *)ptr(v)) \
|
2019-08-09 12:36:20 -04:00
|
|
|
: cv_data((struct cvalue *)ptr(v)))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2019-08-09 07:02:02 -04:00
|
|
|
typedef value_t (*builtin_t)(value_t *, uint32_t);
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2009-08-08 17:44:14 -04:00
|
|
|
extern value_t QUOTE;
|
2008-06-30 21:54:22 -04:00
|
|
|
extern value_t int8sym, uint8sym, int16sym, uint16sym, int32sym, uint32sym;
|
2008-12-10 23:04:17 -05:00
|
|
|
extern value_t int64sym, uint64sym;
|
2008-12-23 23:43:36 -05:00
|
|
|
extern value_t longsym, ulongsym, bytesym, wcharsym;
|
2019-08-09 07:02:02 -04:00
|
|
|
extern value_t structsym, arraysym, enumsym, cfunctionsym, voidsym,
|
|
|
|
pointersym;
|
2008-06-30 21:54:22 -04:00
|
|
|
extern value_t stringtypesym, wcstringtypesym, emptystringsym;
|
2009-08-08 17:44:14 -04:00
|
|
|
extern value_t unionsym, floatsym, doublesym;
|
2019-08-09 12:33:04 -04:00
|
|
|
extern struct fltype *bytetype, *wchartype;
|
|
|
|
extern struct fltype *stringtype, *wcstringtype;
|
|
|
|
extern struct fltype *builtintype;
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2019-08-09 12:33:04 -04:00
|
|
|
value_t cvalue(struct fltype *type, size_t sz);
|
2019-08-09 12:36:20 -04:00
|
|
|
void add_finalizer(struct cvalue *cv);
|
|
|
|
void cv_autorelease(struct cvalue *cv);
|
|
|
|
void cv_pin(struct cvalue *cv);
|
2008-06-30 21:54:22 -04:00
|
|
|
size_t ctype_sizeof(value_t type, int *palign);
|
|
|
|
value_t cvalue_copy(value_t v);
|
2019-08-09 12:33:04 -04:00
|
|
|
value_t cvalue_from_data(struct fltype *type, void *data, size_t sz);
|
|
|
|
value_t cvalue_from_ref(struct fltype *type, void *ptr, size_t sz,
|
|
|
|
value_t parent);
|
2008-12-21 00:55:00 -05:00
|
|
|
value_t cbuiltin(char *name, builtin_t f);
|
2008-06-30 21:54:22 -04:00
|
|
|
size_t cvalue_arraylen(value_t v);
|
|
|
|
value_t size_wrap(size_t sz);
|
|
|
|
size_t toulong(value_t n, char *fname);
|
|
|
|
value_t cvalue_string(size_t sz);
|
2009-03-24 22:28:21 -04:00
|
|
|
value_t cvalue_static_cstring(const char *str);
|
2019-08-11 16:27:12 -04:00
|
|
|
value_t string_from_cstr(const char *str);
|
|
|
|
value_t string_from_cstrn(const char *str, size_t n);
|
2009-08-23 03:06:57 -04:00
|
|
|
int fl_isstring(value_t v);
|
|
|
|
int fl_isnumber(value_t v);
|
2010-05-04 20:00:37 -04:00
|
|
|
int fl_isgensym(value_t v);
|
2009-08-23 03:06:57 -04:00
|
|
|
int fl_isiostream(value_t v);
|
2019-08-09 12:26:20 -04:00
|
|
|
struct ios *fl_toiostream(value_t v, char *fname);
|
2008-06-30 21:54:22 -04:00
|
|
|
value_t cvalue_compare(value_t a, value_t b);
|
2009-04-15 23:05:38 -04:00
|
|
|
int numeric_compare(value_t a, value_t b, int eq, int eqnans, char *fname);
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2009-03-04 22:48:17 -05:00
|
|
|
void to_sized_ptr(value_t v, char *fname, char **pdata, size_t *psz);
|
|
|
|
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *get_type(value_t t);
|
|
|
|
struct fltype *get_array_type(value_t eltype);
|
|
|
|
struct fltype *define_opaque_type(value_t sym, size_t sz,
|
|
|
|
struct cvtable *vtab, cvinitfunc_t init);
|
2008-12-10 23:04:17 -05:00
|
|
|
|
2019-08-13 11:28:19 -04:00
|
|
|
value_t mk_double(double_t n);
|
|
|
|
value_t mk_float(float_t n);
|
2008-06-30 21:54:22 -04:00
|
|
|
value_t mk_uint32(uint32_t n);
|
|
|
|
value_t mk_uint64(uint64_t n);
|
2008-12-23 23:43:36 -05:00
|
|
|
value_t mk_wchar(int32_t n);
|
2008-06-30 21:54:22 -04:00
|
|
|
value_t return_from_uint64(uint64_t Uaccum);
|
|
|
|
value_t return_from_int64(int64_t Saccum);
|
|
|
|
|
2012-02-17 23:59:45 -05:00
|
|
|
numerictype_t effective_numerictype(double r);
|
|
|
|
double conv_to_double(void *data, numerictype_t tag);
|
|
|
|
void conv_from_double(void *data, double d, numerictype_t tag);
|
|
|
|
int64_t conv_to_int64(void *data, numerictype_t tag);
|
|
|
|
uint64_t conv_to_uint64(void *data, numerictype_t tag);
|
|
|
|
int32_t conv_to_int32(void *data, numerictype_t tag);
|
|
|
|
uint32_t conv_to_uint32(void *data, numerictype_t tag);
|
|
|
|
#ifdef BITS64
|
|
|
|
#define conv_to_long conv_to_int64
|
|
|
|
#define conv_to_ulong conv_to_uint64
|
|
|
|
#else
|
|
|
|
#define conv_to_long conv_to_int32
|
|
|
|
#define conv_to_ulong conv_to_uint32
|
|
|
|
#endif
|
|
|
|
|
2019-08-09 12:20:18 -04:00
|
|
|
struct builtinspec {
|
2008-11-23 02:12:37 -05:00
|
|
|
char *name;
|
2008-12-10 23:04:17 -05:00
|
|
|
builtin_t fptr;
|
2019-08-09 12:20:18 -04:00
|
|
|
};
|
2008-11-23 02:12:37 -05:00
|
|
|
|
2019-08-09 12:20:18 -04:00
|
|
|
void assign_global_builtins(struct builtinspec *b);
|
2008-11-23 02:12:37 -05:00
|
|
|
|
2008-12-20 01:16:00 -05:00
|
|
|
/* builtins */
|
2019-08-09 14:00:03 -04:00
|
|
|
value_t fl_hash(value_t *args, uint32_t nargs);
|
2008-12-23 23:43:36 -05:00
|
|
|
value_t cvalue_byte(value_t *args, uint32_t nargs);
|
2008-12-20 01:16:00 -05:00
|
|
|
value_t cvalue_wchar(value_t *args, uint32_t nargs);
|
|
|
|
|
2010-05-02 16:36:39 -04:00
|
|
|
void fl_init(size_t initial_heapsize);
|
2019-08-13 16:07:44 -04:00
|
|
|
int fl_load_boot_image(void);
|