Przeglądaj źródła

toto.mod smoke build: TestIO.def/.mod + invoke.sh (verified, prints greeting, exit 0)

Eric Streit 2 tygodni temu
rodzic
commit
001e5bc089

+ 1 - 0
compiler/.gitignore

@@ -7,4 +7,5 @@ src/M2.err
 src/modules.lst
 src/*.LST
 tests/*.LST
+/*.LST
 gen_ssa/

+ 11 - 0
compiler/TestIO.def

@@ -0,0 +1,11 @@
+DEFINITION MODULE TestIO;
+(* Minimal test I/O for toto.mod: WriteString + WriteLn, bound to the
+   runtime shim (same externals as stdlib/SysIO). *)
+
+PROCEDURE WriteString (VAR s : ARRAY OF CHAR);
+(* Writes s to standard output (no newline). *)
+
+PROCEDURE WriteLn;
+(* Writes a newline to standard output. *)
+
+END TestIO.

+ 20 - 0
compiler/TestIO.mod

@@ -0,0 +1,20 @@
+IMPLEMENTATION MODULE TestIO;
+(* Thin wrapper over the C shim's external procedures. *)
+
+PROCEDURE m2write (VAR s : ARRAY OF CHAR);
+  EXTERNAL;
+
+PROCEDURE m2writeln;
+  EXTERNAL;
+
+PROCEDURE WriteString (VAR s : ARRAY OF CHAR);
+BEGIN
+  m2write(s)
+END WriteString;
+
+PROCEDURE WriteLn;
+BEGIN
+  m2writeln
+END WriteLn;
+
+END TestIO.

+ 23 - 0
compiler/invoke.sh

@@ -0,0 +1,23 @@
+#!/bin/sh
+# Build (and run) toto.mod through the V3 pipeline.
+#
+#   ./M2 <session .def/.mod files> <program.mod>   -> gen_ssa/<Module>.ssa
+#   qbe                                            -> gen_ssa/<Module>.s
+#   cc  (+ runtime shim)                           -> gen_ssa/<Module>
+#
+# toto.mod is `MODULE toto;` and imports TestIO, so the session is
+# TestIO.def, TestIO.mod, then the program module last.
+#
+# Usage: ./invoke.sh        (from anywhere; it cd's to its own dir)
+set -e
+cd "$(dirname "$0")"
+
+PROG=toto                       # output name = module name (lowercase)
+
+./M2 TestIO.def TestIO.mod toto.mod
+qbe -o "gen_ssa/$PROG.s" "gen_ssa/$PROG.ssa"
+cc "gen_ssa/$PROG.s" ../runtime/syslib/shim.c -o "gen_ssa/$PROG" -lm
+
+echo "--- running gen_ssa/$PROG ---"
+if "./gen_ssa/$PROG"; then rc=0; else rc=$?; fi
+echo "exit=$rc"

+ 8 - 0
compiler/toto.mod

@@ -0,0 +1,8 @@
+MODULE toto;
+
+FROM TestIO IMPORT WriteString, WriteLn;
+
+BEGIN
+ WriteString("Hello world, I'm coming to life!");
+WriteLn;
+END toto.

+ 47 - 0
docs/summary_invoke-toto.md

@@ -0,0 +1,47 @@
+# Summary — toto.mod test build (`invoke.sh`)
+
+A tiny end-to-end smoke build of a user program, added on top of step
+8.3 (suite 106/106).
+
+## Files
+
+- `compiler/toto.mod` — `MODULE toto;`, imports `FROM TestIO IMPORT
+  WriteString, WriteLn;` and prints
+  `Hello world, I'm coming to life!`.
+- `compiler/TestIO.def` / `compiler/TestIO.mod` — minimal `WriteString`
+  + `WriteLn`, bound to the runtime shim externals (`m2write`,
+  `m2writeln`), same approach as `stdlib/SysIO`. (No `TestIO` existed
+  in the tree before.)
+- `compiler/invoke.sh` — the build pipeline, executable.
+
+## Pipeline
+
+```sh
+./M2 TestIO.def TestIO.mod toto.mod        # module `toto` -> gen_ssa/toto.ssa
+qbe -o gen_ssa/toto.s gen_ssa/toto.ssa
+cc gen_ssa/toto.s ../runtime/syslib/shim.c -o gen_ssa/toto -lm
+./gen_ssa/toto
+```
+
+The output name is the **module name** (`toto`, as written in the
+source), not the file name. Session files: definitions/implementations
+first, the program module last.
+
+## Verification
+
+`./invoke.sh` (from `compiler/`):
+
+```
+Parsed correctly
+--- running gen_ssa/toto ---
+Hello world, I'm coming to life!
+exit=0
+```
+
+## Notes
+
+- `/*.LST` added to `compiler/.gitignore` (driver listings at the
+  compiler root are build artifacts, like `src/*.LST` and
+  `tests/*.LST`).
+- `invoke.sh` is toto-specific; adapt `PROG`/the `./M2` file list for
+  other programs.