// Ary/Vector of i64s struct aryi64 { u32 !len = 0; i64[] !buf; new aryi64 = { i64[] b -> buf = b; }; // Grow as needed 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( u32 i=0; i _grow(1).buf[len++] = c; self; }; 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( u32 i=0; i i64 tmp = buf[i]; buf[i] = buf[j]; buf[j] = tmp; self; }; }; // Parse a comma-separated list of numbers, wrapped with square brackets, // with optional whitespace e.g. "[ -17, 0,99,12456789 ] ". // parseAryI64 & aryi64.str are bijections modulo whitespace. // Returns null if the parse failed, without giving a clue as to why. val parseAryI64 = { u8[~] str -> !scan !s = new scan(str); if( !s.match('[') ) return null; // Array of parsed results var nums = new aryi64(new i64[1]); // Parse a list of numbers if( s.match(']') ) // Handle the empty list return nums; // Parse number commas "123, " until something else while( s.x < s.buf# ) { nums.add(s.number()); if( s.bad ) return null; if( !s.match(',') ) break; }; // Close the list if( !s.match(']') ) return null; s.skip(); return s.x == s.buf# ? nums : null; }; val copy = { i64[] dst, u32 doff, i64[~] src, u32 soff, u32 len -> 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