-/* 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
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);
fprintf(fi, "%s", prefix);
char*id = mkid(c);
dict_t*d = &c->members;
- fprintf(fi, "dict_init(&%s.members, %d);\n", id, d->hashsize);
+ fprintf(fi, "dict_init2(&%s.members, &memberinfo_type, %d);\n", id, d->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));
+ char*id2 = mkid2(id, s2->name);
+ fprintf(fi, "dict_put(&%s.members, &%s, &%s);\n", id, id2,id2);
l = l->next;
}
}
}
}
+
+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");
}
}
}
}
+ 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;
}