1
0
Fork 0
forked from AbleOS/ableos

broken for now

This commit is contained in:
koniifer 2024-12-17 17:43:00 +00:00 committed by peony
parent 8a78faecdf
commit 9e0ed8a5d7
3 changed files with 40 additions and 42 deletions

6
Cargo.lock generated
View file

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

View file

@ -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 { format_int := fn($T: type, v: T, str: ^u8, radix: T): uint {
if integer(T) { 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 { format_inner := fn($T: type, v: T, str: ^u8, opts: FormatOptions): uint {
if integer(T) | pointer(T) { match @as(Kind, @bitcast(@kindof(T))) {
if integer(T) { .Pointer => return @inline(format_int, uint, @bitcast(v), str, 16),
return @inline(format_int, T, v, str, @intcast(opts.radix)) .Builtin => {
} else { if integer(T) {
return @inline(format_int, uint, @bitcast(v), str, 16) if integer(T) {
} return @inline(format_int, T, v, str, @intcast(opts.radix))
} else if T == bool { } else {
return @inline(format_bool, v, str) }
} else if float(T) { } else if T == bool {
return @inline(format_float, T, v, str, opts.decimal_digits, @intcast(opts.radix)) return @inline(format_bool, v, str)
} else if !primitive(T) { } else if float(T) {
i := 0 return @inline(format_float, T, v, str, opts.decimal_digits, @intcast(opts.radix))
// 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
} }
}; },
*@as(^[u8; 1], @bitcast(str + len)) = *@bitcast(")\0") .Struct => {
len += 1 i := 0
return len name := @nameof(T);
} else { *@as(^[u8; @len(name)], @bitcast(str)) = *@bitcast(name)
panic("Unsupported formatter type\0") 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,
} }
} }

View file

@ -24,9 +24,7 @@ panic := fn(message: ?^u8): never {
die die
} }
$pointer := fn($T: type): bool { Kind := enum {Builtin, Struct, Enum, Union, Pointer, Slice, Opt, Function, Template, Global, Const, Module}
return T != f64 & T != uint & T != int & @sizeof(T) == @sizeof(uint) & @alignof(T) == @alignof(uint)
}
$unsigned_int := fn($T: type): bool { $unsigned_int := fn($T: type): bool {
return T == uint | T == u8 | T == u16 | T == u32 return T == uint | T == u8 | T == u16 | T == u32
@ -44,10 +42,6 @@ $float := fn($T: type): bool {
return T == f32 | T == f64 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 { $float_bytes := fn($T: type): type {
if T == f64 return uint else if T == f32 return u32 if T == f64 return uint else if T == f32 return u32
} }