From 23ac1f4f98accc3bb84e81be264d8408be372028 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 17 May 2020 18:28:05 -0700 Subject: fix: bugs associated to map reallocating --- sys/cmd/cc/lex.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'sys/cmd/cc/lex.c') 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,7 +1,27 @@ #include "cc.h" - #include +// ----------------------------------------------------------------------- +// 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 @@ -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); } -- cgit v1.2.1