diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-18 04:26:26 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-18 04:26:26 -0500 |
| commit | 5ce55a6a29b240e7f0818fff0475f924188c74c8 (patch) | |
| tree | 6bcf53929257a8cd1f071ddba54c539c775b66a9 /types.c | |
| parent | 30c34a7243db7357733bd11c9ee3a093c35891cc (diff) | |
Better table literals
Diffstat (limited to 'types.c')
| -rw-r--r-- | types.c | 53 |
1 files changed, 3 insertions, 50 deletions
@@ -1,6 +1,7 @@ // Logic for handling type_t types #include <gc/cord.h> #include <stdint.h> +#include <signal.h> #include <limits.h> #include <math.h> @@ -15,6 +16,7 @@ CORD type_to_cord(type_t *t) { case VoidType: return "Void"; case MemoryType: return "Memory"; case BoolType: return "Bool"; + case StringType: return "Str"; case IntType: return CORD_asprintf("Int%ld", Match(t, IntType)->bits); case NumType: return CORD_asprintf("Num%ld", Match(t, NumType)->bits); case ArrayType: { @@ -39,22 +41,6 @@ CORD type_to_cord(type_t *t) { case StructType: { auto struct_ = Match(t, StructType); return struct_->name; - // CORD c = CORD_asprintf("%s(", struct_->name); - // int64_t i = 1; - // for (arg_t *field = struct_->fields; field; field = field->next) { - // const char *fname = field->name ? field->name : heap_strf("_%lu", i); - // ++i; - // if (fname && !streq(fname, heap_strf("_%lu", i+1))) - // c = CORD_cat(CORD_cat(c, fname), ":"); - // else - // c = CORD_cat(c, ":"); - - // c = CORD_cat(c, type_to_cord(field->type)); - - // if (field->next) c = CORD_cat(c, ", "); - // } - // c = CORD_cat(c, ")"); - // return c; } case PointerType: { auto ptr = Match(t, PointerType); @@ -65,45 +51,12 @@ CORD type_to_cord(type_t *t) { case EnumType: { auto tagged = Match(t, EnumType); return tagged->name; - -// CORD c = CORD_asprintf("%s(", tagged->name); -// int64_t next_tag = 0; -// for (tag_t *tag = tagged->tags; tag; tag = tag->next) { -// // name, tag_value, type -// c = CORD_cat(c, tag->name); -// if (tag->type) { -// c = CORD_cat(c, "("); -// auto struct_ = Match(tag->type, StructType); -// int64_t i = 1; -// for (arg_t *field = struct_->fields; field; field = field->next) { -// if (field->name && !streq(field->name, heap_strf("_%lu", i))) -// c = CORD_cat(CORD_cat(c, field->name), ":"); - -// CORD fstr = type_to_cord(field->type); -// c = CORD_cat(c, fstr); -// if (field->next) c = CORD_cat(c, ","); -// ++i; -// } -// c = CORD_cat(c, ")"); -// } - -// if (tag->tag_value != next_tag) { -// CORD_sprintf(&c, "%r=%ld", c, tag->tag_value); -// next_tag = tag->tag_value + 1; -// } else { -// ++next_tag; -// } - -// if (tag->next) -// c = CORD_cat(c, ", "); -// } -// c = CORD_cat(c, ")"); -// return c; } case TypeInfoType: { return "TypeInfo"; } default: { + raise(SIGABRT); return CORD_asprintf("Unknown type: %d", t->tag); } } |
