+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;
+ multiname_t*m=0;
+ namespace_t ns = {cls->access, (char*)cls->package};
+ return multiname_new(&ns,cls->name);
+}
+
+// ----------------------- memberinfo methods ------------------------------
+
+/* hacky code to wrap a variable or function into a "type"
+ object, but keep a pointer to the "value" */
+static dict_t* functionobjects = 0;
+classinfo_t* slotinfo_asclass(slotinfo_t*f) {
+ if(!functionobjects) {
+ functionobjects = dict_new2(&ptr_type);
+ } else {
+ classinfo_t*c = dict_lookup(functionobjects, f);
+ if(c)
+ return c;
+ }
+
+ classinfo_t*c = rfx_calloc(sizeof(classinfo_t)+sizeof(classinfo_t*));
+ c->access = ACCESS_PUBLIC;
+ c->package = "";
+ if(f->kind == INFOTYPE_METHOD) {
+ c->name = "Function";
+ c->superclass = registry_getobjectclass();
+ } else if(f->kind == INFOTYPE_CLASS) {
+ c->name = "Class";
+ c->superclass = registry_getobjectclass();
+ } else if(f->kind == INFOTYPE_VAR) {
+ c->name = "Object";
+ } else {
+ c->name = "undefined";
+ }
+
+ dict_init2(&c->members, &memberinfo_type, 1);
+ dict_init2(&c->static_members, &memberinfo_type, 1);
+ c->data = f;
+ dict_put(functionobjects, f, c);
+ return c;
+}
+
+classinfo_t* slotinfo_gettype(slotinfo_t*f)
+{
+ if(f) {
+ if(f->kind == INFOTYPE_METHOD) {
+ return slotinfo_asclass(f);
+ } else if(f->kind == INFOTYPE_VAR) {
+ varinfo_t*v = (varinfo_t*)f;
+ return v->type;
+ } else
+ return 0;
+ } else {
+ return TYPE_ANY;
+ }
+}
+
+// ----------------------- package handling ---------------------------
+char registry_ispackage(const char*package)
+{
+ /* crude approximation of "the real thing", but sufficient for now */
+ return !strncmp(package, "flash", 5);
+}
+// ----------------------- builtin types ------------------------------
+
+char registry_isfunctionclass(classinfo_t*c) {
+ return (c && c->package && c->name &&
+ !strcmp(c->package, "") && !strcmp(c->name, "Function"));
+}
+char registry_isclassclass(classinfo_t*c) {
+ return (c && c->package && c->name &&
+ !strcmp(c->package, "") && !strcmp(c->name, "Class"));
+}
+
+classinfo_t* registry_getobjectclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "Object");
+ return c;
+}
+classinfo_t* registry_getstringclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "String");
+ return c;
+}
+classinfo_t* registry_getarrayclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "Array");
+ return c;
+}
+classinfo_t* registry_getintclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "int");
+ return c;
+}
+classinfo_t* registry_getuintclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "uint");
+ return c;
+}
+classinfo_t* registry_getbooleanclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "Boolean");
+ return c;
+}
+classinfo_t* registry_getnumberclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "Number");
+ return c;
+}
+classinfo_t* registry_getregexpclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "RegExp");
+ return c;
+}
+classinfo_t* registry_getdateclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "Date");
+ return c;
+}
+classinfo_t* registry_getxmlclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "XML");
+ return c;
+}
+classinfo_t* registry_getxmllistclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "XMLList");
+ return c;
+}
+classinfo_t* registry_getnamespaceclass() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("", "Namespace");
+ return c;
+}
+classinfo_t* registry_getMovieClip() {
+ static classinfo_t*c = 0;
+ if(!c) c = (classinfo_t*)registry_safefind("flash.display", "MovieClip");
+ return c;
+}
+
+// ----------------------- builtin dummy types -------------------------
+classinfo_t nullclass = {
+ INFOTYPE_CLASS,0,0,ACCESS_PACKAGE, "", "null", 0, 0, 0
+};
+classinfo_t* registry_getnullclass() {
+ return &nullclass;
+}
+classinfo_t voidclass = {
+ INFOTYPE_CLASS,0,0,ACCESS_PACKAGE, "", "void", 0, 0, 0
+};
+classinfo_t* registry_getvoidclass() {
+ return &voidclass;
+}
+
+namespace_t access2namespace(U8 access, char*package)
+{
+ namespace_t ns;
+ ns.access = access;
+ ns.name = package;
+ return ns;
+}
+
+char* infotypename(slotinfo_t*s)
+{
+ if(s->kind == INFOTYPE_CLASS) return "class";
+ else if(s->kind == INFOTYPE_VAR) return "var";
+ else if(s->kind == INFOTYPE_METHOD) return "function";
+ else return "object";
+}
+
+void slotinfo_dump(slotinfo_t*s)