From 31a3e0652a1251f251eed7a4b66e66a8b2fcc288 Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Tue, 3 Sep 2024 13:22:53 +0100 Subject: [PATCH 1/4] some helpers for working with constant expression evaluator --- CHANGELOG.md | 4 ++++ fortran-src.cabal | 2 +- src/Language/Fortran/Repr/Value/Machine.hs | 14 ++++++++++++++ src/Language/Fortran/Repr/Value/Scalar/Machine.hs | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20e431db..8d1164b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.16.0 (2024) + * Added `--show-make-list` option + * Some robustness improvements around mod files + ### 0.15.1 (Jun 22, 2023) * remove unused vector-sized dependency diff --git a/fortran-src.cabal b/fortran-src.cabal index 647e8d44..0dcfb6dc 100644 --- a/fortran-src.cabal +++ b/fortran-src.cabal @@ -1,6 +1,6 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.2. +-- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack diff --git a/src/Language/Fortran/Repr/Value/Machine.hs b/src/Language/Fortran/Repr/Value/Machine.hs index f885c4cb..ac1c13b8 100644 --- a/src/Language/Fortran/Repr/Value/Machine.hs +++ b/src/Language/Fortran/Repr/Value/Machine.hs @@ -2,6 +2,8 @@ module Language.Fortran.Repr.Value.Machine where +import Language.Fortran.Repr.Value.Scalar.Real +import Language.Fortran.Repr.Value.Scalar.Int.Machine import Language.Fortran.Repr.Value.Scalar.Machine import Language.Fortran.Repr.Type @@ -18,3 +20,15 @@ data FValue = MkFScalarValue FScalarValue fValueType :: FValue -> FType fValueType = \case MkFScalarValue a -> MkFScalarType $ fScalarValueType a + +fromConstInt :: FValue -> Maybe Integer +fromConstInt (MkFScalarValue (FSVInt a)) = Just $ withFInt a +fromConstInt _ = Nothing + +fromConstReal :: FValue -> Maybe Double +-- convert Float to Double +fromConstReal (MkFScalarValue (FSVReal (FReal4 a))) = Just $ floatToDouble a + where + floatToDouble :: Float -> Double + floatToDouble = realToFrac +fromConstReal (MkFScalarValue (FSVReal (FReal8 a))) = Just $ a diff --git a/src/Language/Fortran/Repr/Value/Scalar/Machine.hs b/src/Language/Fortran/Repr/Value/Scalar/Machine.hs index 2a0a0e4a..33f58cb5 100644 --- a/src/Language/Fortran/Repr/Value/Scalar/Machine.hs +++ b/src/Language/Fortran/Repr/Value/Scalar/Machine.hs @@ -55,4 +55,4 @@ fScalarValueType = \case FSVReal a -> FSTReal $ fKind a FSVComplex a -> FSTComplex $ fKind a FSVLogical a -> FSTLogical $ fKind a - FSVString a -> FSTString $ fromIntegral $ Text.length a + FSVString a -> FSTString $ fromIntegral $ Text.length a \ No newline at end of file From 2240b9d478abb2532a0fd8dbdbbaa95568754c71 Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Tue, 3 Sep 2024 13:25:19 +0100 Subject: [PATCH 2/4] remoev comment --- src/Language/Fortran/Repr/Value/Machine.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Language/Fortran/Repr/Value/Machine.hs b/src/Language/Fortran/Repr/Value/Machine.hs index ac1c13b8..27bd188b 100644 --- a/src/Language/Fortran/Repr/Value/Machine.hs +++ b/src/Language/Fortran/Repr/Value/Machine.hs @@ -26,7 +26,6 @@ fromConstInt (MkFScalarValue (FSVInt a)) = Just $ withFInt a fromConstInt _ = Nothing fromConstReal :: FValue -> Maybe Double --- convert Float to Double fromConstReal (MkFScalarValue (FSVReal (FReal4 a))) = Just $ floatToDouble a where floatToDouble :: Float -> Double From 5bd841fa5b2ca26925092e4f79f7f897c9f5b7c7 Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Wed, 4 Sep 2024 18:20:24 +0200 Subject: [PATCH 3/4] add missing fall through case --- src/Language/Fortran/Repr/Value/Machine.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Language/Fortran/Repr/Value/Machine.hs b/src/Language/Fortran/Repr/Value/Machine.hs index 27bd188b..0829ce44 100644 --- a/src/Language/Fortran/Repr/Value/Machine.hs +++ b/src/Language/Fortran/Repr/Value/Machine.hs @@ -31,3 +31,4 @@ fromConstReal (MkFScalarValue (FSVReal (FReal4 a))) = Just $ floatToDouble a floatToDouble :: Float -> Double floatToDouble = realToFrac fromConstReal (MkFScalarValue (FSVReal (FReal8 a))) = Just $ a +fromConstReal _ = Nothing \ No newline at end of file From 3322bd5e3b796d69fe8c526dab2463f7a99ecb2f Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Tue, 3 Sep 2024 14:46:32 +0100 Subject: [PATCH 4/4] more robust test --- test/Language/Fortran/Analysis/ModGraphSpec.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/Language/Fortran/Analysis/ModGraphSpec.hs b/test/Language/Fortran/Analysis/ModGraphSpec.hs index dd2528db..bb6169ff 100644 --- a/test/Language/Fortran/Analysis/ModGraphSpec.hs +++ b/test/Language/Fortran/Analysis/ModGraphSpec.hs @@ -21,6 +21,10 @@ testDependencyList = do paths' <- expandDirs ["test-data" "module"] mg <- genModGraph (Just Fortran90) ["."] Nothing paths' let list = modGraphToList mg - let files = ["leaf.f90", "mid1.f90", "mid2.f90", "top.f90"] - let filesWithPaths = map (("test-data" "module") ) files - list `shouldBe` filesWithPaths + -- we should have two possible orderings + let files1 = ["leaf.f90", "mid1.f90", "mid2.f90", "top.f90"] + let filesWithPaths1 = map (("test-data" "module") ) files1 + -- or in a different order + let files2 = ["leaf.f90", "mid2.f90", "mid1.f90", "top.f90"] + let filesWithPaths2 = map (("test-data" "module") ) files2 + shouldSatisfy list (\x -> x == filesWithPaths1 || x == filesWithPaths2)