ソースを参照

showcase14: enums, string =/#, Unicode, Conversions/RealIO, ProgramArgs, IOChan

End-to-end program linking seven modules; accumulates checks and
exits 42. stdout: 'showcase14 n=42' / '3.500000E+00 ok ✓'. IOChan
demo goes to stderr (stdio buffering vs unbuffered shim writes).
127/127.
Eric Streit 1 週間 前
親
コミット
94c4c5e1c2
3 ファイル変更、137 行追加、0 行削除
  1. 10 0
      compiler/run_tests.sh
  2. 67 0
      compiler/tests/showcase14.mod
  3. 60 0
      docs/summary_showcase14.md

+ 10 - 0
compiler/run_tests.sh

@@ -271,6 +271,16 @@ rm -f gen_ssa/_showcase11.txt
 # statements, 1-char strings, qualified type names.
 # statements, 1-char strings, qualified type names.
 expect_run_files Showcase12 42 showcase12lib.def showcase12lib.mod showcase12.mod
 expect_run_files Showcase12 42 showcase12lib.def showcase12lib.mod showcase12.mod
 expect_run_files_out Showcase13 42 "Even(8)=T Odd(7)=T total=42" ../stdlib/sysio.def ../stdlib/sysio.mod showcase13.mod
 expect_run_files_out Showcase13 42 "Even(8)=T Odd(7)=T total=42" ../stdlib/sysio.def ../stdlib/sysio.mod showcase13.mod
+expect_run_files_out Showcase14 42 "showcase14 n=42" \
+  ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
+  ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
+  ../stdlib/sysio.def ../stdlib/sysio.mod \
+  ../stdlib/textio.def ../stdlib/textio.mod \
+  ../stdlib/conversions.def ../stdlib/conversions.mod \
+  ../stdlib/realio.def ../stdlib/realio.mod \
+  ../stdlib/programargs.def ../stdlib/programargs.mod \
+  ../stdlib/iochan.def ../stdlib/iochan.mod \
+  showcase14.mod
 expect_run_files_out MixProg 0 "7" ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod ../stdlib/textio.def ../stdlib/textio.mod ../stdlib/sysio.def ../stdlib/sysio.mod ../stdlib/files.def ../stdlib/files.mod d_mix_prog.mod
 expect_run_files_out MixProg 0 "7" ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod ../stdlib/textio.def ../stdlib/textio.mod ../stdlib/sysio.def ../stdlib/sysio.mod ../stdlib/files.def ../stdlib/files.mod d_mix_prog.mod
 rm -f gen_ssa/_mix.txt
 rm -f gen_ssa/_mix.txt
 
 

+ 67 - 0
compiler/tests/showcase14.mod

@@ -0,0 +1,67 @@
+MODULE Showcase14;
+// Session showcase: enumerations (literals in expressions / CASE /
+// CONST), string content equality, Unicode (UCHAR literals, the Utf8
+// codec, UTF-8 output), Conversions / RealIO, ProgramArgs and IOChan.
+// Prints two lines and exits 42.
+IMPORT SysIO, TextIO, Utf8, Conversions, RealIO, ProgramArgs, IOChan;
+
+VAR ExitCode : INTEGER;
+VAR n, m : INTEGER;
+VAR out : IOChan.ChanId;
+VAR s : ARRAY [0 .. 31] OF CHAR;
+VAR cp : UCHAR;
+VAR next : CARDINAL;
+VAR x : REAL;
+
+TYPE Color = (red, green, blue);
+CONST Favourite = blue;
+
+PROCEDURE Bump (points : INTEGER);
+BEGIN
+  n := n + points
+END Bump;
+
+BEGIN
+  n := 0;
+
+  (* enumerations: CASE label, ordinal ordering, CONST *)
+  CASE Favourite OF
+    red: n := 100
+  | green: n := 100
+  | blue: Bump(1)
+  END;
+  IF red < green THEN Bump(2) END;
+
+  (* string content equality *)
+  IF "abc" = "abc" THEN Bump(4) END;
+  IF "abc" # "abd" THEN Bump(8) END;
+
+  (* Unicode: strict decode of a UTF-8 literal back to a UCHAR *)
+  IF Utf8.Decode("é", 0, cp, next) AND (UORD(cp) = 233) THEN Bump(16) END;
+
+  (* ProgramArgs: run with no arguments *)
+  IF ProgramArgs.ArgCount() = 0 THEN Bump(5) END;
+
+  (* Conversions: integer and real round-trips *)
+  IF Conversions.StrToInt("-56", m) AND (m = -56) THEN Bump(3) END;
+  IF Conversions.StrToReal("3.5", x) AND (x = 3.5) THEN Bump(3) END;
+
+  (* IOChan demo goes to stderr (stdio buffering would otherwise
+     reorder it against the unbuffered shim writes) *)
+  out := IOChan.StdErrChan();
+  IOChan.WriteString(out, "iochan: showcase14 evaluating");
+  IOChan.WriteLn(out);
+
+  (* stdout: summary line, then REAL + UTF-8 via TextIO *)
+  SysIO.Write("showcase14 n=");
+  Conversions.IntToStr(n, s);
+  SysIO.Write(s);
+  SysIO.WriteLn;
+
+  RealIO.WriteReal(3.5);
+  TextIO.WriteString(" ");
+  TextIO.UWriteString(U"ok ✓");
+  TextIO.WriteLn;
+
+  ExitCode := n
+END Showcase14.

