From 58af6dcf569c7f83b317d30f8dd85d96d314d785 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 13 Aug 2022 07:11:23 +0200 Subject: cond switch --- src/fmt.cff | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/fmt.cff') diff --git a/src/fmt.cff b/src/fmt.cff index ecf7d74..ad28bbd 100644 --- a/src/fmt.cff +++ b/src/fmt.cff @@ -10,13 +10,14 @@ extern fn vpfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, ap va_list) defmacro pch(ch) [ { extern fn isprint(int) int; - if isprint(ch) != 0 { - p(ch); + let $ch = ch; + if isprint($ch) != 0 { + p($ch); } else { p('\\'); - p('0' + (ch % 8)); - p('0' + ((ch / 8) % 8)); - p('0' + ((ch / 8 / 8) % 8)); + p('0' + ($ch % 8)); + p('0' + (($ch / 8) % 8)); + p('0' + (($ch / 8 / 8) % 8)); } } ] @@ -27,12 +28,31 @@ extern fn vpfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, ap va_list) case :int; sprintf(buf, "%lld", tok.u.int); ps(buf); + case :flo; + sprintf(buf, "%.14f", tok.u.flo); + ps(buf); + case :bool; + ps(tok.u.bool ? "#t" : "#f"); case :str; pfmt(proc, parg, "%S", tok.u.str); - case :ident; + case :chr; + let t = bswap64(tok.u.uint); + p('\''); + while t != 0 { + if t & 0xFF != 0 { + pch(t & 0xFF); + } + t >>= 8; + } + p('\''); + case :null; + ps("#null"); + case :ident, :macident, :gensym, :label; if quote { p('`'); } ps(tok.u.ident); if quote { p('\''); } + case :type; + pfmt(proc, parg, "%t", tok.ty); case else if tok.t >= 0 and tok.t < NUM_KEYWORDS { if quote { p('`'); } @@ -41,14 +61,12 @@ extern fn vpfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, ap va_list) } else if tok.t > 0 { if quote { p('`'); } let t = bswap32(tok.t); - let i = 0; while t != 0 { if t & 0xFF != 0 { p(t); } t >>= 8; } - buf[i] = '\0'; if quote { p('\''); } } } -- cgit v1.2.3