diff options
Diffstat (limited to 'anim/src/objects.zig')
| -rw-r--r-- | anim/src/objects.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/anim/src/objects.zig b/anim/src/objects.zig index 57e2b11..0c4f48a 100644 --- a/anim/src/objects.zig +++ b/anim/src/objects.zig @@ -122,6 +122,20 @@ pub fn spell(scratch: std.mem.Allocator, t: types.Type) []const u8 { }; } +/// A number as its type says to read it (the `value` classes a type +/// gives): a boolean `true`, a character quoted, else its decimal. +pub fn reading(scratch: std.mem.Allocator, n: i64, t: types.Type) []const u8 { + if (t == .scalar) switch (t.scalar.kind) { + .bool => return if (n != 0) "true" else "false", + .char => { + const c: u8 = @truncate(@as(u64, @bitCast(n))); + return if (std.ascii.isPrint(c) and c != '\'' and c != '\\') std.fmt.allocPrint(scratch, "'{c}'", .{c}) catch "?" else std.fmt.allocPrint(scratch, "'\\x{x:0>2}'", .{c}) catch "?"; + }, + else => {}, + }; + return std.fmt.allocPrint(scratch, "{d}", .{n}) catch "?"; +} + /// A variable as C declares it: `int a[8]`, `node *prev`, `long n`. pub fn declare(scratch: std.mem.Allocator, rec: *const Recording, v: Recording.Variable) []const u8 { const name = rec.name(v.name); |
