less broken

This commit is contained in:
koniifer 2024-12-17 18:20:16 +00:00
parent b059faa7f8
commit a8572da351
3 changed files with 14 additions and 21 deletions

6
Cargo.lock generated
View file

@ -213,12 +213,12 @@ dependencies = [
[[package]]
name = "hbbytecode"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#95496116b05bf2ee2192a5acfe1bcedbdb23b28f"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#248bdf003aa991f4bad18ddcb084532d1bcb78d5"
[[package]]
name = "hblang"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#95496116b05bf2ee2192a5acfe1bcedbdb23b28f"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#248bdf003aa991f4bad18ddcb084532d1bcb78d5"
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#95496116b05bf2ee2192a5acfe1bcedbdb23b28f"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#248bdf003aa991f4bad18ddcb084532d1bcb78d5"
dependencies = [
"hbbytecode",
]

View file

@ -130,10 +130,7 @@ format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint {
.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 {
}
return @inline(format_int, T, v, str, @intcast(opts.radix))
} else if T == bool {
return @inline(format_bool, v, str)
} else if float(T) {
@ -141,10 +138,10 @@ format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint {
}
},
.Struct => {
i := 0
name := @nameof(T);
*@as(^[u8; @len(name)], @bitcast(str)) = *@bitcast(name)
len := @inline(string.length, name);
// name := ;
i := 0;
*@as(^[u8; @len(@nameof(T))], @bitcast(str)) = *@bitcast(@nameof(T))
len := @len(@nameof(T));
*@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".(\0")
len += 2
$loop {
@ -161,7 +158,7 @@ format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint {
len += 1
return len
},
_ => return 0,
_ => panic("unsupported format type\0"),
}
}
@ -178,16 +175,14 @@ format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint {
*/
FormatOptions := struct {
decimal_digits: uint,
radix: uint,
decimal_digits: uint = 1 << 32,
radix: uint = 10,
}
$DEFAULT_OPTS := FormatOptions.(2, 10)
/* SAFETY:
* Assumes the buffer is wide enough for the formatted text and a null char
*/
format := fn($T: type, v: T, str: ^u8): ^u8 return @inline(format_args, T, v, str, DEFAULT_OPTS)
format := fn($T: type, v: T, str: ^u8): ^u8 return @inline(format_args, T, v, str, .())
format_args := fn($T: type, v: T, str: ^u8, opts: FormatOptions): ^u8 {
@inline(string.clear, str)

View file

@ -17,12 +17,10 @@ test := fn(): uint {
log.info(format(Thingy, .(-100, -100, .(-math.PI, true)), buffer))
log.info(format(SubThingy, .(-math.E, false), buffer))
log.info(format_args(Color, .{r: 255, g: 254, b: 253, a: 252}, buffer, .{
decimal_digits: DEFAULT_OPTS.decimal_digits,
radix: 16,
}))
// default value: .{decimal_digits: 2}
log.info(format_args(f64, math.LN_2, buffer, .{decimal_digits: 1 << 32, radix: 16}))
log.info(format([u8; 3], .(1, 2, 3), buffer))
log.info(format_args(f64, math.LN_2, buffer, .{radix: 16}))
// log.info(format([u8; 3], .(1, 2, 3), buffer))
log.info(format(^SubThingy, &.(0.0, true), buffer))
return 0