+ 60 - 0
docs/summary_showcase14.md

@@ -0,0 +1,60 @@
+# Showcase 14 — session capabilities end-to-end
+
+Tags `v3-showcase14` (program) and `v3-showcase14-summary` (this doc).
+Suite **127/127**; fixpoint **OK** (2,071,330 bytes).
+
+## What it runs
+
+`compiler/tests/showcase14.mod` (`Showcase14`) links seven modules and
+exercises everything added this session:
+
+```
+IMPORT SysIO, TextIO, Utf8, Conversions, RealIO, ProgramArgs, IOChan;
+```
+
+1. **Enumerations** — `TYPE Color = (red, green, blue)`,
+   `CONST Favourite = blue`; a literal as a `CASE` label, ordinal
+   ordering (`red < green`), and a `CONST` initialiser.
+2. **String content equality** — `"abc" = "abc"`, `"abc" # "abd"`.
+3. **Unicode** — `Utf8.Decode("é", 0, cp, next)` (strict RFC 3629)
+   back to `UCHAR`, checked with `UORD(cp) = 233`.
+4. **Conversions** — `StrToInt("-56")` and `StrToReal("3.5")`
+   round-trips; `IntToStr` used to render the result.
+5. **ProgramArgs** — `ArgCount()` (run with no arguments).
+6. **RealIO / TextIO** — `WriteReal(3.5)` and
+   `UWriteString(U"ok ✓")` (UTF-8).
+7. **IOChan** — `StdErrChan` diagnostics via the channel handle.
+
+Each check adds to an accumulator; the program prints and exits with
+it (42).
+
+## Output
+
+```
+showcase14 n=42
+3.500000E+00 ok ✓
+```
+
+(stdout; the `IOChan` line goes to stderr so that stdio buffering does
+not reorder it against the unbuffered shim writes).
+
+## Registration
+
+`expect_run_files_out Showcase14 42 "showcase14 n=42" …` with the
+`Utf8`/`SysShim`/`sysio`/`textio`/`conversions`/`realio`/`programargs`/
+`iochan` definitions and bodies.
+
+## Session features exercised
+
+| Area | Where |
+| --- | --- |
+| Enums in expressions/CASE/CONST/params | `docs/summary_lang-polish.md` (`v3-lang-polish`) |
+| String `=`/`#` | same |
+| Unicode `UCHAR`/`UString`/`Utf8`/`TextIO.U*` | `docs/summary_unicode.md` (`v3-unicode-1/-2`) |
+| `Conversions` / `RealIO` | `docs/summary_stdlib-conversions.md` |
+| `ProgramArgs` / `IOChan` | `docs/summary_programargs-iochan.md` |
+
+## Files
+
+`compiler/tests/showcase14.mod`, `compiler/run_tests.sh`,
+`docs/summary_showcase14.md`.