aboutsummaryrefslogtreecommitdiff
path: root/src/fmt.cff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-13 07:11:23 +0200
committerlemon <lsof@mailbox.org>2022-08-13 07:11:23 +0200
commit58af6dcf569c7f83b317d30f8dd85d96d314d785 (patch)
tree76d53089d8510ab9cade4e21200b36d648c4ecb6 /src/fmt.cff
parentd98b1ecb7a23b369e533f20386cb7aa83156d25d (diff)
cond switch
Diffstat (limited to 'src/fmt.cff')
-rw-r--r--src/fmt.cff34
1 files changed, 26 insertions, 8 deletions
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('\''); }
}
}