+void write_slotinfo_decl(FILE*fi, slotinfo_t*s, char*prefix)
+{
+ fprintf(fi, "%s", prefix);
+ char*id = mkid(s);
+ fprintf(fi, "static %s %s;\n", mktype(s), id);
+
+ if(s->kind == INFOTYPE_CLASS) {
+ classinfo_t*c = (classinfo_t*)s;
+ dict_t*d = &c->members;
+ 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;
+ char*id = mkid(c);
+ 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;
+ 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);
+ if(s->package)
+ fprintf(fi, "\"%s\", ", s->package);
+ else
+ fprintf(fi, "0, ");
+
+ if(s->name)
+ fprintf(fi, "\"%s\", ", s->name);
+ else
+ fprintf(fi, "0, ");
+
+ fprintf(fi, "%d, ", s->slot);
+
+ if(s->kind == INFOTYPE_CLASS) {
+ classinfo_t*c = (classinfo_t*)s;
+ fprintf(fi, "%s, ", mkptr(c->superclass));
+ fprintf(fi, "interfaces: {");
+ int t;
+ for(t=0;c->interfaces[t];t++) {
+ fprintf(fi, "%s", mkptr(c->interfaces[t]));
+ fprintf(fi, ", ");
+ }
+ fprintf(fi, "0}};\n");
+ }
+ if(s->kind == INFOTYPE_METHOD) {
+ methodinfo_t*m = (methodinfo_t*)s;
+ fprintf(fi, "%s, ", mkptr(m->return_type));
+ fprintf(fi, "%s, ", mkptr(m->parent));
+ fprintf(fi, "0"); // params TODO
+ fprintf(fi, "};\n");
+ }
+ if(s->kind == INFOTYPE_VAR) {
+ varinfo_t*m = (varinfo_t*)s;
+ fprintf(fi, "%s, ", mkptr(m->type));
+ fprintf(fi, "%s, ", mkptr(m->parent));
+ 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;
+ 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);
+ }
+ }