diff --git a/Cargo.lock b/Cargo.lock index dfd1f73..9abbe33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#945e5c70f6cb20a77fbb654a0ab6bef7d2b25aac" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#95496116b05bf2ee2192a5acfe1bcedbdb23b28f" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#945e5c70f6cb20a77fbb654a0ab6bef7d2b25aac" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#95496116b05bf2ee2192a5acfe1bcedbdb23b28f" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#945e5c70f6cb20a77fbb654a0ab6bef7d2b25aac" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#95496116b05bf2ee2192a5acfe1bcedbdb23b28f" dependencies = [ "hbbytecode", ] diff --git a/sysdata/libraries/stn/src/formatters.hb b/sysdata/libraries/stn/src/formatters.hb index 8c90fa1..32c645f 100644 --- a/sysdata/libraries/stn/src/formatters.hb +++ b/sysdata/libraries/stn/src/formatters.hb @@ -1,4 +1,4 @@ -.{string, pointer, primitive, unsigned_int, signed_int, float, integer, memory, panic} := @use("stn") +.{Kind, string, unsigned_int, signed_int, float, integer, memory, panic} := @use("stn") format_int := fn($T: type, v: T, str: ^u8, radix: T): uint { if integer(T) { @@ -126,38 +126,42 @@ format_float := fn($T: type, v: T, str: ^u8, precision: uint, radix: int): uint } format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint { - if integer(T) | pointer(T) { - if integer(T) { - return @inline(format_int, T, v, str, @intcast(opts.radix)) - } else { - return @inline(format_int, uint, @bitcast(v), str, 16) - } - } else if T == bool { - return @inline(format_bool, v, str) - } else if float(T) { - return @inline(format_float, T, v, str, opts.decimal_digits, @intcast(opts.radix)) - } else if !primitive(T) { - i := 0 - // name := @nameof(T) - // len := @inline(string.length, name) - len := 0; - *@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".(\0") - len += 2 - $loop { - v_sub := v[i] - TSub := @TypeOf(v_sub) - len += @inline(format_inner, TSub, v_sub, str + len, opts) - i += 1 - if i == @len(T) break else { - *@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(", \0") - len += 2 + match @as(Kind, @bitcast(@kindof(T))) { + .Pointer => return @inline(format_int, uint, @bitcast(v), str, 16), + .Builtin => { + if integer(T) { + if integer(T) { + return @inline(format_int, T, v, str, @intcast(opts.radix)) + } else { + } + } else if T == bool { + return @inline(format_bool, v, str) + } else if float(T) { + return @inline(format_float, T, v, str, opts.decimal_digits, @intcast(opts.radix)) } - }; - *@as(^[u8; 1], @bitcast(str + len)) = *@bitcast(")\0") - len += 1 - return len - } else { - panic("Unsupported formatter type\0") + }, + .Struct => { + i := 0 + name := @nameof(T); + *@as(^[u8; @len(name)], @bitcast(str)) = *@bitcast(name) + len := @inline(string.length, name); + *@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".(\0") + len += 2 + $loop { + v_sub := v[i] + TSub := @TypeOf(v_sub) + len += @inline(format_inner, TSub, v_sub, str + len, opts) + i += 1 + if i == @len(T) break else { + *@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(", \0") + len += 2 + } + }; + *@as(^[u8; 1], @bitcast(str + len)) = *@bitcast(")\0") + len += 1 + return len + }, + _ => return 0, } } diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index a99515d..14aa9f5 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -24,9 +24,7 @@ panic := fn(message: ?^u8): never { die } -$pointer := fn($T: type): bool { - return T != f64 & T != uint & T != int & @sizeof(T) == @sizeof(uint) & @alignof(T) == @alignof(uint) -} +Kind := enum {Builtin, Struct, Enum, Union, Pointer, Slice, Opt, Function, Template, Global, Const, Module} $unsigned_int := fn($T: type): bool { return T == uint | T == u8 | T == u16 | T == u32 @@ -44,10 +42,6 @@ $float := fn($T: type): bool { return T == f32 | T == f64 } -$primitive := fn($T: type): bool { - return integer(T) | float(T) | pointer(T) | T == bool -} - $float_bytes := fn($T: type): type { if T == f64 return uint else if T == f32 return u32 } \ No newline at end of file