-/* code.c
+/* mklib.c
File to generate builtin.c
- Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
+ Copyright (c) 2008,2009 Matthias Kramm <kramm@quiss.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
}
static char* mkptr2(const char*package, const char*name)
{
+ if(!package[0] && !strcmp(name, "void")) {
+ return "&voidclass";
+ }
char*id = malloc(strlen(package)+strlen(name)+10);
strcpy(id, "&");
strcat(id, package);
return "classinfo_t";
} else if(s->kind == INFOTYPE_METHOD) {
return "methodinfo_t";
- } else if(s->kind == INFOTYPE_SLOT) {
+ } else if(s->kind == INFOTYPE_VAR) {
return "varinfo_t";
}
+ return "**ERROR**";
}
void write_slotinfo(FILE*fi, slotinfo_t*s, char*id, char*prefix);
if(s->kind == INFOTYPE_CLASS) {
classinfo_t*c = (classinfo_t*)s;
dict_t*d = &c->members;
- int t;
- for(t=0;t<d->hashsize;t++) {
- dictentry_t*l = d->slots[t];
- while(l) {
- slotinfo_t*s2 = (slotinfo_t*)l->data;
- fprintf(fi, "static %s %s;\n", mktype(s2), mkid2(id, s2->name));
- l = l->next;
- }
- }
+ DICT_ITERATE_DATA(d, slotinfo_t*, s1) {
+ fprintf(fi, "static %s %s;\n", mktype(s1), mkid2(id, s1->name));
+ }
+ DICT_ITERATE_DATA(d, slotinfo_t*, s2) {
+ fprintf(fi, "static %s %s;\n", mktype(s2), mkid2(id, s2->name));
+ }
}
}
void write_initinfo(FILE*fi, slotinfo_t*s, char*prefix)
{
if(s->kind == INFOTYPE_CLASS) {
classinfo_t*c = (classinfo_t*)s;
- fprintf(fi, "%s", prefix);
char*id = mkid(c);
- dict_t*d = &c->members;
- fprintf(fi, "dict_init(&%s.members, %d);\n", id, d->hashsize);
+ dict_t*d1 = &c->members;
+ dict_t*d2 = &c->static_members;
+ fprintf(fi, "%s", prefix);
+ fprintf(fi, "dict_init2(&%s.members, &memberinfo_type, %d);\n", id, d1->hashsize);
+ fprintf(fi, "%s", prefix);
+ fprintf(fi, "dict_init2(&%s.static_members, &memberinfo_type, %d);\n", id, d2->hashsize);
int t;
- for(t=0;t<d->hashsize;t++) {
- dictentry_t*l = d->slots[t];
- while(l) {
- slotinfo_t*s2 = (slotinfo_t*)l->data;
- fprintf(fi, "%s", prefix);
- fprintf(fi, "dict_put(&%s.members, \"%s\", &%s);\n", id, s2->name, mkid2(id, s2->name));
- l = l->next;
- }
- }
+ DICT_ITERATE_DATA(d1,slotinfo_t*,s1) {
+ fprintf(fi, "%s", prefix);
+ char*id2 = mkid2(id, s1->name);
+ fprintf(fi, "dict_put(&%s.members, &%s, &%s);\n", id, id2, id2);
+ }
+ DICT_ITERATE_DATA(d2,slotinfo_t*,s2) {
+ fprintf(fi, "%s", prefix);
+ char*id2 = mkid2(id, s2->name);
+ fprintf(fi, "dict_put(&%s.static_members, &%s, &%s);\n", id, id2, id2);
+ }
+ }
+}
+
+void write_constant(FILE*fi, constant_t*value, char*id, char*prefix)
+{
+ if(NS_TYPE(value->type)) {
+ fprintf(fi, "%s", prefix);
+ fprintf(fi, "static namespace_t %s_constant_ns = {0x%02x, \"%s\"};\n", id, value->ns->access, value->ns->name);
+ } else if(value->type == CONSTANT_STRING) {
+ fprintf(fi, "%s", prefix);
+ fprintf(fi, "static string_t %s_constant_s = {\"%s\", %d};\n", id, value->s->str, value->s->len);
}
+ fprintf(fi, "%s", prefix);
+ fprintf(fi, "static constant_t %s_constant = ", id);
+ fprintf(fi, "{type: %d", value->type);
+ if(NS_TYPE(value->type)) {
+ fprintf(fi, ", &%s_constant_ns", id);
+ } else if(value->type == CONSTANT_INT) {
+ fprintf(fi, ",i: %d,", value->type);
+ } else if(value->type == CONSTANT_UINT) {
+ fprintf(fi, ",u: %u", value->u);
+ } else if(value->type == CONSTANT_FLOAT) {
+ if(!isnan(value->f) && !isinf(value->f))
+ fprintf(fi, ", %f", value->f);
+ } else if(value->type == CONSTANT_STRING) {
+ fprintf(fi, ", &%s_constant_s", id);
+ }
+ fprintf(fi, "};\n");
}
+
void write_slotinfo(FILE*fi, slotinfo_t*s, char*id, char*prefix)
{
+ if(s->kind == INFOTYPE_VAR) {
+ varinfo_t*v = (varinfo_t*)s;
+ if(v->value) {
+ write_constant(fi, v->value, id, prefix);
+ }
+ }
fprintf(fi, "%s", prefix);
fprintf(fi, "static %s %s = {", mktype(s), id);
fprintf(fi, "0x%02x, 0x%02x, 0x%02x, 0x%02x, ", s->kind, s->subtype, s->flags, s->access);
fprintf(fi, "interfaces: {");
int t;
for(t=0;c->interfaces[t];t++) {
- fprintf(fi, "%c", mkptr(c->interfaces[t]));
- if(c->interfaces[t+1])
- fprintf(fi, ", ");
+ fprintf(fi, "%s", mkptr(c->interfaces[t]));
+ fprintf(fi, ", ");
}
fprintf(fi, "0}};\n");
}
fprintf(fi, "0"); // params TODO
fprintf(fi, "};\n");
}
- if(s->kind == INFOTYPE_SLOT) {
+ if(s->kind == INFOTYPE_VAR) {
varinfo_t*m = (varinfo_t*)s;
fprintf(fi, "%s, ", mkptr(m->type));
fprintf(fi, "%s, ", mkptr(m->parent));
- fprintf(fi, "0"); // value TODO
+ if(!m->value) fprintf(fi, "0");
+ else fprintf(fi, "&%s_constant", id);
fprintf(fi, "};\n");
}
if(s->kind == INFOTYPE_CLASS) {
classinfo_t*c = (classinfo_t*)s;
dict_t*d = &c->members;
- int t;
- for(t=0;t<d->hashsize;t++) {
- dictentry_t*l = d->slots[t];
- while(l) {
- slotinfo_t*s2 = (slotinfo_t*)l->data;
- write_slotinfo(fi, s2, mkid2(id,s2->name), prefix);
- l = l->next;
- }
+ DICT_ITERATE_DATA(d, slotinfo_t*, s1) {
+ write_slotinfo(fi, s1, mkid2(id,s1->name), prefix);
+ }
+ d = &c->static_members;
+ DICT_ITERATE_DATA(d, slotinfo_t*, s2) {
+ write_slotinfo(fi, s2, mkid2(id,s2->name), prefix);
}
}
}
{
registry_classes = builtin_getclasses();
- as3_import_abc("/home/kramm/c/swftools/lib/as3/builtin.abc");
- as3_import_abc("/home/kramm/c/swftools/lib/as3/playerglobal.abc");
+ as3_import_abc("builtin.abc");
+ as3_import_abc("playerglobal.abc");
FILE*fi = fopen("builtin.c", "wb");
}
}
}
+ fprintf(fi, " _NaN_constant.f = __builtin_nan(\"\");\n");
+ fprintf(fi, " _Infinity_constant.f = __builtin_inf();\n");
fprintf(fi, " return d;\n");
fprintf(fi, "}\n");
-
+ return 0;
}