summaryrefslogtreecommitdiff
path: root/chapter31/src/main/smp
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-13 16:17:13 -0800
committerCliff Click <cliffc@acm.org>2026-11-13 16:17:13 -0800
commitafcf96444366fb4b7c83f938763013cbc360aade (patch)
tree67eb69ac6cc58322549020550d48aceb8f2f5ff8 /chapter31/src/main/smp
parentd2c59dbe9d6cc8dc4ff4d1e7949bfeddd8bef5d0 (diff)
downloadSimple-afcf96444366fb4b7c83f938763013cbc360aade.tar.gz
Simple-afcf96444366fb4b7c83f938763013cbc360aade.zip
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
Diffstat (limited to 'chapter31/src/main/smp')
-rw-r--r--chapter31/src/main/smp/sys/aryu8.smp11
-rw-r--r--chapter31/src/main/smp/sys/draw/Canvas.smp90
-rw-r--r--chapter31/src/main/smp/sys/text.smp5
3 files changed, 23 insertions, 83 deletions
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<str# ? str[i] : '\0'; };
+}; \ No newline at end of file
diff --git a/chapter31/src/main/smp/sys/draw/Canvas.smp b/chapter31/src/main/smp/sys/draw/Canvas.smp
index c736e4e2..5bd7d68e 100644
--- a/chapter31/src/main/smp/sys/draw/Canvas.smp
+++ b/chapter31/src/main/smp/sys/draw/Canvas.smp
@@ -112,79 +112,25 @@ struct Canvas {
};
};
-// An old-school 3x5 font
+// An old-school 3x5 font, ASCII 32..127. Five octal row digits need u16.
+// Lowercase uses uppercase shapes; unsupported characters use '?'.
+val _glyphs = new u16[~96]{
+ 000000,022202,055000,057575,061202,051245,061202,022000, // space..'
+ 012221,042224,005250,002720,000024,000700,000002,011244, // (../
+ 075557,026227,061247,061216,055711,074616,034757,071222, // 0..7
+ 075757,075716,002020,002024,012421,007070,042124,061202, // 8..?
+ 061202,025755,065656,034443,065556,074647,074644,034553, // @..G
+ 055755,072227,011152,055655,044447,057755,057775,025552, // H..O
+ 065644,025573,065655,034216,072222,055557,055552,055775, // P..W
+ 055255,055222,071247,032223,044211,062226,025000,000007, // X.._
+ 042000,025755,065656,034443,065556,074647,074644,034553, // `..g
+ 055755,072227,011152,055655,044447,057755,057775,025552, // h..o
+ 065644,025573,065655,034216,072222,055557,055552,055775, // p..w
+ 055255,055222,071247,032423,022222,062126,003600,061202, // x..DEL
+};
+
val _glyph = { u8 c ->
- // 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 ->