1
0
Fork 0
forked from AbleOS/ableos

tuple and array syntax

This commit is contained in:
koniifer 2024-12-20 11:21:03 +00:00
parent 25fecab5b3
commit 0fc95160cc
2 changed files with 28 additions and 11 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#f59c0c10922fb330d43b944a5bfcaa1021ecffe3"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4b3b6af70eb84d513b9fa926dd8c36e1dba88713"
[[package]]
name = "hblang"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#f59c0c10922fb330d43b944a5bfcaa1021ecffe3"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4b3b6af70eb84d513b9fa926dd8c36e1dba88713"
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#f59c0c10922fb330d43b944a5bfcaa1021ecffe3"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4b3b6af70eb84d513b9fa926dd8c36e1dba88713"
dependencies = [
"hbbytecode",
]

View file

@ -119,11 +119,23 @@ fmt_float := fn(v: @Any(), str: ^u8, precision: uint, radix: int): uint {
fmt_container := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint {
T2 := @TypeOf(v)
i := 0;
*@as(^[@lenof(@nameof(T2))]u8, @bitcast(str)) = *@bitcast(@nameof(T2))
len := @lenof(@nameof(T2));
kind := Kind.of(T2)
i := 0
len := 0
if kind == .Struct {
*@as(^[@lenof(@nameof(T2))]u8, @bitcast(str + len)) = *@bitcast(@nameof(T2))
len += @lenof(@nameof(T2));
*@as(^[2]u8, @bitcast(str + len)) = *@bitcast(".(\0")
len += 2
} else if kind == .Slice {
*@as(^[@lenof(@nameof(@ChildOf(T2)))]u8, @bitcast(str + len)) = *@bitcast(@nameof(@ChildOf(T2)))
len += @lenof(@nameof(@ChildOf(T2)));
*@as(^[2]u8, @bitcast(str + len)) = *@bitcast(".[\0")
len += 2
} else if kind == .Tuple {
*@as(^[2]u8, @bitcast(str + len)) = *@bitcast(".(\0")
len += 2
}
$loop {
v_sub := v[i]
len += @inline(format, v_sub, str + len, opts)
@ -132,9 +144,14 @@ fmt_container := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint {
*@as(^[2]u8, @bitcast(str + len)) = *@bitcast(", \0")
len += 2
}
};
}
if kind == .Struct | kind == .Tuple {
*@as(^[1]u8, @bitcast(str + len)) = *@bitcast(")\0")
len += 1
} else if kind == .Slice {
*@as(^[1]u8, @bitcast(str + len)) = *@bitcast("]\0")
len += 1
}
return len
}