+ 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);
+ }
+}
+// ------------------------- 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);
+ dict_init2(&c->static_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, char is_static)
+{
+ NEW(methodinfo_t,m);
+ m->kind = INFOTYPE_METHOD;
+ m->access = access;
+ m->name = name;
+ m->package = ns;
+ m->parent = cls;
+ if(!is_static)
+ dict_put(&cls->members, m, m);
+ else
+ dict_put(&cls->static_members, m, m);
+ return m;
+}
+varinfo_t* varinfo_register_onclass(classinfo_t*cls, U8 access, const char*ns, const char*name, char is_static)
+{
+ NEW(varinfo_t,m);
+ m->kind = INFOTYPE_VAR;
+ m->access = access;
+ m->name = name;
+ m->package = ns;
+ m->parent = cls;
+ if(!is_static)
+ dict_put(&cls->members, m, m);
+ else
+ dict_put(&cls->static_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_VAR;
+ 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)
+{
+ assert(registry_classes);
+ slotinfo_t tmp;
+ tmp.package = package;
+ tmp.name = name;
+ slotinfo_t* c = (slotinfo_t*)dict_lookup(registry_classes, &tmp);
+ /*if(c)
+ printf("%s.%s->%08x (%s.%s)\n", package, name, c, c->package, c->name);*/
+ return c;
+}
+slotinfo_t* registry_safefind(const char*package, const char*name)
+{
+ slotinfo_t*c = registry_find(package, name);
+ if(!c) {
+ printf("%s.%s\n", package, name);
+ }
+ assert(c);
+ return c;
+}
+void registry_dump()
+{
+ int t;
+ for(t=0;t<registry_classes->hashsize;t++) {
+ dictentry_t*e = registry_classes->slots[t];
+ while(e) {
+ slotinfo_t*i = (slotinfo_t*)e->key;
+ printf("[%s] %s.%s\n", access2str(i->access), i->package, i->name);
+ e = e->next;
+ }
+ }
+}
+
+memberinfo_t* registry_findmember(classinfo_t*cls, const char*ns, const char*name, char recursive, char is_static)
+{
+ memberinfo_t tmp;
+ tmp.name = name;
+ tmp.package = ns?ns:"";
+
+ if(!recursive) {
+ if(!is_static)
+ return (memberinfo_t*)dict_lookup(&cls->members, &tmp);
+ else
+ return (memberinfo_t*)dict_lookup(&cls->static_members, &tmp);
+ }
+ /* look at classes directly extended by this class */
+ slotinfo_t*m = 0;
+ classinfo_t*s = cls;
+
+ if(recursive>1) // check *only* superclasses
+ s = s->superclass;
+
+ while(s) {
+ if(s->kind == INFOTYPE_UNRESOLVED)
+ break;
+
+ if(!is_static) {
+ m = (slotinfo_t*)dict_lookup(&s->members, &tmp);
+ if(m) return (memberinfo_t*)m;
+ }
+ m = (slotinfo_t*)dict_lookup(&s->static_members, &tmp);
+ if(m) return (memberinfo_t*)m;
+
+ s = s->superclass;
+ }
+ /* look at interfaces, and parent interfaces */
+ int t=0;
+ while(cls->interfaces[t]) {
+ classinfo_t*s = cls->interfaces[t];
+ if(s->kind != INFOTYPE_UNRESOLVED) {
+ while(s) {
+ if(!is_static) {
+ m = (slotinfo_t*)dict_lookup(&s->members, &tmp);
+ if(m) return (memberinfo_t*)m;
+ }
+ m = (slotinfo_t*)dict_lookup(&s->static_members, &tmp);
+ if(m) return (memberinfo_t*)m;
+
+ s = s->superclass;
+ }
+ }
+ t++;
+ }
+ return 0;
+}
+
+memberinfo_t* registry_findmember_nsset(classinfo_t*cls, namespace_list_t*ns, const char*name, char superclasses, char is_static)
+{
+ memberinfo_t*m = 0;
+ while(ns) {
+ m = registry_findmember(cls, ns->namespace->name, name, superclasses, is_static);
+ if(m) return m;
+ ns = ns->next;
+ }
+ m = registry_findmember(cls, "", name, superclasses, is_static);
+ if(m) return m;
+ /* TODO: it maybe would be faster to just store the builtin namespace as "" in
+ builtins.c (update: some members (e.g. XML.length) are present both for
+ "" and "http:...builtin") */
+ m = registry_findmember(cls, "http://adobe.com/AS3/2006/builtin", name, superclasses, is_static);
+ if(m) return m;
+ return 0;
+}
+
+
+void registry_fill_multiname(multiname_t*m, namespace_t*n, slotinfo_t*c)
+{
+ m->type = QNAME;
+ m->ns = n;
+ m->ns->access = c->access;
+ m->ns->name = (char*)c->package;
+ m->name = c->name;
+ m->namespace_set = 0;
+}
+multiname_t* classinfo_to_multiname(slotinfo_t*cls)
+{
+ if(!cls)
+ return 0;