+ 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_SLOT) {
+ 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);
+ }
+ 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_SLOT) {
+ 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);
+ }
+}
+// ------------------------- constructors --------------------------------
+
+#define AVERAGE_NUMBER_OF_MEMBERS 8
+classinfo_t* classinfo_register(int access, const char*package, const char*name, int num_interfaces)
+{
+ classinfo_t*c = rfx_calloc(sizeof(classinfo_t)+(sizeof(classinfo_t*)*(num_interfaces+1)));
+ c->interfaces[0] = 0;
+ c->kind = INFOTYPE_CLASS;
+ c->access = access;
+ c->package = package;
+ c->name = name;
+ dict_put(registry_classes, c, c);
+ dict_init2(&c->members, &memberinfo_type, AVERAGE_NUMBER_OF_MEMBERS);
+
+ schedule_for_resolve((slotinfo_t*)c);
+ return c;
+}
+methodinfo_t* methodinfo_register_onclass(classinfo_t*cls, U8 access, const char*ns, const char*name)
+{
+ NEW(methodinfo_t,m);
+ m->kind = INFOTYPE_METHOD;
+ m->access = access;
+ m->name = name;
+ m->package = ns;
+ m->parent = cls;
+ dict_put(&cls->members, m, m);
+ return m;
+}
+varinfo_t* varinfo_register_onclass(classinfo_t*cls, U8 access, const char*ns, const char*name)
+{
+ NEW(varinfo_t,m);
+ m->kind = INFOTYPE_SLOT;
+ m->access = access;
+ m->name = name;
+ m->package = ns;
+ m->parent = cls;
+ dict_put(&cls->members, m, m);
+ return m;
+}
+methodinfo_t* methodinfo_register_global(U8 access, const char*package, const char*name)
+{
+ NEW(methodinfo_t, m);
+ m->kind = INFOTYPE_METHOD;
+ m->flags = FLAG_STATIC;
+ m->access = access;
+ m->package = package;
+ m->name = name;
+ m->parent = 0;
+ dict_put(registry_classes, m, m);
+
+ schedule_for_resolve((slotinfo_t*)m);
+ return m;
+}
+varinfo_t* varinfo_register_global(U8 access, const char*package, const char*name)
+{
+ NEW(varinfo_t, m);
+ m->kind = INFOTYPE_SLOT;
+ m->flags = FLAG_STATIC;
+ m->access = access;
+ m->package = package;
+ m->name = name;
+ m->parent = 0;
+ dict_put(registry_classes, m, m);
+
+ schedule_for_resolve((slotinfo_t*)m);
+ return m;
+}
+
+// --------------- builtin classes (from builtin.c) ----------------------
+
+void registry_init()
+{
+ if(!registry_classes)
+ registry_classes = builtin_getclasses();
+}
+slotinfo_t* registry_find(const char*package, const char*name)