String Library Update #15

Merged
able merged 3 commits from Trees/ableos_time:my-branch into master 2024-07-16 20:52:54 -05:00
2 changed files with 5 additions and 49 deletions
Showing only changes of commit 9f9c7af85f - Show all commits

View file

@ -7,8 +7,7 @@ length := fn(ptr: ^u8): int {
return len; return len;
} }
display_int := fn(num: int): ^u8 { display_int := fn(num: int, p: ^u8): ^u8 {
p := page;
i := 0; i := 0;
if num == 0 { if num == 0 {
set(p, 48); set(p, 48);

View file

@ -1,64 +1,21 @@
stn := @use("../../../libraries/stn/src/lib.hb"); stn := @use("../../../libraries/stn/src/lib.hb");
log := stn.log; log := stn.log;
mem := stn.memory; mem := stn.memory;
s := stn.string;
page := 0 page := 0
main := fn(): void { main := fn(): void {
page += mem.request_page(1); page += mem.request_page(1);
port_str := "\0\{46}\0"; port_str := "\0\{47}\0";
a := @eca(u8, 3, 3, port_str, 2); a := @eca(u8, 3, 3, port_str, 2);
log.debug(&a);
n := 5000000; n := 5000000;
loop { loop {
if n == 0 break; if n == 0 break;
n -= 1; n -= 1;
stack_reclamation_edge_case := 0; stack_reclamation_edge_case := 0;
} }
td := display_int(100); td := s.display_int(a, page);
log.debug(td); log.debug(td);
return; return;
} }
display_int := fn(num: int): ^u8 {
p := page;
i := 0;
if num == 0 {
set(p, 48);
return p;
}
loop {
if num == 0 break;
set(p + i, num % 10 + 48);
num /= 10;
i += 1;
}
reverse(p);
//null terminate
set(p + i, 0);
return p;
}
reverse := fn(s: ^u8): void {
//reverse a string, don't remove digits
len := 0;
loop {
if *(s + len) == 0 break;
len += 1;
}
i := 0;
j := len - 1;
loop {
if i >= j break;
temp := *(s + i);
*(s + i) = *(s + j);
*(s + j) = temp;
i += 1;
j -= 1;
}
return;
}
set := fn(change: ^int, new: int): void {
*(change) = new;
return;
}