Преглед на файлове

v3 step 1.6 — showcase1 tour of the integer pipeline (10/10 tests green)

Eric Streit преди 3 седмици
родител
ревизия
3cbff1e7c0
променени са 2 файла, в които са добавени 28 реда и са изтрити 0 реда
  1. 1 0
      compiler/run_tests.sh
  2. 27 0
      compiler/tests/showcase1.mod

+ 1 - 0
compiler/run_tests.sh

@@ -49,6 +49,7 @@ mkdir -p gen_ssa
 expect_run t_minimal.mod 0
 expect_run t_exit.mod 7
 expect_run t_arith.mod 25
+expect_run showcase1.mod 50
 expect_fail t_bad_undecl.mod "undeclared identifier"
 expect_fail t_bad_dup.mod "duplicate identifier"
 expect_fail t_bad_mismatch.mod "module name mismatch"

+ 27 - 0
compiler/tests/showcase1.mod

@@ -0,0 +1,27 @@
+MODULE Showcase1;
+// Tour of the V3 step-1 integer pipeline: modern tokens (0x hex,
+// // comments), both IMPORT forms, folded CONSTs, every operator,
+// precedence, parens, unary minus on literals and variables.
+// Expected ExitCode: 50 (hand-computed, truncating DIV).
+IMPORT Dummy;
+FROM Elsewhere IMPORT Thing;
+
+CONST
+  Ten = 10;
+  NegThree = -3;
+  Mask = 0xFF;  (* 255 *)
+  Big = 0x10;   (* 16 *)
+
+VAR
+  ExitCode, tmp, acc : INTEGER;
+
+BEGIN
+  (* (10 + 255) * 2 - 100 DIV 7 + (-3) = 530 - 14 - 3 = 513 *)
+  tmp := (Ten + Mask) * 2 - 100 DIV 7 + NegThree;
+  (* 513 MOD 100 - (-3) + 2 = 13 + 3 + 2 = 18 *)
+  acc := tmp MOD 100 - NegThree + 2;
+  (* 18 * 3 - (513 - 18) DIV 100 + 16 - 16 + (-513) + 513
+     = 54 - 4 + 0 + 0 = 50; unary minus needs parens after
+     a binary operator, per Wirth simpleExpr *)
+  ExitCode := acc * 3 - (tmp - acc) DIV 100 + Big - Big + (-tmp) + tmp
+END Showcase1.