+ if(as3_pass == 2) {
+ state->cls = dict_lookup(global->token2info, (void*)(ptroff_t)as3_tokencount);
+
+ state->method = state->cls->init;
+ parserassert(state->cls && state->cls->info);
+
+ function_initvars(state->cls->init, 0, 0, 1);
+ function_initvars(state->cls->static_init, 0, 0, 0);
+
+ if(extends && (extends->flags & FLAG_FINAL))
+ syntaxerror("Can't extend final class '%s'", extends->name);
+
+ int pos = 0;
+ while(state->cls->info->interfaces[pos]) {
+ if(!(state->cls->info->interfaces[pos]->flags & FLAG_INTERFACE))
+ syntaxerror("'%s' is not an interface",
+ state->cls->info->interfaces[pos]->name);
+ pos++;
+ }
+
+ /* fill out interfaces and extends (we couldn't resolve those during the first pass) */
+ state->cls->info->superclass = extends;
+
+ /* generate the abc code for this class */
+ MULTINAME(classname2,state->cls->info);
+ multiname_t*extends2 = sig2mname(extends);
+
+ state->cls->abc = abc_class_new(global->file, &classname2, extends2);
+ if(state->cls->info->flags&FLAG_FINAL) abc_class_final(state->cls->abc);
+ if(!(state->cls->info->flags&FLAG_DYNAMIC)) abc_class_sealed(state->cls->abc);
+ if(state->cls->info->flags&FLAG_INTERFACE) {
+ abc_class_interface(state->cls->abc);
+ }
+
+ abc_class_protectedNS(state->cls->abc, classname);
+
+ for(mlist=implements;mlist;mlist=mlist->next) {
+ MULTINAME(m, mlist->classinfo);
+ abc_class_add_interface(state->cls->abc, &m);
+ }
+
+ /* write the construction code for this class to the global init
+ function */
+ int slotindex = abc_initscript_addClassTrait(global->init, &classname2, state->cls->abc);
+
+ abc_method_body_t*m = global->init->method->body;
+ __ getglobalscope(m);
+ classinfo_t*s = extends;
+
+ int count=0;
+
+ while(s) {
+ //TODO: take a look at the current scope stack, maybe
+ // we can re-use something
+ s = s->superclass;
+ if(!s)
+ break;
+
+ multiname_t*s2 = sig2mname(s);
+ __ getlex2(m, s2);
+ multiname_destroy(s2);
+
+ __ pushscope(m); count++;
+ m->code = m->code->prev->prev; // invert
+ }
+ /* continue appending after last op end */
+ while(m->code && m->code->next) m->code = m->code->next;
+
+ /* TODO: if this is one of *our* classes, we can also
+ do a getglobalscope/getslot <nr> (which references
+ the init function's slots) */
+ if(extends2) {
+ __ getlex2(m, extends2);
+ __ dup(m);
+ /* notice: we get a Verify Error #1107 if the top elemnt on the scope
+ stack is not the superclass */
+ __ pushscope(m);count++;
+ } else {
+ __ pushnull(m);
+ /* notice: we get a verify error #1107 if the top element on the scope
+ stack is not the global object */
+ __ getlocal_0(m);
+ __ pushscope(m);count++;
+ }
+ __ newclass(m,state->cls->abc);
+ while(count--) {
+ __ popscope(m);
+ }
+ __ setslot(m, slotindex);
+ multiname_destroy(extends2);