Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some helpers for working with constant expression evaluator #285

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion fortran-src.cabal
Original file line number Diff line number Diff line change
@@ -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

Expand Down
14 changes: 14 additions & 0 deletions src/Language/Fortran/Repr/Value/Machine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
fromConstReal (MkFScalarValue (FSVReal (FReal4 a))) = Just $ floatToDouble a
where
floatToDouble :: Float -> Double
floatToDouble = realToFrac
fromConstReal (MkFScalarValue (FSVReal (FReal8 a))) = Just $ a
dorchard marked this conversation as resolved.
Show resolved Hide resolved
fromConstReal _ = Nothing
2 changes: 1 addition & 1 deletion src/Language/Fortran/Repr/Value/Scalar/Machine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions test/Language/Fortran/Analysis/ModGraphSpec.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Language.Fortran.Analysis.ModGraphSpec (spec) where

import Test.Hspec
import TestUtil

Check warning on line 4 in test/Language/Fortran/Analysis/ModGraphSpec.hs

View workflow job for this annotation

GitHub Actions / Ubuntu / GHC 9.4, Cabal / test

The import of ‘TestUtil’ is redundant

import Language.Fortran.Analysis.ModGraph
import Language.Fortran.Util.Files (expandDirs)
Expand All @@ -17,10 +17,14 @@
-- A simple test on a simple module structure to check that
-- we are understanding this correctly (via the dependency graph
-- and then its topological sort).
testDependencyList = do

Check warning on line 20 in test/Language/Fortran/Analysis/ModGraphSpec.hs

View workflow job for this annotation

GitHub Actions / Ubuntu / GHC 9.4, Cabal / test

Top-level binding with no type signature:
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)
Loading