Procházet zdrojové kódy

m2comp step 5.1 — toto.def/toto.mod naming plus Showcase5 tour (55/55 tests green)

Eric Streit před 3 týdny
rodič
revize
363ef4c50c

binární
MC4/Showcase5.MC4


+ 11 - 6
docs/summary_m2comp_step5.md

@@ -1,10 +1,13 @@
 # m2comp step 5 — separate compilation (tag: `m2comp-step5`)
 # m2comp step 5 — separate compilation (tag: `m2comp-step5`)
 
 
 Single-image separate compilation, v1 step-11 style: `M2comp lib.def
 Single-image separate compilation, v1 step-11 style: `M2comp lib.def
-impl.mod prog.mod` compiles definitions, then implementations, then
-exactly one program into one `<Prog>.MC4` (depCount 0). One `.LST`
-per input, fail-fast. Suite 54/54 (41 inherited + 6 run + 7 reject);
-all single-file images byte-identical to step 4 (no drift).
+lib.mod prog.mod` compiles definitions, then implementations, then
+exactly one program into one `<Prog>.MC4` (depCount 0). Definition
+and implementation share their basename (`toto.def` / `toto.mod`)
+and hence one `.LST` (the implementation listing overwrites the
+definition's); one `.LST` per basename otherwise, fail-fast. Suite
+55/55 (41 inherited + 7 run + 7 reject); all single-file images
+byte-identical to step 4 (no drift).
 
 
 ## Session model
 ## Session model
 
 
@@ -59,14 +62,16 @@ all single-file images byte-identical to step 4 (no drift).
 - `run_tests.sh`: `expect_run_files` / `expect_fail_files` /
 - `run_tests.sh`: `expect_run_files` / `expect_fail_files` /
   `expect_fail_multi` (MC4-aware, timeout-guarded like the rest).
   `expect_fail_multi` (MC4-aware, timeout-guarded like the rest).
 
 
-## Tests — 54/54
+## Tests — 55/55
 
 
 New `tests/d_*` (hand-computed ExitCodes): `DBasic` 60 (FROM +
 New `tests/d_*` (hand-computed ExitCodes): `DBasic` 60 (FROM +
 qualified, var/proc), `DFrom` 35 (two libs, const/var/proc,
 qualified, var/proc), `DFrom` 35 (two libs, const/var/proc,
 cross-def import), `DMulti` 68 (qualified VAR actual), `DInit` 7
 cross-def import), `DMulti` 68 (qualified VAR actual), `DInit` 7
 (impl `BEGIN` runs: preset 2 vs zeroed 0), `DFunc` 81 (nested
 (impl `BEGIN` runs: preset 2 vs zeroed 0), `DFunc` 81 (nested
 function calls), `DType` 40 (`FROM` array type + qualified
 function calls), `DType` 40 (`FROM` array type + qualified
-`Lib.Point` record). Rejections: unknown definition (201),
+`Lib.Point` record). Showcase `tests/showcase5.mod` (+ `s5lib.def`
+/ `s5lib.mod`) tours every interface kind in one program and
+prints 46. Rejections: unknown definition (201),
 signature mismatch (231), missing body (231), unimplemented
 signature mismatch (231), missing body (231), unimplemented
 import (201), duplicate definition (200), private access (201),
 import (201), duplicate definition (200), private access (201),
 second program file (driver-level).
 second program file (driver-level).

+ 9 - 8
run_tests.sh

@@ -182,19 +182,20 @@ expect_run r_ptr.mod 111
 expect_run r_module.mod 83
 expect_run r_module.mod 83
 expect_run r_const.mod 1102
 expect_run r_const.mod 1102
 echo "=== Step-5 run tests (DEFINITION/IMPLEMENTATION/IMPORT) ==="
 echo "=== Step-5 run tests (DEFINITION/IMPLEMENTATION/IMPORT) ==="
-expect_run_files DBasic 60 tests/d_lib.def tests/d_libimpl.mod tests/d_basic.mod
-expect_run_files DFrom 35 tests/d_lib.def tests/d_libimpl.mod tests/d_lib2.def tests/d_lib2impl.mod tests/d_from.mod
-expect_run_files DMulti 68 tests/d_lib.def tests/d_libimpl.mod tests/d_lib2.def tests/d_lib2impl.mod tests/d_multi.mod
-expect_run_files DInit 7 tests/d_lib.def tests/d_libimpl.mod tests/d_init.mod
-expect_run_files DFunc 81 tests/d_lib.def tests/d_libimpl.mod tests/d_func.mod
-expect_run_files DType 40 tests/d_lib.def tests/d_libimpl.mod tests/d_type.mod
+expect_run_files DBasic 60 tests/d_lib.def tests/d_lib.mod tests/d_basic.mod
+expect_run_files DFrom 35 tests/d_lib.def tests/d_lib.mod tests/d_lib2.def tests/d_lib2.mod tests/d_from.mod
+expect_run_files DMulti 68 tests/d_lib.def tests/d_lib.mod tests/d_lib2.def tests/d_lib2.mod tests/d_multi.mod
+expect_run_files DInit 7 tests/d_lib.def tests/d_lib.mod tests/d_init.mod
+expect_run_files DFunc 81 tests/d_lib.def tests/d_lib.mod tests/d_func.mod
+expect_run_files DType 40 tests/d_lib.def tests/d_lib.mod tests/d_type.mod
+expect_run_files Showcase5 46 tests/s5lib.def tests/s5lib.mod tests/showcase5.mod
 echo "=== Step-5 rejection tests ==="
 echo "=== Step-5 rejection tests ==="
 expect_fail_files "undeclared identifier" tests/d_bad_nodef.mod
 expect_fail_files "undeclared identifier" tests/d_bad_nodef.mod
 expect_fail_files "procedure forward mismatch" tests/d_lib.def tests/d_bad_sig.mod
 expect_fail_files "procedure forward mismatch" tests/d_lib.def tests/d_bad_sig.mod
 expect_fail_files "procedure forward mismatch" tests/d_lib.def tests/d_bad_nobody.mod
 expect_fail_files "procedure forward mismatch" tests/d_lib.def tests/d_bad_nobody.mod
 expect_fail_files "undeclared identifier" tests/d_lib.def tests/d_bad_noimpl.mod
 expect_fail_files "undeclared identifier" tests/d_lib.def tests/d_bad_noimpl.mod
 expect_fail_files "duplicate identifier" tests/d_lib.def tests/d_bad_dup.def
 expect_fail_files "duplicate identifier" tests/d_lib.def tests/d_bad_dup.def
-expect_fail_files "undeclared identifier" tests/d_lib.def tests/d_libimpl.mod tests/d_bad_priv.mod
-expect_fail_multi tests/d_lib.def tests/d_libimpl.mod tests/d_basic.mod tests/d_basic.mod
+expect_fail_files "undeclared identifier" tests/d_lib.def tests/d_lib.mod tests/d_bad_priv.mod
+expect_fail_multi tests/d_lib.def tests/d_lib.mod tests/d_basic.mod tests/d_basic.mod
 echo "--- $pass passed, $fail failed ---"
 echo "--- $pass passed, $fail failed ---"
 [ "$fail" -eq 0 ]
 [ "$fail" -eq 0 ]

+ 16 - 8
tests/d_lib.LST

@@ -1,13 +1,21 @@
 Listing:
 Listing:
 
 
-    1  DEFINITION MODULE DLib;
-    2  CONST step = 5;
-    3  VAR counter : INTEGER;
-    4  TYPE Vec = ARRAY [0 .. 3] OF INTEGER;
-    5  TYPE Point = RECORD x, y : INTEGER END;
-    6  PROCEDURE Add(n : INTEGER);
-    7  PROCEDURE Get() : INTEGER;
-    8  END DLib.
+    1  IMPLEMENTATION MODULE DLib;
+    2  VAR total : INTEGER;
+    3  PROCEDURE Add(n : INTEGER);
+    4  BEGIN
+    5    total := total + n;
+    6    counter := counter + n
+    7  END Add;
+    8  PROCEDURE Get() : INTEGER;
+    9  BEGIN
+   10    RETURN total + counter + step
+   11  END Get;
+   12  BEGIN
+   13    (* preset proves the init body runs: zeroed globals would read 0 *)
+   14    total := 0;
+   15    counter := 2
+   16  END DLib.
 
 
     0 errors
     0 errors
 
 

+ 0 - 0
tests/d_libimpl.mod → tests/d_lib.mod


+ 9 - 7
tests/d_lib2.LST

@@ -1,12 +1,14 @@
 Listing:
 Listing:
 
 
-    1  DEFINITION MODULE DLib2;
-    2  FROM DLib IMPORT step;
-    3  CONST dbl = 10;
-    4  VAR flag : INTEGER;
-    5  TYPE SArr = ARRAY [0 .. step] OF INTEGER;
-    6  PROCEDURE Bump(VAR v : INTEGER);
-    7  END DLib2.
+    1  IMPLEMENTATION MODULE DLib2;
+    2  FROM DLib IMPORT counter;
+    3  PROCEDURE Bump(VAR v : INTEGER);
+    4  BEGIN
+    5    v := v + dbl + counter
+    6  END Bump;
+    7  BEGIN
+    8    flag := 0
+    9  END DLib2.
 
 
     0 errors
     0 errors
 
 

+ 0 - 0
tests/d_lib2impl.mod → tests/d_lib2.mod


+ 0 - 15
tests/d_lib2impl.LST

@@ -1,15 +0,0 @@
-Listing:
-
-    1  IMPLEMENTATION MODULE DLib2;
-    2  FROM DLib IMPORT counter;
-    3  PROCEDURE Bump(VAR v : INTEGER);
-    4  BEGIN
-    5    v := v + dbl + counter
-    6  END Bump;
-    7  BEGIN
-    8    flag := 0
-    9  END DLib2.
-
-    0 errors
-
-

+ 0 - 22
tests/d_libimpl.LST

@@ -1,22 +0,0 @@
-Listing:
-
-    1  IMPLEMENTATION MODULE DLib;
-    2  VAR total : INTEGER;
-    3  PROCEDURE Add(n : INTEGER);
-    4  BEGIN
-    5    total := total + n;
-    6    counter := counter + n
-    7  END Add;
-    8  PROCEDURE Get() : INTEGER;
-    9  BEGIN
-   10    RETURN total + counter + step
-   11  END Get;
-   12  BEGIN
-   13    (* preset proves the init body runs: zeroed globals would read 0 *)
-   14    total := 0;
-   15    counter := 2
-   16  END DLib.
-
-    0 errors
-
-

+ 18 - 0
tests/s5lib.LST

@@ -0,0 +1,18 @@
+Listing:
+
+    1  IMPLEMENTATION MODULE S5Lib;
+    2  PROCEDURE Add(n : INTEGER);
+    3  BEGIN
+    4    total := total + n
+    5  END Add;
+    6  PROCEDURE Get() : INTEGER;
+    7  BEGIN
+    8    RETURN total + unit
+    9  END Get;
+   10  BEGIN
+   11    total := 3
+   12  END S5Lib.
+
+    0 errors
+
+

+ 8 - 0
tests/s5lib.def

@@ -0,0 +1,8 @@
+DEFINITION MODULE S5Lib;
+(* Step-5 showcase library: every interface kind in one place. *)
+CONST unit = 7;
+VAR total : INTEGER;
+TYPE Pair = RECORD a, b : INTEGER END;
+PROCEDURE Add(n : INTEGER);
+PROCEDURE Get() : INTEGER;
+END S5Lib.

+ 12 - 0
tests/s5lib.mod

@@ -0,0 +1,12 @@
+IMPLEMENTATION MODULE S5Lib;
+PROCEDURE Add(n : INTEGER);
+BEGIN
+  total := total + n
+END Add;
+PROCEDURE Get() : INTEGER;
+BEGIN
+  RETURN total + unit
+END Get;
+BEGIN
+  total := 3
+END S5Lib.

+ 21 - 0
tests/showcase5.LST

@@ -0,0 +1,21 @@
+Listing:
+
+    1  MODULE Showcase5;
+    2  (* Step-5 tour: FROM-imported var/proc/type, qualified var/call/const,
+    3     exported record type, implementation init body. ExitCode = 46:
+    4     init total=3; Add(10) -> 13; total=13+1+2=16;
+    5     Get()=16+7=23; ExitCode=16+23+7=46. *)
+    6  FROM S5Lib IMPORT total, Add, Pair;
+    7  IMPORT S5Lib;
+    8  VAR ExitCode : INTEGER;
+    9      p : Pair;
+   10  BEGIN
+   11    Add(10);
+   12    p.a := 1; p.b := 2;
+   13    total := total + p.a + p.b;
+   14    ExitCode := total + S5Lib.Get() + S5Lib.unit
+   15  END Showcase5.
+
+    0 errors
+
+

+ 15 - 0
tests/showcase5.mod

@@ -0,0 +1,15 @@
+MODULE Showcase5;
+(* Step-5 tour: FROM-imported var/proc/type, qualified var/call/const,
+   exported record type, implementation init body. ExitCode = 46:
+   init total=3; Add(10) -> 13; total=13+1+2=16;
+   Get()=16+7=23; ExitCode=16+23+7=46. *)
+FROM S5Lib IMPORT total, Add, Pair;
+IMPORT S5Lib;
+VAR ExitCode : INTEGER;
+    p : Pair;
+BEGIN
+  Add(10);
+  p.a := 1; p.b := 2;
+  total := total + p.a + p.b;
+  ExitCode := total + S5Lib.Get() + S5Lib.unit
+END Showcase5.