HL_PRIM void hl_init_enum( hl_type *et, hl_module_context *m ) { int i, j; int mark_size = 0; unsigned int *mark; for(i=0;i<et->tenum->nconstructs;i++) { hl_enum_construct *c = et->tenum->constructs + i; c->hasptr = false; c->size = sizeof(void*)+sizeof(int); // t + index for(j=0;j<c->nparams;j++) { hl_type *t = c->params[j]; c->size += hl_pad_struct(c->size,t); c->offsets[j] = c->size; if( hl_is_ptr(t) ) c->hasptr = true; c->size += hl_type_size(t); } if( c->hasptr ) { int max_pos = i * sizeof(int) + hl_mark_size(c->size - HL_WSIZE*2); if( max_pos > mark_size ) mark_size = max_pos; } } mark = (unsigned int*)hl_zalloc(&m->alloc,mark_size); for(i=0;i<et->tenum->nconstructs;i++) { hl_enum_construct *c = et->tenum->constructs + i; if( !c->hasptr ) continue; for(j=0;j<c->nparams;j++) if( hl_is_ptr(c->params[j]) ) { int pos = (c->offsets[j] / HL_WSIZE) - 2; mark[i + (pos >> 5)] |= 1 << (pos & 31); } }
static void hl_read_type( hl_reader *r, hl_type *t ) { t->kind = READ(); switch( (int)t->kind ) { case HFUN: case HMETHOD: { int i; int nargs = READ(); t->fun = (hl_type_fun*)hl_zalloc(&r->code->alloc,sizeof(hl_type_fun)); t->fun->nargs = nargs; t->fun->args = (hl_type**)hl_malloc(&r->code->alloc,sizeof(hl_type*)*nargs); for(i=0;i<nargs;i++) t->fun->args[i] = hl_get_type(r); t->fun->ret = hl_get_type(r); } break; case HOBJ: { int i; const uchar *name = hl_read_ustring(r); int super = INDEX(); int global = UINDEX(); int nfields = UINDEX(); int nproto = UINDEX(); int nbindings = UINDEX(); t->obj = (hl_type_obj*)hl_malloc(&r->code->alloc,sizeof(hl_type_obj)); t->obj->name = name; t->obj->super = super < 0 ? NULL : r->code->types + super; t->obj->global_value = (void**)(int_val)global; t->obj->nfields = nfields; t->obj->nproto = nproto; t->obj->nbindings = nbindings; t->obj->fields = (hl_obj_field*)hl_malloc(&r->code->alloc,sizeof(hl_obj_field)*nfields); t->obj->proto = (hl_obj_proto*)hl_malloc(&r->code->alloc,sizeof(hl_obj_proto)*nproto); t->obj->bindings = (int*)hl_malloc(&r->code->alloc,sizeof(int)*nbindings*2); t->obj->rt = NULL; for(i=0;i<nfields;i++) { hl_obj_field *f = t->obj->fields + i; f->name = hl_read_ustring(r); f->hashed_name = hl_hash_gen(f->name,true); f->t = hl_get_type(r); } for(i=0;i<nproto;i++) { hl_obj_proto *p = t->obj->proto + i; p->name = hl_read_ustring(r); p->hashed_name = hl_hash_gen(p->name,true); p->findex = UINDEX(); p->pindex = INDEX(); } for(i=0;i<nbindings;i++) { t->obj->bindings[i<<1] = UINDEX(); t->obj->bindings[(i<<1)|1] = UINDEX(); } } break; case HREF: t->tparam = hl_get_type(r); break; case HVIRTUAL: { int i; int nfields = UINDEX(); t->virt = (hl_type_virtual*)hl_malloc(&r->code->alloc,sizeof(hl_type_virtual)); t->virt->nfields = nfields; t->virt->fields = (hl_obj_field*)hl_malloc(&r->code->alloc,sizeof(hl_obj_field)*nfields); for(i=0;i<nfields;i++) { hl_obj_field *f = t->virt->fields + i; f->name = hl_read_ustring(r); f->hashed_name = hl_hash_gen(f->name,true); f->t = hl_get_type(r); } } break; case HABSTRACT: t->abs_name = hl_read_ustring(r); break; case HENUM: { int i,j; t->tenum = hl_malloc(&r->code->alloc,sizeof(hl_type_enum)); t->tenum->name = hl_read_ustring(r); t->tenum->global_value = (void**)(int_val)UINDEX(); t->tenum->nconstructs = READ(); t->tenum->constructs = (hl_enum_construct*)hl_malloc(&r->code->alloc, sizeof(hl_enum_construct)*t->tenum->nconstructs); for(i=0;i<t->tenum->nconstructs;i++) { hl_enum_construct *c = t->tenum->constructs + i; c->name = hl_read_ustring(r); c->nparams = UINDEX(); c->params = (hl_type**)hl_malloc(&r->code->alloc,sizeof(hl_type*)*c->nparams); c->offsets = (int*)hl_malloc(&r->code->alloc,sizeof(int)*c->nparams); for(j=0;j<c->nparams;j++) c->params[j] = hl_get_type(r); } } break; case HNULL: t->tparam = hl_get_type(r); break; default: if( t->kind >= HLAST ) ERROR("Invalid type"); break; } }