commit c0a461ef05775c225c41652d613f7546aaa7b921
parent eeedd1c31c817481a1a097cbe1840a940ee172fe
Author: Brian Swetland <swetland@frotz.net>
Date: Tue, 30 Nov 2021 14:46:48 -0800
compiler2: ponder necessity of 'Type' distinct from 'Symbol'
Diffstat:
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/docs/todo.md b/docs/todo.md
@@ -7,6 +7,7 @@
- [ ] const / readonly
- [ ] type inference for var definitions
- [ ] support for named enums
+- [ ] simplify use of Type/Symbol for type system
- [x] support for global anonymous enums
- [x] continue
- [x] support for arrays
diff --git a/src/compiler2.c b/src/compiler2.c
@@ -345,6 +345,7 @@ Type type_make(type_t kind, Type base, u32 len, u32 size) {
}
void type_add(Type type, String name) {
+ //fprintf(stderr,"type_add(%s, %s)\n",type_id_tab[type->kind],name->text);
Symbol sym = symbol_make(SYM_TYPE, 0, name, type, 0);
if (type->sym == nil) {
// only set the the type's object if it is
@@ -1216,7 +1217,6 @@ Type parse_array_type() {
return type_make(TYPE_SLICE, parse_type(false), 0, 8);
} else {
Ast expr = parse_expr();
- // XXX get const to nelem
require(tCBRACK);
i32 nelem = ast_get_const_i32(expr);
if (nelem <= 0) {
@@ -1843,6 +1843,22 @@ void ast_dump(Ast node, u32 indent) {
}
}
+#if 0
+void type_dump_all() {
+ Symbol sym = ctx.typetab;
+
+ while (sym != nil) {
+ fprintf(stderr, "Symbol %p '%s'\n", sym, sym->name->text);
+ fprintf(stderr, " Type %p %s len=%u sz=%u\n",
+ sym->type, type_id_tab[sym->type->kind],
+ sym->type->len, sym->type->size);
+ fprintf(stderr, " sym=%p first=%p\n",
+ sym->type->sym, sym->type->first);
+ sym = sym->next;
+ }
+}
+#endif
+
// ================================================================
i32 main(int argc, args argv) {
@@ -1918,5 +1934,7 @@ i32 main(int argc, args argv) {
ast_dump(a, 0);
+ //type_dump_all();
+
return 0;
}