almost enums

This commit is contained in:
koniifer 2024-12-19 17:29:39 +00:00
parent d0bd3714ee
commit d2cb73c2ce
3 changed files with 15 additions and 10 deletions

View file

@ -149,14 +149,13 @@ fmt_nullable := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint {
fmt_enum := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint {
T := @TypeOf(v)
// len := @len(@nameof(T));
// *@as(^[u8; @len(@nameof(T))], @bitcast(str)) = *@bitcast(@nameof(T));
// *@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".(\0")
// len += 2
// len += @inline(fmt_int, @as(usize(T), @bitcast(v)), str + len, 10);
// *@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".)\0")
// return len + 2
return fmt_int(@as(usize(T), @bitcast(v)), str, 10)
len := @len(@nameof(T));
*@as(^[u8; @len(@nameof(T))], @bitcast(str)) = *@bitcast(@nameof(T));
*@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".(\0")
len += 2
len += @inline(fmt_int, @as(usize(T), @bitcast(v)), str + len, 10);
*@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".)\0")
return len + 2
}
/* SAFETY:

View file

@ -24,7 +24,7 @@ print_buffer := memory.dangling(u8)
print := fn(v: @Any(), opts: fmt.FormatOptions): void {
if @TypeOf(v) == ^u8 {
info(v)
@inline(log, opts.log, v)
return
}
if print_buffer == memory.dangling(u8) {

View file

@ -12,9 +12,15 @@ SubThingy := struct {
b: bool,
}
OtherThingy := enum {
TheOther,
TheOtherer,
}
test := fn(): uint {
log.print("Hello, World!\0", .{log: .Error})
log.print(Thingy.(-100, -100, .(-math.PI, true)), .{})
log.print(OtherThingy.TheOther, .{})
log.print(Thingy.(-100, -100, .(-math.PI, true)), .{log: .Warn})
log.print(SubThingy.(-math.E, false), .{})
log.print(Color.{r: 255, g: 254, b: 253, a: 252}, .{radix: 2})
log.print(@as(f64, math.LN_2), .{radix: 16, decimal_digits: 1 << 32})