1
0
Fork 0
forked from AbleOS/ableos

minor changes

This commit is contained in:
Able 2024-09-16 20:45:00 -05:00
parent 48027196b1
commit 3173b63c93

View file

@ -3,8 +3,6 @@ length := fn(ptr: ^u8): int {
loop if *(ptr + len) == 0 break else len += 1
return len
}
// WTFFF is wrong with display_int
display_int := fn(num: int, p: ^u8): ^u8 {
ptr := p
negative := num < 0
@ -12,37 +10,42 @@ display_int := fn(num: int, p: ^u8): ^u8 {
num = -num
}
if num == 0 {
*ptr = 48
ptr += 1
} else {
loop if num == 0 break else {
*ptr = num % 10 + 48
ptr += 1
num /= 10
}
*p = 48;
*(p + 1) = 0
return p
}
if negative {
*ptr = 45
ptr += 1
};
*ptr = 0
@inline(reverse, p)
neg := false
if num < 0 {
neg = true
num = -num
}
loop if num == 0 break else {
*(p + i) = num % 10 + 48
num /= 10
i += 1
}
if neg {
*(p + i) = 45
i += 1
}
reverse(p, i)
return p
}
reverse := fn(s: ^u8): void {
//reverse a string, don't remove digits
len := 0
loop if *(s + len) == 0 break else len += 1
i := 0
j := len - 1
temp := 0
loop if i >= j break else {
temp = *(s + i);
*(s + i) = *(s + j);
*(s + j) = temp
i += 1
j -= 1
reverse := fn(p: ^u8, len: int): void {
start := 0
end := len - 1
loop if start >= end break else {
temp := *(p + start);
*(p + start) = *(p + end);
*(p + end) = temp
start += 1
end -= 1
}
return
}