forked from AbleOS/ableos
63 lines
983 B
Plaintext
63 lines
983 B
Plaintext
length := fn(ptr: ^u8): uint {
|
|
len := 0
|
|
loop if *(ptr + len) == 0 return len else len += 1
|
|
}
|
|
|
|
display_int := fn(num: int, p: ^u8, radix: uint): ^u8 {
|
|
is_negative := num < 0
|
|
if is_negative num = -num
|
|
|
|
ptr := p
|
|
|
|
if num == 0 {
|
|
*ptr = 0x30;
|
|
*(ptr + 1) = 0
|
|
return p
|
|
}
|
|
|
|
loop if num == 0 break else {
|
|
remainder := num % @bitcast(radix)
|
|
num /= @bitcast(radix);
|
|
*ptr = @intcast(remainder + 0x30)
|
|
if remainder > 9 {
|
|
*ptr = @intcast(remainder - 10 + 0x41)
|
|
}
|
|
ptr += 1
|
|
}
|
|
|
|
if is_negative {
|
|
*ptr = 0x2D
|
|
ptr += 1
|
|
}
|
|
// ! it gets broked when you do this ??
|
|
// *ptr = 0
|
|
|
|
@inline(reverse, p)
|
|
return p
|
|
}
|
|
|
|
reverse := fn(s: ^u8): void {
|
|
j := s + @inline(length, s) - 1
|
|
temp := @as(u8, 0)
|
|
loop if s < j {
|
|
temp = *s;
|
|
*s = *j;
|
|
*j = temp
|
|
s += 1
|
|
j -= 1
|
|
} else return
|
|
}
|
|
|
|
equals := fn(lhs: ^u8, rhs: ^u8): bool {
|
|
if lhs == rhs {
|
|
return true
|
|
}
|
|
loop if *lhs != *rhs {
|
|
return false
|
|
} else if *lhs == 0 {
|
|
return true
|
|
} else {
|
|
lhs += 1
|
|
rhs += 1
|
|
}
|
|
} |