ソースを参照

v3 step 1.8 — showcase2 tour of scalar TYPEs in action (16/16 tests green)

Eric Streit 3 週間 前
親
コミット
3f3624f555
2 ファイル変更、31 行追加、0 行削除
  1. 1 0
      compiler/run_tests.sh
  2. 30 0
      compiler/tests/showcase2.mod

+ 1 - 0
compiler/run_tests.sh

@@ -51,6 +51,7 @@ expect_run t_exit.mod 7
 expect_run t_arith.mod 25
 expect_run showcase1.mod 50
 expect_run t_types.mod 8
+expect_run showcase2.mod 71
 expect_fail t_enumdecl.mod "not supported yet"
 expect_fail t_proc.mod "not supported yet"
 expect_fail t_forward.mod "not supported yet"

+ 30 - 0
compiler/tests/showcase2.mod

@@ -0,0 +1,30 @@
+MODULE Showcase2;
+// Stage 1.7 tour: scalar TYPEs used for real work — subranges with
+// decimal and hex bounds, aliases, folded CONSTs, all operators.
+// Expected ExitCode: 71 (hand-computed, truncating DIV).
+IMPORT Dummy;
+FROM Elsewhere IMPORT Thing;
+
+CONST
+  Step = 7;
+  Bonus = -5;
+
+TYPE
+  Score = [0..100];
+  Nibble = [0x0..0xF];
+  Amount = INTEGER;
+
+VAR
+  ExitCode : INTEGER;
+  s : Score;
+  i : Nibble;
+  a : Amount;
+
+BEGIN
+  s := 90;
+  i := 0xB;  (* 11 *)
+  (* (90 + 11) * 7 DIV 10 + (-5) = 707 DIV 10 - 5 = 70 - 5 = 65 *)
+  a := (s + i) * Step DIV 10 + Bonus;
+  (* 65 + 90 MOD 7 = 65 + 6 = 71 *)
+  ExitCode := a + s MOD Step
+END Showcase2.