forked from AbleOS/ableos
less broken
This commit is contained in:
parent
b059faa7f8
commit
a8572da351
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -213,12 +213,12 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbbytecode"
|
name = "hbbytecode"
|
||||||
version = "0.1.0"
|
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]]
|
[[package]]
|
||||||
name = "hblang"
|
name = "hblang"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
"hbbytecode",
|
"hbbytecode",
|
||||||
|
@ -229,7 +229,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbvm"
|
name = "hbvm"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"hbbytecode",
|
"hbbytecode",
|
||||||
]
|
]
|
||||||
|
|
|
@ -129,11 +129,8 @@ format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint {
|
||||||
match @as(Kind, @bitcast(@kindof(T))) {
|
match @as(Kind, @bitcast(@kindof(T))) {
|
||||||
.Pointer => return @inline(format_int, uint, @bitcast(v), str, 16),
|
.Pointer => return @inline(format_int, uint, @bitcast(v), str, 16),
|
||||||
.Builtin => {
|
.Builtin => {
|
||||||
if integer(T) {
|
|
||||||
if integer(T) {
|
if integer(T) {
|
||||||
return @inline(format_int, T, v, str, @intcast(opts.radix))
|
return @inline(format_int, T, v, str, @intcast(opts.radix))
|
||||||
} else {
|
|
||||||
}
|
|
||||||
} else if T == bool {
|
} else if T == bool {
|
||||||
return @inline(format_bool, v, str)
|
return @inline(format_bool, v, str)
|
||||||
} else if float(T) {
|
} else if float(T) {
|
||||||
|
@ -141,10 +138,10 @@ format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.Struct => {
|
.Struct => {
|
||||||
i := 0
|
// name := ;
|
||||||
name := @nameof(T);
|
i := 0;
|
||||||
*@as(^[u8; @len(name)], @bitcast(str)) = *@bitcast(name)
|
*@as(^[u8; @len(@nameof(T))], @bitcast(str)) = *@bitcast(@nameof(T))
|
||||||
len := @inline(string.length, name);
|
len := @len(@nameof(T));
|
||||||
*@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".(\0")
|
*@as(^[u8; 2], @bitcast(str + len)) = *@bitcast(".(\0")
|
||||||
len += 2
|
len += 2
|
||||||
$loop {
|
$loop {
|
||||||
|
@ -161,7 +158,7 @@ format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint {
|
||||||
len += 1
|
len += 1
|
||||||
return len
|
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 {
|
FormatOptions := struct {
|
||||||
decimal_digits: uint,
|
decimal_digits: uint = 1 << 32,
|
||||||
radix: uint,
|
radix: uint = 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
$DEFAULT_OPTS := FormatOptions.(2, 10)
|
|
||||||
|
|
||||||
/* SAFETY:
|
/* SAFETY:
|
||||||
* Assumes the buffer is wide enough for the formatted text and a null char
|
* 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 {
|
format_args := fn($T: type, v: T, str: ^u8, opts: FormatOptions): ^u8 {
|
||||||
@inline(string.clear, str)
|
@inline(string.clear, str)
|
||||||
|
|
|
@ -17,12 +17,10 @@ test := fn(): uint {
|
||||||
log.info(format(Thingy, .(-100, -100, .(-math.PI, true)), buffer))
|
log.info(format(Thingy, .(-100, -100, .(-math.PI, true)), buffer))
|
||||||
log.info(format(SubThingy, .(-math.E, false), buffer))
|
log.info(format(SubThingy, .(-math.E, false), buffer))
|
||||||
log.info(format_args(Color, .{r: 255, g: 254, b: 253, a: 252}, buffer, .{
|
log.info(format_args(Color, .{r: 255, g: 254, b: 253, a: 252}, buffer, .{
|
||||||
decimal_digits: DEFAULT_OPTS.decimal_digits,
|
|
||||||
radix: 16,
|
radix: 16,
|
||||||
}))
|
}))
|
||||||
// default value: .{decimal_digits: 2}
|
log.info(format_args(f64, math.LN_2, buffer, .{radix: 16}))
|
||||||
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([u8; 3], .(1, 2, 3), buffer))
|
|
||||||
log.info(format(^SubThingy, &.(0.0, true), buffer))
|
log.info(format(^SubThingy, &.(0.0, true), buffer))
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue