shithub: femtolisp

ref: 6df541775b1cd4eb2d9bd3698d68c5cd6d42736b
dir: /cvalues.h/

View raw version
#pragma once

#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])

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, bool nofinalizer);
#define cvalue(type, sz) cvalue_(type, sz, false)
#define cvalue_nofinalizer(type, sz) cvalue_(type, sz, true)
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, uint8_t **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);
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_rune(Rune n);
#if defined(ULONG64)
value_t mk_ulong(uint64_t n);
#else
value_t mk_ulong(uint32_t n);
#endif

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