Replace fltype_t with struct
This commit is contained in:
parent
c9f5e4faeb
commit
b48261f21c
96
c/cvalues.h
96
c/cvalues.h
|
@ -18,17 +18,17 @@ value_t unionsym;
|
|||
|
||||
static struct htable TypeTable;
|
||||
static struct htable reverse_dlsym_lookup_table;
|
||||
static fltype_t *int8type, *uint8type;
|
||||
static fltype_t *int16type, *uint16type;
|
||||
static fltype_t *int32type, *uint32type;
|
||||
static fltype_t *int64type, *uint64type;
|
||||
static fltype_t *longtype, *ulongtype;
|
||||
static fltype_t *floattype, *doubletype;
|
||||
fltype_t *bytetype, *wchartype;
|
||||
fltype_t *stringtype, *wcstringtype;
|
||||
fltype_t *builtintype;
|
||||
static struct fltype *int8type, *uint8type;
|
||||
static struct fltype *int16type, *uint16type;
|
||||
static struct fltype *int32type, *uint32type;
|
||||
static struct fltype *int64type, *uint64type;
|
||||
static struct fltype *longtype, *ulongtype;
|
||||
static struct fltype *floattype, *doubletype;
|
||||
struct fltype *bytetype, *wchartype;
|
||||
struct fltype *stringtype, *wcstringtype;
|
||||
struct fltype *builtintype;
|
||||
|
||||
static void cvalue_init(fltype_t *type, value_t v, void *dest);
|
||||
static void cvalue_init(struct fltype *type, value_t v, void *dest);
|
||||
|
||||
// cvalues-specific builtins
|
||||
value_t cvalue_new(value_t *args, u_int32_t nargs);
|
||||
|
@ -74,7 +74,7 @@ static void sweep_finalizers(void)
|
|||
lst[n] = (cvalue_t *)ptr(forwardloc((value_t)tmp));
|
||||
n++;
|
||||
} else {
|
||||
fltype_t *t = cv_class(tmp);
|
||||
struct fltype *t = cv_class(tmp);
|
||||
if (t->vtable != NULL && t->vtable->finalize != NULL) {
|
||||
t->vtable->finalize(tagptr(tmp, TAG_CVALUE));
|
||||
}
|
||||
|
@ -111,13 +111,13 @@ static size_t cv_nwords(cvalue_t *cv)
|
|||
|
||||
static void autorelease(cvalue_t *cv)
|
||||
{
|
||||
cv->type = (fltype_t *)(((uptrint_t)cv->type) | CV_OWNED_BIT);
|
||||
cv->type = (struct fltype *)(((uptrint_t)cv->type) | CV_OWNED_BIT);
|
||||
add_finalizer(cv);
|
||||
}
|
||||
|
||||
void cv_autorelease(cvalue_t *cv) { autorelease(cv); }
|
||||
|
||||
static value_t cprim(fltype_t *type, size_t sz)
|
||||
static value_t cprim(struct fltype *type, size_t sz)
|
||||
{
|
||||
assert(!ismanaged((uptrint_t)type));
|
||||
assert(sz == type->size);
|
||||
|
@ -127,7 +127,7 @@ static value_t cprim(fltype_t *type, size_t sz)
|
|||
return tagptr(pcp, TAG_CPRIM);
|
||||
}
|
||||
|
||||
value_t cvalue(fltype_t *type, size_t sz)
|
||||
value_t cvalue(struct fltype *type, size_t sz)
|
||||
{
|
||||
cvalue_t *pcv;
|
||||
int str = 0;
|
||||
|
@ -165,7 +165,7 @@ value_t cvalue(fltype_t *type, size_t sz)
|
|||
return tagptr(pcv, TAG_CVALUE);
|
||||
}
|
||||
|
||||
value_t cvalue_from_data(fltype_t *type, void *data, size_t sz)
|
||||
value_t cvalue_from_data(struct fltype *type, void *data, size_t sz)
|
||||
{
|
||||
value_t cv;
|
||||
cv = cvalue(type, sz);
|
||||
|
@ -181,7 +181,8 @@ value_t cvalue_from_data(fltype_t *type, void *data, size_t sz)
|
|||
// user explicitly calls (autorelease ) on the result of this function.
|
||||
// 'parent' is an optional cvalue that this pointer is known to point
|
||||
// into; NIL if none.
|
||||
value_t cvalue_from_ref(fltype_t *type, void *ptr, size_t sz, value_t parent)
|
||||
value_t cvalue_from_ref(struct fltype *type, void *ptr, size_t sz,
|
||||
value_t parent)
|
||||
{
|
||||
cvalue_t *pcv;
|
||||
value_t cv;
|
||||
|
@ -191,7 +192,7 @@ value_t cvalue_from_ref(fltype_t *type, void *ptr, size_t sz, value_t parent)
|
|||
pcv->len = sz;
|
||||
pcv->type = type;
|
||||
if (parent != NIL) {
|
||||
pcv->type = (fltype_t *)(((uptrint_t)pcv->type) | CV_PARENT_BIT);
|
||||
pcv->type = (struct fltype *)(((uptrint_t)pcv->type) | CV_PARENT_BIT);
|
||||
pcv->parent = parent;
|
||||
}
|
||||
cv = tagptr(pcv, TAG_CVALUE);
|
||||
|
@ -236,23 +237,23 @@ void cv_pin(cvalue_t *cv)
|
|||
autorelease(cv);
|
||||
}
|
||||
|
||||
#define num_init(ctype, cnvt, tag) \
|
||||
static int cvalue_##ctype##_init(fltype_t *type, value_t arg, \
|
||||
void *dest) \
|
||||
{ \
|
||||
fl_##ctype##_t n = 0; \
|
||||
(void)type; \
|
||||
if (isfixnum(arg)) { \
|
||||
n = numval(arg); \
|
||||
} else if (iscprim(arg)) { \
|
||||
struct cprim *cp = (struct cprim *)ptr(arg); \
|
||||
void *p = cp_data(cp); \
|
||||
n = (fl_##ctype##_t)conv_to_##cnvt(p, cp_numtype(cp)); \
|
||||
} else { \
|
||||
return 1; \
|
||||
} \
|
||||
*((fl_##ctype##_t *)dest) = n; \
|
||||
return 0; \
|
||||
#define num_init(ctype, cnvt, tag) \
|
||||
static int cvalue_##ctype##_init(struct fltype *type, value_t arg, \
|
||||
void *dest) \
|
||||
{ \
|
||||
fl_##ctype##_t n = 0; \
|
||||
(void)type; \
|
||||
if (isfixnum(arg)) { \
|
||||
n = numval(arg); \
|
||||
} else if (iscprim(arg)) { \
|
||||
struct cprim *cp = (struct cprim *)ptr(arg); \
|
||||
void *p = cp_data(cp); \
|
||||
n = (fl_##ctype##_t)conv_to_##cnvt(p, cp_numtype(cp)); \
|
||||
} else { \
|
||||
return 1; \
|
||||
} \
|
||||
*((fl_##ctype##_t *)dest) = n; \
|
||||
return 0; \
|
||||
}
|
||||
num_init(int8, int32, T_INT8) num_init(uint8, uint32, T_UINT8)
|
||||
num_init(int16, int32, T_INT16) num_init(uint16, uint32, T_UINT16)
|
||||
|
@ -317,7 +318,7 @@ size_t toulong(value_t n, char *fname)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cvalue_enum_init(fltype_t *ft, value_t arg, void *dest)
|
||||
static int cvalue_enum_init(struct fltype *ft, value_t arg, void *dest)
|
||||
{
|
||||
int n = 0;
|
||||
value_t syms;
|
||||
|
@ -353,7 +354,7 @@ value_t cvalue_enum(value_t *args, u_int32_t nargs)
|
|||
{
|
||||
argcount("enum", nargs, 2);
|
||||
value_t type = fl_list2(enumsym, args[0]);
|
||||
fltype_t *ft = get_type(type);
|
||||
struct fltype *ft = get_type(type);
|
||||
value_t cv = cvalue(ft, sizeof(int32_t));
|
||||
cvalue_enum_init(ft, args[1], cp_data((struct cprim *)ptr(cv)));
|
||||
return cv;
|
||||
|
@ -377,11 +378,11 @@ static size_t predict_arraylen(value_t arg)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int cvalue_array_init(fltype_t *ft, value_t arg, void *dest)
|
||||
static int cvalue_array_init(struct fltype *ft, value_t arg, void *dest)
|
||||
{
|
||||
value_t type = ft->type;
|
||||
size_t elsize, i, cnt, sz;
|
||||
fltype_t *eltype = ft->eltype;
|
||||
struct fltype *eltype = ft->eltype;
|
||||
|
||||
elsize = ft->elsz;
|
||||
cnt = predict_arraylen(arg);
|
||||
|
@ -419,7 +420,7 @@ static int cvalue_array_init(fltype_t *ft, value_t arg, void *dest)
|
|||
} else if (iscvalue(arg)) {
|
||||
cvalue_t *cv = (cvalue_t *)ptr(arg);
|
||||
if (isarray(arg)) {
|
||||
fltype_t *aet = cv_class(cv)->eltype;
|
||||
struct fltype *aet = cv_class(cv)->eltype;
|
||||
if (aet == eltype) {
|
||||
if (cv_len(cv) == sz)
|
||||
memcpy(dest, cv_data(cv), sz);
|
||||
|
@ -448,7 +449,7 @@ value_t cvalue_array(value_t *args, u_int32_t nargs)
|
|||
argcount("array", nargs, 1);
|
||||
|
||||
cnt = nargs - 1;
|
||||
fltype_t *type = get_array_type(args[0]);
|
||||
struct fltype *type = get_array_type(args[0]);
|
||||
elsize = type->elsz;
|
||||
sz = elsize * cnt;
|
||||
|
||||
|
@ -568,7 +569,7 @@ size_t ctype_sizeof(value_t type, int *palign)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern fltype_t *iostreamtype;
|
||||
extern struct fltype *iostreamtype;
|
||||
|
||||
// get pointer and size for any plain-old-data value
|
||||
void to_sized_ptr(value_t v, char *fname, char **pdata, size_t *psz)
|
||||
|
@ -647,7 +648,7 @@ static value_t cvalue_relocate(value_t v)
|
|||
if (isinlined(cv))
|
||||
nv->data = &nv->_space[0];
|
||||
ncv = tagptr(nv, TAG_CVALUE);
|
||||
fltype_t *t = cv_class(cv);
|
||||
struct fltype *t = cv_class(cv);
|
||||
if (t->vtable != NULL && t->vtable->relocate != NULL)
|
||||
t->vtable->relocate(v, ncv);
|
||||
forward(v, ncv);
|
||||
|
@ -672,7 +673,8 @@ value_t cvalue_copy(value_t v)
|
|||
memcpy(ncv->data, cv_data(cv), len);
|
||||
autorelease(ncv);
|
||||
if (hasparent(cv)) {
|
||||
ncv->type = (fltype_t *)(((uptrint_t)ncv->type) & ~CV_PARENT_BIT);
|
||||
ncv->type =
|
||||
(struct fltype *)(((uptrint_t)ncv->type) & ~CV_PARENT_BIT);
|
||||
ncv->parent = NIL;
|
||||
}
|
||||
} else {
|
||||
|
@ -703,7 +705,7 @@ value_t fl_podp(value_t *args, u_int32_t nargs)
|
|||
: FL_F;
|
||||
}
|
||||
|
||||
static void cvalue_init(fltype_t *type, value_t v, void *dest)
|
||||
static void cvalue_init(struct fltype *type, value_t v, void *dest)
|
||||
{
|
||||
cvinitfunc_t f = type->init;
|
||||
|
||||
|
@ -763,7 +765,7 @@ value_t cvalue_new(value_t *args, u_int32_t nargs)
|
|||
if (nargs < 1 || nargs > 2)
|
||||
argcount("c-value", nargs, 2);
|
||||
value_t type = args[0];
|
||||
fltype_t *ft = get_type(type);
|
||||
struct fltype *ft = get_type(type);
|
||||
value_t cv;
|
||||
if (ft->eltype != NULL) {
|
||||
// special case to handle incomplete array types bla[]
|
||||
|
@ -823,7 +825,7 @@ static value_t cvalue_array_aref(value_t *args)
|
|||
{
|
||||
char *data;
|
||||
ulong_t index;
|
||||
fltype_t *eltype = cv_class((cvalue_t *)ptr(args[0]))->eltype;
|
||||
struct fltype *eltype = cv_class((cvalue_t *)ptr(args[0]))->eltype;
|
||||
value_t el = 0;
|
||||
numerictype_t nt = eltype->numtype;
|
||||
if (nt >= T_INT32)
|
||||
|
@ -857,7 +859,7 @@ static value_t cvalue_array_aset(value_t *args)
|
|||
{
|
||||
char *data;
|
||||
ulong_t index;
|
||||
fltype_t *eltype = cv_class((cvalue_t *)ptr(args[0]))->eltype;
|
||||
struct fltype *eltype = cv_class((cvalue_t *)ptr(args[0]))->eltype;
|
||||
check_addr_args("aset!", args[0], args[1], &data, &index);
|
||||
char *dest = data + index * eltype->size;
|
||||
cvalue_init(eltype, args[2], dest);
|
||||
|
|
41
c/flisp.h
41
c/flisp.h
|
@ -18,7 +18,7 @@ struct cons {
|
|||
struct symbol {
|
||||
uptrint_t flags;
|
||||
value_t binding; // global value binding
|
||||
struct _fltype_t *type;
|
||||
struct fltype *type;
|
||||
uint32_t hash;
|
||||
void *dlcache; // dlsym address
|
||||
// below fields are private
|
||||
|
@ -33,7 +33,7 @@ struct symbol {
|
|||
struct gensym {
|
||||
value_t isconst;
|
||||
value_t binding; // global value binding
|
||||
struct _fltype_t *type;
|
||||
struct fltype *type;
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
|
@ -248,22 +248,22 @@ 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);
|
||||
|
||||
typedef int (*cvinitfunc_t)(struct _fltype_t *, value_t, void *);
|
||||
typedef int (*cvinitfunc_t)(struct fltype *, value_t, void *);
|
||||
|
||||
typedef struct _fltype_t {
|
||||
struct fltype {
|
||||
value_t type;
|
||||
numerictype_t numtype;
|
||||
size_t size;
|
||||
size_t elsz;
|
||||
struct cvtable *vtable;
|
||||
struct _fltype_t *eltype; // for arrays
|
||||
struct _fltype_t *artype; // (array this)
|
||||
struct fltype *eltype; // for arrays
|
||||
struct fltype *artype; // (array this)
|
||||
int marked;
|
||||
cvinitfunc_t init;
|
||||
} fltype_t;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
fltype_t *type;
|
||||
struct fltype *type;
|
||||
void *data;
|
||||
size_t len; // length of *data in bytes
|
||||
union {
|
||||
|
@ -275,7 +275,7 @@ typedef struct {
|
|||
#define CVALUE_NWORDS 4
|
||||
|
||||
struct cprim {
|
||||
fltype_t *type;
|
||||
struct fltype *type;
|
||||
char _space[1];
|
||||
};
|
||||
|
||||
|
@ -294,7 +294,7 @@ struct function {
|
|||
#define owned(cv) ((uptrint_t)(cv)->type & CV_OWNED_BIT)
|
||||
#define hasparent(cv) ((uptrint_t)(cv)->type & CV_PARENT_BIT)
|
||||
#define isinlined(cv) ((cv)->data == &(cv)->_space[0])
|
||||
#define cv_class(cv) ((fltype_t *)(((uptrint_t)(cv)->type) & ~3))
|
||||
#define cv_class(cv) ((struct fltype *)(((uptrint_t)(cv)->type) & ~3))
|
||||
#define cv_len(cv) ((cv)->len)
|
||||
#define cv_type(cv) (cv_class(cv)->type)
|
||||
#define cv_data(cv) ((cv)->data)
|
||||
|
@ -344,18 +344,19 @@ 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 struct fltype *bytetype, *wchartype;
|
||||
extern struct fltype *stringtype, *wcstringtype;
|
||||
extern struct fltype *builtintype;
|
||||
|
||||
value_t cvalue(fltype_t *type, size_t sz);
|
||||
value_t cvalue(struct fltype *type, size_t sz);
|
||||
void add_finalizer(cvalue_t *cv);
|
||||
void cv_autorelease(cvalue_t *cv);
|
||||
void cv_pin(cvalue_t *cv);
|
||||
size_t ctype_sizeof(value_t type, int *palign);
|
||||
value_t cvalue_copy(value_t v);
|
||||
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_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);
|
||||
value_t cbuiltin(char *name, builtin_t f);
|
||||
size_t cvalue_arraylen(value_t v);
|
||||
value_t size_wrap(size_t sz);
|
||||
|
@ -374,10 +375,10 @@ int numeric_compare(value_t a, value_t b, int eq, int eqnans, char *fname);
|
|||
|
||||
void to_sized_ptr(value_t v, char *fname, char **pdata, size_t *psz);
|
||||
|
||||
fltype_t *get_type(value_t t);
|
||||
fltype_t *get_array_type(value_t eltype);
|
||||
fltype_t *define_opaque_type(value_t sym, size_t sz, struct cvtable *vtab,
|
||||
cvinitfunc_t init);
|
||||
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);
|
||||
|
||||
value_t mk_double(fl_double_t n);
|
||||
value_t mk_float(fl_float_t n);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
static value_t iostreamsym, rdsym, wrsym, apsym, crsym, truncsym;
|
||||
static value_t instrsym, outstrsym;
|
||||
fltype_t *iostreamtype;
|
||||
struct fltype *iostreamtype;
|
||||
|
||||
void print_iostream(value_t v, struct ios *f)
|
||||
{
|
||||
|
@ -267,7 +267,7 @@ value_t fl_ioread(value_t *args, u_int32_t nargs)
|
|||
argcount("io.read", nargs, 2);
|
||||
(void)toiostream(args[0], "io.read");
|
||||
size_t n;
|
||||
fltype_t *ft;
|
||||
struct fltype *ft;
|
||||
if (nargs == 3) {
|
||||
// form (io.read s type count)
|
||||
ft = get_array_type(args[1]);
|
||||
|
|
|
@ -90,7 +90,7 @@ void print_traverse(value_t v)
|
|||
// don't consider shared references to ""
|
||||
if (!cv_isstr(cv) || cv_len(cv) != 0)
|
||||
mark_cons(v);
|
||||
fltype_t *t = cv_class(cv);
|
||||
struct fltype *t = cv_class(cv);
|
||||
if (t->vtable != NULL && t->vtable->print_traverse != NULL)
|
||||
t->vtable->print_traverse(v);
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ value_t fl_string_encode(value_t *args, u_int32_t nargs)
|
|||
argcount("string.encode", nargs, 1);
|
||||
if (iscvalue(args[0])) {
|
||||
cvalue_t *cv = (cvalue_t *)ptr(args[0]);
|
||||
fltype_t *t = cv_class(cv);
|
||||
struct fltype *t = cv_class(cv);
|
||||
if (t->eltype == wchartype) {
|
||||
size_t nc = cv_len(cv) / sizeof(uint32_t);
|
||||
uint32_t *ptr = (uint32_t *)cv_data(cv);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "equalhash.h"
|
||||
|
||||
static value_t tablesym;
|
||||
static fltype_t *tabletype;
|
||||
static struct fltype *tabletype;
|
||||
|
||||
void print_htable(value_t v, struct ios *f)
|
||||
{
|
||||
|
|
20
c/types.h
20
c/types.h
|
@ -1,6 +1,6 @@
|
|||
fltype_t *get_type(value_t t)
|
||||
struct fltype *get_type(value_t t)
|
||||
{
|
||||
fltype_t *ft;
|
||||
struct fltype *ft;
|
||||
if (issymbol(t)) {
|
||||
ft = ((struct symbol *)ptr(t))->type;
|
||||
if (ft != NULL)
|
||||
|
@ -20,7 +20,7 @@ fltype_t *get_type(value_t t)
|
|||
sz = ctype_sizeof(t, &align);
|
||||
}
|
||||
|
||||
ft = (fltype_t *)malloc(sizeof(fltype_t));
|
||||
ft = (struct fltype *)malloc(sizeof(struct fltype));
|
||||
ft->type = t;
|
||||
if (issymbol(t)) {
|
||||
ft->numtype = sym_to_numtype(t);
|
||||
|
@ -37,7 +37,7 @@ fltype_t *get_type(value_t t)
|
|||
ft->init = NULL;
|
||||
if (iscons(t)) {
|
||||
if (isarray) {
|
||||
fltype_t *eltype = get_type(car_(cdr_(t)));
|
||||
struct fltype *eltype = get_type(car_(cdr_(t)));
|
||||
if (eltype->size == 0) {
|
||||
free(ft);
|
||||
lerror(ArgError, "invalid array element type");
|
||||
|
@ -56,18 +56,18 @@ fltype_t *get_type(value_t t)
|
|||
return ft;
|
||||
}
|
||||
|
||||
fltype_t *get_array_type(value_t eltype)
|
||||
struct fltype *get_array_type(value_t eltype)
|
||||
{
|
||||
fltype_t *et = get_type(eltype);
|
||||
struct fltype *et = get_type(eltype);
|
||||
if (et->artype == NULL)
|
||||
et->artype = get_type(fl_list2(arraysym, eltype));
|
||||
return et->artype;
|
||||
}
|
||||
|
||||
fltype_t *define_opaque_type(value_t sym, size_t sz, struct cvtable *vtab,
|
||||
cvinitfunc_t init)
|
||||
struct fltype *define_opaque_type(value_t sym, size_t sz,
|
||||
struct cvtable *vtab, cvinitfunc_t init)
|
||||
{
|
||||
fltype_t *ft = (fltype_t *)malloc(sizeof(fltype_t));
|
||||
struct fltype *ft = (struct fltype *)malloc(sizeof(struct fltype));
|
||||
ft->type = sym;
|
||||
ft->size = sz;
|
||||
ft->numtype = N_NUMTYPES;
|
||||
|
@ -90,7 +90,7 @@ void relocate_typetable(void)
|
|||
nv = (void *)relocate((value_t)h->table[i]);
|
||||
h->table[i] = nv;
|
||||
if (h->table[i + 1] != HT_NOTFOUND)
|
||||
((fltype_t *)h->table[i + 1])->type = (value_t)nv;
|
||||
((struct fltype *)h->table[i + 1])->type = (value_t)nv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue