From afcf96444366fb4b7c83f938763013cbc360aade Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Fri, 13 Nov 2026 16:17:13 -0800 Subject: Array init syntax New array init syntax; used in a bunch of places. Allows e.g. read-only arrays with not-null entries. Fix bug x86 encoding of mem/cmp/fp compares --- chapter31/src/main/smp/sys/aryu8.smp | 11 ++-- chapter31/src/main/smp/sys/draw/Canvas.smp | 90 ++++++------------------------ chapter31/src/main/smp/sys/text.smp | 5 +- 3 files changed, 23 insertions(+), 83 deletions(-) (limited to 'chapter31/src/main/smp/sys') diff --git a/chapter31/src/main/smp/sys/aryu8.smp b/chapter31/src/main/smp/sys/aryu8.smp index 88574522..76d47ec5 100644 --- a/chapter31/src/main/smp/sys/aryu8.smp +++ b/chapter31/src/main/smp/sys/aryu8.smp @@ -69,10 +69,7 @@ val atoi = { u8[~] str -> // Zero-terminate a string for libc, reserving one array element for the zero. { u8[~] -> u8[] } str0 = { u8[~] str -> - if( str# == sys.integer.MAX_U32 ) libc._exit(1); - u8[] !strz = new u8[str#+1]; - u32 len=str#; - ary.copy(strz,0,str,0,len); - strz[str#] = '\0'; - strz; -}; + if( str# == sys.integer.MAX_U32 ) libc._exit(1); + // Copy, terminate and return + return new u8[str#+1]{i64 i -> i - // Only space for upper-case letters in a 3x5 font - if( 'a' <= c <= 'z' ) - c -= 'a'-'A'; - // Five octal digits: one 3-bit row per digit, top to bottom. - if( c==' ' ) return 000000; - if( c=='0' ) return 075557; - if( c=='1' ) return 026227; - if( c=='2' ) return 061247; - if( c=='3' ) return 061216; - if( c=='4' ) return 055711; - if( c=='5' ) return 074616; - if( c=='6' ) return 034757; - if( c=='7' ) return 071222; - if( c=='8' ) return 075757; - if( c=='9' ) return 075716; - if( c=='A' ) return 025755; - if( c=='B' ) return 065656; - if( c=='C' ) return 034443; - if( c=='D' ) return 065556; - if( c=='E' ) return 074647; - if( c=='F' ) return 074644; - if( c=='G' ) return 034553; - if( c=='H' ) return 055755; - if( c=='I' ) return 072227; - if( c=='J' ) return 011152; - if( c=='K' ) return 055655; - if( c=='L' ) return 044447; - if( c=='M' ) return 057755; - if( c=='N' ) return 057775; - if( c=='O' ) return 025552; - if( c=='P' ) return 065644; - if( c=='Q' ) return 025573; - if( c=='R' ) return 065655; - if( c=='S' ) return 034216; - if( c=='T' ) return 072222; - if( c=='U' ) return 055557; - if( c=='V' ) return 055552; - if( c=='W' ) return 055775; - if( c=='X' ) return 055255; - if( c=='Y' ) return 055222; - if( c=='Z' ) return 071247; - if( c=='-' ) return 000700; - if( c=='.' ) return 000002; - if( c==':' ) return 002020; - if( c==',' ) return 000024; - if( c==';' ) return 002024; - if( c=='\'' ) return 022000; - if( c=='"' ) return 055000; - if( c=='`' ) return 042000; - if( c=='/' ) return 011244; - if( c=='\\' ) return 044211; - if( c=='(' ) return 012221; - if( c==')' ) return 042224; - if( c=='[' ) return 032223; - if( c==']' ) return 062226; - if( c=='{' ) return 032423; - if( c=='}' ) return 062126; - if( c=='+' ) return 002720; - if( c=='=' ) return 007070; - if( c=='_' ) return 000007; - if( c=='<' ) return 012421; - if( c=='>' ) return 042124; - if( c=='|' ) return 022222; - if( c=='^' ) return 025000; - if( c=='~' ) return 003600; - if( c=='*' ) return 005250; - if( c=='#' ) return 057575; - if( c=='%' ) return 051245; - if( c=='!' ) return 022202; - if( c=='?' ) return 061202; - return 061202; + return 32<=c<128 ? _glyphs[c-32] : 061202; }; // Pixel coverage for a round-ended segment, separate from traversal. diff --git a/chapter31/src/main/smp/sys/text.smp b/chapter31/src/main/smp/sys/text.smp index a28edf6d..2c4b44ff 100644 --- a/chapter31/src/main/smp/sys/text.smp +++ b/chapter31/src/main/smp/sys/text.smp @@ -5,10 +5,7 @@ val begin = { -> new aryu8(); }; val end = { aryu8 b -> - val bytes = new u8[b.len]; - ary.copy(bytes,0,b.buf,0,b.len); - u8[~] result = bytes; - result; + new u8[~b.len]{ i64 i -> b.buf[i]; }; }; val _pad = { !aryu8 b, i64 n, u8 c -> -- cgit v1.2.3