|
|
@@ -0,0 +1,60 @@
|
|
|
+MODULE Showcase15;
|
|
|
+// Session showcase: separate compilation across a DEFINITION /
|
|
|
+// IMPLEMENTATION pair (whose signatures are verified by the new
|
|
|
+// strict 235 check), string concatenation, and IOChan over files.
|
|
|
+//
|
|
|
+// It writes a small report to a file through a channel, closes it,
|
|
|
+// reopens it for reading, reads it back line by line, and prints a
|
|
|
+// summary on stdout. Expected ExitCode: 42.
|
|
|
+IMPORT Showcase15Lib, IOChan, TextIO, Strings;
|
|
|
+
|
|
|
+VAR ExitCode : INTEGER;
|
|
|
+VAR out, inp : IOChan.ChanId;
|
|
|
+VAR name, line : ARRAY [0 .. 63] OF CHAR;
|
|
|
+VAR p : Showcase15Lib.Point;
|
|
|
+VAR total : INTEGER;
|
|
|
+
|
|
|
+PROCEDURE Emit (cid : IOChan.ChanId; s : ARRAY OF CHAR; n : INTEGER);
|
|
|
+(* one "label + number" line on the channel *)
|
|
|
+ VAR buf : ARRAY [0 .. 63] OF CHAR;
|
|
|
+BEGIN
|
|
|
+ Strings.Assign(s, buf);
|
|
|
+ Showcase15Lib.AppendInt(buf, n);
|
|
|
+ IOChan.WriteString(cid, buf);
|
|
|
+ IOChan.WriteLn(cid)
|
|
|
+END Emit;
|
|
|
+
|
|
|
+BEGIN
|
|
|
+ ExitCode := 0;
|
|
|
+ Strings.Assign("gen_ssa/_showcase15.txt", name);
|
|
|
+
|
|
|
+ Showcase15Lib.InitPoint(p, 20, 22);
|
|
|
+ total := Showcase15Lib.SumPoint(p);
|
|
|
+
|
|
|
+ (* write the report through a file channel *)
|
|
|
+ out := IOChan.OpenWrite(name);
|
|
|
+ IF NOT IOChan.IsOpen(out) THEN ExitCode := 90 ELSE
|
|
|
+ IOChan.WriteString(out, "total");
|
|
|
+ IOChan.WriteLn(out);
|
|
|
+ Emit(out, "point ", total);
|
|
|
+ IOChan.Close(out)
|
|
|
+ END;
|
|
|
+
|
|
|
+ (* read it back through another channel, line by line *)
|
|
|
+ inp := IOChan.OpenRead(name);
|
|
|
+ IF NOT IOChan.IsOpen(inp) THEN ExitCode := 91 ELSE
|
|
|
+ IOChan.ReadString(inp, line); (* "total" *)
|
|
|
+ IF line = "total" THEN ExitCode := ExitCode + 1 ELSE ExitCode := 92 END;
|
|
|
+ IOChan.ReadString(inp, line); (* "point 42" *)
|
|
|
+ IF line = "point 42" THEN ExitCode := ExitCode + 2 ELSE ExitCode := 93 END;
|
|
|
+ TextIO.WriteString("read back: ");
|
|
|
+ TextIO.WriteString(line);
|
|
|
+ TextIO.WriteLn;
|
|
|
+ IOChan.Close(inp)
|
|
|
+ END;
|
|
|
+
|
|
|
+ IF ExitCode = 3 THEN ExitCode := total END; (* 42 on success *)
|
|
|
+ TextIO.WriteString("showcase15 total=");
|
|
|
+ TextIO.WriteInt(total);
|
|
|
+ TextIO.WriteLn
|
|
|
+END Showcase15.
|