From 259f60b105eb770bc6f7e3bd36d91f2b217e9315 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 10 Aug 2026 11:11:18 -0700 Subject: Chapter 30: Text Formatting and Diagnostics Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: Symious <14933944+symious@users.noreply.github.com> Co-authored-by: Jun Kawasaki Co-authored-by: Claude Opus 5 --- src/main/smp/sys/aryi64.smp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/main/smp/sys/aryi64.smp') diff --git a/src/main/smp/sys/aryi64.smp b/src/main/smp/sys/aryi64.smp index 98b72605..b9f1fbed 100644 --- a/src/main/smp/sys/aryi64.smp +++ b/src/main/smp/sys/aryi64.smp @@ -9,36 +9,36 @@ struct aryi64 { }; // Grow as needed - val _grow = { int len2 -> - if( len+len2 < buf# ) return self; - int newlen = buf# * 2; - while( len+len2 >= newlen ) newlen *= 2; + val _grow = { u32 len2 -> + if( len+len2 <= buf# ) return self; + u32 newlen = ary.capacity(buf#,len+len2); + if( !newlen ) libc._exit(1); // Length exceeds the array representation. i64[] !buf2 = new i64[newlen]; - for( int i=0; i _grow(1).buf[len++] = c; self; }; - val get = { int index -> return buf[index]; }; + val get = { u32 index -> return buf[index]; }; // Write the bracketed array-list form to aryu8. val str = { -> // TODO: clunky default constructor syntax var str = new aryu8().add('['); - for( int i=0; i + val swap = { u32 i, u32 j -> i64 tmp = buf[i]; buf[i] = buf[j]; buf[j] = tmp; @@ -75,8 +75,11 @@ val parseAryI64 = { u8[~] str -> return s.x == s.buf# ? nums : null; }; -val copy = { i64[] dst, int doff, i64[~] src, int soff, int len -> - for( int i=0; i + if( doff > dst# || soff > src# ) return dst; + if( len > dst# - doff ) len = dst# - doff; + if( len > src# - soff ) len = src# - soff; + for( u32 i=0; i