diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/main.c | 14 | ||||
-rw-r--r-- | compiler/parser/parser.c | 6 | ||||
-rw-r--r-- | compiler/parser/type.c | 1 |
3 files changed, 18 insertions, 3 deletions
diff --git a/compiler/main.c b/compiler/main.c index da261bc..ada6243 100644 --- a/compiler/main.c +++ b/compiler/main.c @@ -174,6 +174,14 @@ parse_args(int argc, char **argv) } static void +print_ptrs(int n_ptrs) +{ + for (int n = 0; n < n_ptrs; n++) { + putchar('*'); + } +} + +static void print_alias(struct type *typ) { printf("alias (%lu bytes, %d pointer(s))", typ->size, typ->n_ptrs); @@ -207,7 +215,7 @@ print_struct(struct type *typ) { struct struct_member *mem; - printf("struct {\n"); + printf("struct (%lu bytes) {\n", typ->size); for (size_t r = 0; r < typ->members.n_rows; r++) { mem = (struct struct_member*)typ->members.rows[r].head; @@ -216,7 +224,9 @@ print_struct(struct type *typ) } do { - printf(" %.*s %.*s; (%d pointer(s))\n", (int)mem->typ->name_len, mem->typ->name, (int)mem->name_len, mem->name, mem->n_ptrs); + printf(" %.*s", (int)mem->typ->name_len, mem->typ->name); + print_ptrs(mem->n_ptrs); + printf(" %.*s;\n", (int)mem->name_len, mem->name); mem = (struct struct_member*)mem->hashmap_entry.list_entry.next; } while (mem != (struct struct_member*)&typ->members.rows[r]); diff --git a/compiler/parser/parser.c b/compiler/parser/parser.c index aeec48b..261385b 100644 --- a/compiler/parser/parser.c +++ b/compiler/parser/parser.c @@ -79,6 +79,10 @@ parser_init(struct parser *ctx, char *source) debug("Initializing parser...\n"); lexer_init(&ctx->lexer, source); - add_builtin(ctx->types, "uint32", 4, 0); add_builtin(ctx->types, "any", 0, 0); + add_builtin(ctx->types, "uint", sizeof(void*), 0); + add_builtin(ctx->types, "uint64", 8, 0); + add_builtin(ctx->types, "uint32", 4, 0); + add_builtin(ctx->types, "uint16", 2, 0); + add_builtin(ctx->types, "uint8", 1, 0); } diff --git a/compiler/parser/type.c b/compiler/parser/type.c index 4ac9327..e0990c3 100644 --- a/compiler/parser/type.c +++ b/compiler/parser/type.c @@ -189,6 +189,7 @@ parse_struct(struct parser *ctx, struct type *typ) } next_token(ctx); } + typ->size = off; next_token(ctx); return true; |