ソースを参照

v3 step 1.11 — showcase4 scalar tour (44) + showcase5 class frontier (35/35 green)

Eric Streit 3 週間 前
親
コミット
1505ca8eef
3 ファイル変更、60 行追加、0 行削除
  1. 2 0
      compiler/run_tests.sh
  2. 27 0
      compiler/tests/showcase4.mod
  3. 31 0
      compiler/tests/showcase5.mod

+ 2 - 0
compiler/run_tests.sh

@@ -64,6 +64,8 @@ expect_fail t_classdef.mod "not supported yet"
 expect_fail t_class.mod "not supported yet"
 expect_fail t_class.mod "not supported yet"
 expect_fail t_bad_parent.mod "undeclared identifier"
 expect_fail t_bad_parent.mod "undeclared identifier"
 expect_run showcase3.mod 183
 expect_run showcase3.mod 183
+expect_run showcase4.mod 44
+expect_fail showcase5.mod "not supported yet"
 expect_fail t_enumdecl.mod "not supported yet"
 expect_fail t_enumdecl.mod "not supported yet"
 expect_fail t_proc.mod "not supported yet"
 expect_fail t_proc.mod "not supported yet"
 expect_fail t_forward.mod "not supported yet"
 expect_fail t_forward.mod "not supported yet"

+ 27 - 0
compiler/tests/showcase4.mod

@@ -0,0 +1,27 @@
+MODULE Showcase4;
+// Scalar-complete tour (steps 1.9-2): WHILE sum, int->real,
+// real arith/comparisons, FOR, CASE with range, BOOLEAN gate.
+// Expected ExitCode: 44 (hand-computed).
+CONST Pi = 3.14;
+CONST Half = 0.5;
+VAR ExitCode, i, n : INTEGER;
+VAR r, s : REAL;
+VAR b : BOOLEAN;
+BEGIN
+  (* 1+..+7 = 28 *)
+  n := 0; i := 1;
+  WHILE i <= 7 DO n := n + i; i := i + 1 END;
+  r := n;
+  (* 28/4 + 0.5 = 7.5 *)
+  s := r / 4.0 + Half;
+  b := (s > 7.0) AND (Pi > 3.0);
+  (* 28 + 1 + 2 + 3 = 34 *)
+  FOR i := 1 TO 3 DO n := n + i END;
+  (* 34 MOD 4 = 2 -> +10 = 44 *)
+  CASE n MOD 4 OF
+    0 : n := n + 100
+  | 1..2 : n := n + 10
+  ELSE n := n + 1
+  END;
+  IF b THEN ExitCode := n ELSE ExitCode := 0 END
+END Showcase4.

+ 31 - 0
compiler/tests/showcase5.mod

@@ -0,0 +1,31 @@
+MODULE Showcase5;
+// Class-syntax frontier tour (docs/OOP.txt): fields, '=' consts,
+// VIRTUAL, methods with/without formals/results, single + multiple
+// inheritance, impl block with nested procedure in a method body,
+// init bodies. 7 errors, all "not supported yet".
+CONST Limit = 100;
+TYPE
+  CLASS Shape;
+    x, y : INTEGER;
+    Max = Limit;
+    VIRTUAL PROCEDURE Draw;
+    PROCEDURE Move(dx, dy : INTEGER);
+    PROCEDURE Area() : INTEGER;
+  END Shape;
+  CLASS Circle (Shape);
+    r : INTEGER;
+    PROCEDURE SetR(v : INTEGER);
+  END Circle;
+  CLASS Multi (Shape, Circle);
+  END Multi;
+CLASS IMPLEMENTATION Circle;
+  PROCEDURE SetR(v : INTEGER);
+    PROCEDURE Helper() : INTEGER;
+    BEGIN
+    END Helper;
+  BEGIN
+  END SetR;
+BEGIN
+END Circle;
+BEGIN
+END Showcase5.