shithub: femtolisp

ref: 2967f7480c224b0928255cf44ca15cc4c5b08dd7
dir: /cvalues.h/

View raw version
#ifndef CVALUES_H
#define CVALUES_H

#ifdef BITS64
#define NWORDS(sz) (((sz)+7)>>3)
#else
#define NWORDS(sz) (((sz)+3)>>2)
#endif

#define CVALUE_NWORDS 4
#define MAX_INL_SIZE 384
#define CV_OWNED_BIT  0x1
#define CV_PARENT_BIT 0x2
#define owned(cv) ((uintptr_t)(cv)->type & CV_OWNED_BIT)
#define hasparent(cv) ((uintptr_t)(cv)->type & CV_PARENT_BIT)
#define isinlined(cv) ((cv)->data == &(cv)->_space[0])

extern value_t int8sym, uint8sym, int16sym, uint16sym, int32sym, uint32sym;
extern value_t int64sym, uint64sym, bignumsym;
extern value_t longsym, ulongsym, bytesym, wcharsym;
extern value_t structsym, arraysym, enumsym, cfunctionsym, voidsym, pointersym;
extern value_t stringtypesym, wcstringtypesym, emptystringsym;
extern value_t unionsym, floatsym, doublesym;

extern fltype_t *bytetype, *wchartype;
extern fltype_t *stringtype, *wcstringtype;
extern fltype_t *builtintype;

extern htable_t TypeTable;
extern htable_t reverse_dlsym_lookup_table;
extern fltype_t *mpinttype;

void add_finalizer(cvalue_t *cv);
void sweep_finalizers(void);
void cv_autorelease(cvalue_t *cv);
value_t cvalue(fltype_t *type, size_t sz);
value_t cvalue_from_data(fltype_t *type, void *data, size_t sz);
value_t cvalue_from_ref(fltype_t *type, void *ptr, size_t sz, value_t parent);
value_t cvalue_string(size_t sz);
value_t cvalue_static_cstring(const char *str);
value_t string_from_cstrn(char *str, size_t n);
value_t string_from_cstr(char *str);
int fl_isstring(value_t v);
void cv_pin(cvalue_t *cv);
value_t mk_mpint(mpint *n);
value_t size_wrap(size_t sz);
size_t toulong(value_t n);
off_t tooffset(value_t n);
int cvalue_enum_init(fltype_t *ft, value_t arg, void *dest);
int isarray(value_t v);
int cvalue_array_init(fltype_t *ft, value_t arg, void *dest);
size_t cvalue_arraylen(value_t v);
size_t ctype_sizeof(value_t type, int *palign);
void to_sized_ptr(value_t v, char **pdata, size_t *psz);
value_t cvalue_relocate(value_t v);
value_t cvalue_copy(value_t v);
value_t cvalue_compare(value_t a, value_t b);
value_t cvalue_array_aref(value_t *args);
value_t cvalue_array_aset(value_t *args);
value_t cbuiltin(char *name, builtin_t f);
value_t return_from_uint64(uint64_t Uaccum);
value_t return_from_int64(int64_t Saccum);
value_t fl_add_any(value_t *args, uint32_t nargs, fixnum_t carryIn);
value_t fl_neg(value_t n);
value_t fl_mul_any(value_t *args, uint32_t nargs, int64_t Saccum);
int num_to_ptr(value_t a, fixnum_t *pi, numerictype_t *pt, void **pp);
int numeric_compare(value_t a, value_t b, int eq, int eqnans, int typeerr);
_Noreturn void DivideByZeroError(void);
value_t fl_div2(value_t a, value_t b);
value_t fl_idiv2(value_t a, value_t b);
void cvalues_init(void);

value_t mk_double(double n);
value_t mk_float(float n);
value_t mk_int32(int32_t n);
value_t mk_uint32(uint32_t n);
value_t mk_int64(int64_t n);
value_t mk_uint64(uint64_t n);
value_t mk_wchar(int32_t n);

/* builtins.c */
size_t llength(value_t v);

#endif