diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-05-17 18:28:05 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-05-17 18:28:05 -0700 |
commit | 23ac1f4f98accc3bb84e81be264d8408be372028 (patch) | |
tree | d3876d6d5ce73c9f0669ec3f0c04c3a7524ec91e /sys/cmd/cc/lex.c | |
parent | 9ec5bed6a7d715ffa69851569485a685dd69db2e (diff) |
fix: bugs associated to map reallocating
Diffstat (limited to 'sys/cmd/cc/lex.c')
-rw-r--r-- | sys/cmd/cc/lex.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/sys/cmd/cc/lex.c b/sys/cmd/cc/lex.c index 6b85d8c..6d3da59 100644 --- a/sys/cmd/cc/lex.c +++ b/sys/cmd/cc/lex.c @@ -1,8 +1,28 @@ #include "cc.h" - #include <libn/macro/map.h> // ----------------------------------------------------------------------- +// printing functions + +void +puttok(Token tok) +{ + if (tok.kind < Alit) + printf("%s", tokens[tok.kind]); + else if (tok.kind & Alit) { + if (tok.kind & Vchar) + if (tok.kind & Vint) + if (tok.kind & Vlong) + if (tok.kind & Vvlong) + printf("literal <%lld>", tok.val.i); + if (tok.kind & Vfloat) + printf("literal <%f>", tok.val.f); + printf("literal <%s>", tok.val.s); + } else + printf("ident <%s>", tok.val.s); +} + +// ----------------------------------------------------------------------- // simple wrappers byte @@ -607,7 +627,7 @@ static int moresymtab(SymTab *tab, int n) { - MAP_GROW(tab, string, Sym*, n, PTR_HASH, mem·sys.alloc, mem·sys.free, nil); + MAP_GROW(tab, string, Sym*, n, PTR_HASH, ·calloc, ·free, nil); } static @@ -642,8 +662,9 @@ errorat(Pos x, byte *fmt, ...) va_start(args, fmt); printf("error %d: ", x.line); - vprintf(fmt, args); + printf("\n"); + va_end(args); } |