Forráskód Böngészése

language: fold SHORTREAL CONST conversions

Eric Streit 1 napja
szülő
commit
3c09b61c2b
3 módosított fájl, 28 hozzáadás és 3 törlés
  1. 1 0
      compiler/run_tests.sh
  2. 10 3
      compiler/src/M2.atg
  3. 17 0
      compiler/tests/t_f32const.mod

+ 1 - 0
compiler/run_tests.sh

@@ -173,6 +173,7 @@ expect_run t_f32.mod 42
 expect_run t_f32proc.mod 42
 expect_run t_f32field.mod 42
 expect_run t_f32conv.mod 42
+expect_run t_f32const.mod 42
 expect_run t_extern_alias.mod 42
 expect_run t_with.mod 114
 expect_run t_set.mod 131

+ 10 - 3
compiler/src/M2.atg

@@ -4014,9 +4014,16 @@ PRODUCTIONS
                                            astRes := astNode;
                                            t := ct2;
                                            QbeGen.CopyOp(q2, q);
-                                           IF isConvF AND QbeGen.IsImm(convQ)
-                                              AND OrdClass(convT) AND OrdClass(ct2) THEN
-                                             QbeGen.CopyOp(convQ, q)
+                                           IF isConvF AND QbeGen.IsImm(convQ) THEN
+                                             IF OrdClass(convT) AND OrdClass(ct2) THEN
+                                               QbeGen.CopyOp(convQ, q)
+                                             ELSIF SymTab.IsRealType(ct2) THEN
+                                               IF SymTab.IsIntFamily(convT) THEN
+                                                 QbeGen.NormReal(convQ, q)
+                                               ELSE
+                                                 QbeGen.CopyOp(convQ, q)
+                                               END
+                                             END
                                            END;
                                            sfx := FALSE; .)
         { ResultComp<t, q, sfx, astRes, mname, methCls, isM>

+ 17 - 0
compiler/tests/t_f32const.mod

@@ -0,0 +1,17 @@
+MODULE TF32Const;
+(* Compile-time SHORTREAL conversion in CONST declarations. *)
+CONST
+  sr = SHORTREAL(1.5);
+  si = SHORTREAL(1);
+VAR
+  ExitCode : INTEGER;
+  x, y : SHORTREAL;
+BEGIN
+  x := sr;
+  y := si;
+  IF (x = 1.5) AND (y = 1.0) THEN
+    ExitCode := 42
+  ELSE
+    ExitCode := 1
+  END
+END TF32Const.