summaryrefslogtreecommitdiff
path: root/chapter22/docs/examples
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-05-08 13:38:45 -0700
committerCliff Click <cliffc@acm.org>2025-05-08 13:38:45 -0700
commitf1c1c070f0491cba8b18f3169e72e9a1df8f1a2a (patch)
treed6b3a7c903daf0d3f953e40f877030d86b690377 /chapter22/docs/examples
parenta174b75edab35f078455b4b9a737f383a3be55a3 (diff)
downloadSimple-f1c1c070f0491cba8b18f3169e72e9a1df8f1a2a.tar.gz
Simple-f1c1c070f0491cba8b18f3169e72e9a1df8f1a2a.zip
Work on a cmd-line driver for Simple
Diffstat (limited to 'chapter22/docs/examples')
-rw-r--r--chapter22/docs/examples/A_helloWorld.smp3
-rw-r--r--chapter22/docs/examples/BubbleSort.smp25
2 files changed, 28 insertions, 0 deletions
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;
+};