+// ----------------------- assets -------------------------------------
+static void use_asset(asset_bundle_t*a)
+{
+ a->used = 1;
+ asset_bundle_list_t*l = a->dependencies;
+ while(l) {
+ if(!l->asset_bundle->used) {
+ use_asset(l->asset_bundle);
+ }
+ l = l->next;
+ }
+}
+void registry_use(slotinfo_t*s)
+{
+ if(!s) return;
+ if(!(s->flags&FLAG_USED)) {
+ s->flags |= FLAG_USED;
+ if(s->kind == INFOTYPE_CLASS) {
+ classinfo_t*c=(classinfo_t*)s;
+ if(c->assets) {
+ use_asset(c->assets);
+ }
+ int t=0;
+ while(c->interfaces[t]) {
+ registry_use((slotinfo_t*)c->interfaces[t]);
+ t++;
+ }
+ while(c->superclass) {
+ c = c->superclass;
+ registry_use((slotinfo_t*)c);
+ }
+ } else if(s->kind == INFOTYPE_METHOD) {
+ methodinfo_t*m=(methodinfo_t*)s;
+ if(m->parent) {
+ registry_use((slotinfo_t*)m->parent);
+ }
+ } else if(s->kind == INFOTYPE_VAR) {
+ varinfo_t*v=(varinfo_t*)s;
+ if(v->parent) {
+ registry_use((slotinfo_t*)v->parent);
+ }
+ }
+ }
+}
+void registry_add_asset(asset_bundle_t*bundle)
+{
+ list_append(assets, bundle);
+}
+asset_bundle_list_t*registry_getassets()
+{
+ return assets;
+}
+// ----------------------- resolving ----------------------------------
+slotinfo_t* registry_resolve(slotinfo_t*_s)
+{
+ if(!_s || _s->kind != INFOTYPE_UNRESOLVED)
+ return _s;
+ unresolvedinfo_t*s = (unresolvedinfo_t*)_s;
+
+ if(s->package)
+ return registry_find(s->package, s->name);
+
+ namespace_list_t*l = s->nsset;
+ while(l) {
+ slotinfo_t* n = registry_find(l->namespace->name, s->name);
+ if(n) return n;
+ l = l->next;
+ }
+ return 0;
+}
+
+static slotinfo_list_t*unresolved = 0;
+static void schedule_for_resolve(slotinfo_t*s)
+{
+ list_append(unresolved, s);
+}
+static void resolve_on_slot(slotinfo_t*_member)
+{
+ if(_member->kind == INFOTYPE_VAR) {
+ varinfo_t*member = (varinfo_t*)_member;
+ member->type = (classinfo_t*)registry_resolve((slotinfo_t*)member->type);
+ } else if(_member->kind == INFOTYPE_METHOD) {
+ methodinfo_t*member = (methodinfo_t*)_member;
+ member->return_type = (classinfo_t*)registry_resolve((slotinfo_t*)member->return_type);
+ classinfo_list_t*l = member->params;
+ while(l) {
+ l->classinfo = (classinfo_t*)registry_resolve((slotinfo_t*)l->classinfo);
+ l = l->next;
+ }
+ } else fprintf(stderr, "Internal Error: bad slot %s", _member->name);
+}
+static void resolve_on_class(slotinfo_t*_cls)
+{
+ classinfo_t*cls = (classinfo_t*)_cls;
+ cls->superclass = (classinfo_t*)registry_resolve((slotinfo_t*)cls->superclass);
+
+ DICT_ITERATE_DATA(&cls->members,slotinfo_t*,m) {
+ resolve_on_slot(m);
+ }
+ DICT_ITERATE_DATA(&cls->static_members,slotinfo_t*,m2) {
+ resolve_on_slot(m2);
+ }
+
+ int t=0;
+ while(cls->interfaces[t]) {
+ cls->interfaces[t] = (classinfo_t*)registry_resolve((slotinfo_t*)cls->interfaces[t]);
+ t++;
+ }
+}
+void registry_resolve_all()
+{
+ while(unresolved) {
+ slotinfo_t*_s = unresolved->slotinfo;
+ if(_s->kind == INFOTYPE_CLASS) {
+ resolve_on_class(_s);
+ } else if(_s->kind == INFOTYPE_METHOD || _s->kind == INFOTYPE_VAR) {
+ resolve_on_slot(_s);
+ } else {
+ fprintf(stderr, "Internal Error: object %s.%s has bad type\n", _s->package, _s->name);
+ }
+ slotinfo_list_t*tofree = unresolved;
+ unresolved = unresolved->next;
+ free(tofree);
+ }
+}