2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *get_type(value_t t)
|
2008-12-10 23:04:17 -05:00
|
|
|
{
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *ft;
|
2019-08-18 18:14:09 -04:00
|
|
|
void **bp;
|
|
|
|
size_t sz;
|
|
|
|
int align, isarray;
|
|
|
|
|
2008-12-10 23:04:17 -05:00
|
|
|
if (issymbol(t)) {
|
2019-08-09 12:30:15 -04:00
|
|
|
ft = ((struct symbol *)ptr(t))->type;
|
2008-12-10 23:04:17 -05:00
|
|
|
if (ft != NULL)
|
|
|
|
return ft;
|
|
|
|
}
|
2019-08-18 18:14:09 -04:00
|
|
|
bp = equalhash_bp(&TypeTable, (void *)t);
|
2008-12-10 23:04:17 -05:00
|
|
|
if (*bp != HT_NOTFOUND)
|
|
|
|
return *bp;
|
2019-08-09 07:02:02 -04:00
|
|
|
isarray = (iscons(t) && car_(t) == arraysym && iscons(cdr_(t)));
|
2008-12-10 23:04:17 -05:00
|
|
|
if (isarray && !iscons(cdr_(cdr_(t)))) {
|
|
|
|
// special case: incomplete array type
|
|
|
|
sz = 0;
|
2019-08-09 07:02:02 -04:00
|
|
|
} else {
|
2008-12-10 23:04:17 -05:00
|
|
|
sz = ctype_sizeof(t, &align);
|
|
|
|
}
|
2019-08-09 12:33:04 -04:00
|
|
|
ft = (struct fltype *)malloc(sizeof(struct fltype));
|
2008-12-10 23:04:17 -05:00
|
|
|
ft->type = t;
|
|
|
|
if (issymbol(t)) {
|
|
|
|
ft->numtype = sym_to_numtype(t);
|
2019-08-09 12:30:15 -04:00
|
|
|
((struct symbol *)ptr(t))->type = ft;
|
2019-08-09 07:02:02 -04:00
|
|
|
} else {
|
2008-12-10 23:04:17 -05:00
|
|
|
ft->numtype = N_NUMTYPES;
|
|
|
|
}
|
|
|
|
ft->size = sz;
|
|
|
|
ft->vtable = NULL;
|
|
|
|
ft->artype = NULL;
|
|
|
|
ft->marked = 1;
|
|
|
|
ft->elsz = 0;
|
|
|
|
ft->eltype = NULL;
|
|
|
|
ft->init = NULL;
|
|
|
|
if (iscons(t)) {
|
|
|
|
if (isarray) {
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *eltype = get_type(car_(cdr_(t)));
|
2009-03-01 23:26:16 -05:00
|
|
|
if (eltype->size == 0) {
|
2010-05-03 01:07:22 -04:00
|
|
|
free(ft);
|
2009-03-01 23:26:16 -05:00
|
|
|
lerror(ArgError, "invalid array element type");
|
|
|
|
}
|
2008-12-10 23:04:17 -05:00
|
|
|
ft->elsz = eltype->size;
|
|
|
|
ft->eltype = eltype;
|
|
|
|
ft->init = &cvalue_array_init;
|
2019-08-09 07:02:02 -04:00
|
|
|
// eltype->artype = ft; -- this is a bad idea since some types
|
|
|
|
// carry array sizes
|
|
|
|
} else if (car_(t) == enumsym) {
|
2008-12-10 23:04:17 -05:00
|
|
|
ft->numtype = T_INT32;
|
|
|
|
ft->init = &cvalue_enum_init;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*bp = ft;
|
|
|
|
return ft;
|
|
|
|
}
|
|
|
|
|
2019-08-09 12:33:04 -04:00
|
|
|
struct fltype *get_array_type(value_t eltype)
|
2008-12-10 23:04:17 -05:00
|
|
|
{
|
2019-08-18 18:14:09 -04:00
|
|
|
struct fltype *et;
|
|
|
|
|
|
|
|
et = get_type(eltype);
|
2017-08-18 13:48:32 -04:00
|
|
|
if (et->artype == NULL)
|
|
|
|
et->artype = get_type(fl_list2(arraysym, eltype));
|
|
|
|
return et->artype;
|
2008-12-10 23:04:17 -05:00
|
|
|
}
|
|
|
|
|
2019-08-09 12:33:04 -04:00
|
|
|
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-18 18:14:09 -04:00
|
|
|
struct fltype *ft;
|
|
|
|
|
|
|
|
ft = (struct fltype *)malloc(sizeof(struct fltype));
|
2008-12-10 23:04:17 -05:00
|
|
|
ft->type = sym;
|
|
|
|
ft->size = sz;
|
|
|
|
ft->numtype = N_NUMTYPES;
|
|
|
|
ft->vtable = vtab;
|
|
|
|
ft->artype = NULL;
|
|
|
|
ft->eltype = NULL;
|
|
|
|
ft->elsz = 0;
|
|
|
|
ft->marked = 1;
|
|
|
|
ft->init = init;
|
|
|
|
return ft;
|
|
|
|
}
|
|
|
|
|
2013-06-08 19:29:15 -04:00
|
|
|
void relocate_typetable(void)
|
2008-12-10 23:04:17 -05:00
|
|
|
{
|
2019-08-18 18:14:09 -04:00
|
|
|
struct htable *h;
|
2008-12-10 23:04:17 -05:00
|
|
|
size_t i;
|
|
|
|
void *nv;
|
2019-08-18 18:14:09 -04:00
|
|
|
|
|
|
|
h = &TypeTable;
|
2019-08-09 07:02:02 -04:00
|
|
|
for (i = 0; i < h->size; i += 2) {
|
2008-12-10 23:04:17 -05:00
|
|
|
if (h->table[i] != HT_NOTFOUND) {
|
2019-08-09 07:02:02 -04:00
|
|
|
nv = (void *)relocate((value_t)h->table[i]);
|
2008-12-10 23:04:17 -05:00
|
|
|
h->table[i] = nv;
|
2019-08-09 07:02:02 -04:00
|
|
|
if (h->table[i + 1] != HT_NOTFOUND)
|
2019-08-09 12:33:04 -04:00
|
|
|
((struct fltype *)h->table[i + 1])->type = (value_t)nv;
|
2008-12-10 23:04:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|