From f1c1c070f0491cba8b18f3169e72e9a1df8f1a2a Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Thu, 8 May 2025 13:38:45 -0700 Subject: Work on a cmd-line driver for Simple --- chapter22/docs/examples/A_helloWorld.smp | 3 +++ chapter22/docs/examples/BubbleSort.smp | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 chapter22/docs/examples/A_helloWorld.smp create mode 100644 chapter22/docs/examples/BubbleSort.smp (limited to 'chapter22/docs') diff --git a/chapter22/docs/examples/A_helloWorld.smp b/chapter22/docs/examples/A_helloWorld.smp new file mode 100644 index 00000000..07ff935f --- /dev/null +++ b/chapter22/docs/examples/A_helloWorld.smp @@ -0,0 +1,3 @@ +// -*- mode: java; -*- +sys.io.p("Hello, World!"); +return 0; diff --git a/chapter22/docs/examples/BubbleSort.smp b/chapter22/docs/examples/BubbleSort.smp new file mode 100644 index 00000000..af110159 --- /dev/null +++ b/chapter22/docs/examples/BubbleSort.smp @@ -0,0 +1,25 @@ +// -*- mode: java; -*- + + +val _exit = { u8[~] msg -> + sys.io.p(msg); + sys.libc._exit(1); +}; + +struct Scan { + int !x; + u8[~] buf; +}; + + +// Read from stdin a line of the form "[ 4, 3, 2, 1]" and print it sorted. +val main = { -> + Scan !s = new Scan{ buf = sys.io.stdin(); }; + var junk = new u8[1]; + while( s.x < s.buf# ) { + sys.io.p("scan "); + junk[0] = s.buf[s.x++]; + sys.io.p(junk); + }; + return 0; +}; -- cgit v1.2.3