abc_class_t* abc_class_new(abc_file_t*file, multiname_t*classname, multiname_t*superclass) {
NEW(abc_class_t,c);
- array_append(file->classes, NO_KEY, c);
+ if(file)
+ array_append(file->classes, NO_KEY, c);
c->file = file;
c->classname = multiname_clone(classname);
}
-trait_t* abc_class_find_slotid(abc_class_t*cls, int slotid)
+trait_t* traits_find_slotid(trait_list_t*traits, int slotid)
{
trait_list_t*l;
trait_t*t=0;
- for(l=cls->traits;l;l=l->next) {
+ for(l=traits;l;l=l->next) {
if(l->trait->slot_id==slotid) {
t=l->trait;
break;
/* notice: traits of a method (body) belonging to an init script
and traits of the init script are *not* the same thing */
-int abc_initscript_addClassTrait(abc_script_t*script, multiname_t*multiname, abc_class_t*cls)
+trait_t* abc_initscript_addClassTrait(abc_script_t*script, multiname_t*multiname, abc_class_t*cls)
{
abc_file_t*file = script->file;
multiname_t*m = multiname_clone(multiname);
trait_t*trait = trait_new(TRAIT_CLASS, m, slotid, 0, 0);
trait->cls = cls;
list_append(script->traits, trait);
- return slotid;
+ return trait;
}
abc_script_t* abc_initscript(abc_file_t*file)
if(m->return_type)
return_type = multiname_tostring(m->return_type);
else
- return_type = strdup("void");
+ return_type = strdup("*");
fprintf(fo, "%s", prefix);
fprintf(fo, "%s %s ", attr, type);
char*value = constant_tostring(trait->value);
fprintf(fo, "%sslot %d: %s %s:%s %s %s\n", prefix, trait->slot_id,
kind==TRAIT_CONST?"const":"var", name, type_name,
- value?"=":"", value?value:"");
+ trait->value?"=":"", trait->value?value:"");
if(value) free(value);
free(type_name);
} else {
char*supername = multiname_tostring(cls->superclass);
fprintf(fo, " extends %s", supername);
free(supername);
+ }
+ if(cls->interfaces) {
multiname_list_t*ilist = cls->interfaces;
if(ilist)
fprintf(fo, " implements");
NEW(abc_method_body_t,body);array_append(file->method_bodies, NO_KEY, body);
// don't bother to set m->index
body->method = m; m->body = body;
- __ returnvoid(body);
+ if(c->superclass && c->superclass->name && strcmp(c->superclass->name,"Object")) {
+ body->code = abc_getlocal_0(body->code);
+ body->code = abc_constructsuper(body->code, 0);
+ }
+ body->code = abc_returnvoid(body->code);
c->constructor = m;
} else {
NEW(abc_method_t,m);array_append(file->methods, NO_KEY, m);
NEW(abc_method_t,m);array_append(file->methods, NO_KEY, m);
NEW(abc_method_body_t,body);array_append(file->method_bodies, NO_KEY, body);
body->method = m; m->body = body;
- __ returnvoid(body);
+ body->code = abc_returnvoid(0);
c->static_constructor = m;
}
}
swf_SetU30(tag, file->scripts->num);
for(t=0;t<file->scripts->num;t++) {
abc_script_t*s = (abc_script_t*)array_getvalue(file->scripts, t);
+ if(!s->method->body || !s->method->body->code) {
+ fprintf(stderr, "Internal Error: initscript has no body\n");
+ }
swf_SetU30(tag, s->method->index); //!=t!
traits_write(pool, tag, s->traits);
}