forked from rrnewton/haskell-lockfree
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a currently failing (not compiling) test case.
Using GHCi via TemplateHaskell bytecode interpretation with Data.Atomics. Related to rrnewton#10 . Note: hello-word-atomic-primops.hs missing.
- Loading branch information
1 parent
0169990
commit 93c0e2c
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{-# LANGUAGE TemplateHaskell, | ||
RankNTypes #-} | ||
|
||
-- | TH splices used in atommic-primops tests. | ||
-- Splices defined in own module for technical reasons. | ||
|
||
module TemplateHaskellSplices where | ||
|
||
import Language.Haskell.TH | ||
import Control.Monad (replicateM) | ||
|
||
tmap :: forall a. (Enum a, Eq a, Num a) | ||
=> a -> Int -> Q Exp | ||
tmap i n = do | ||
f <- newName "f" | ||
as <- replicateM n (newName "a") | ||
lamE [varP f, tupP (map varP as)] $ | ||
tupE [ if i == i' | ||
then [| $(varE f) $a |] | ||
else a | ||
| (a,i') <- map varE as `zip` [1..] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
-- | Test the invocation of the GHCi bytecode intepreter with atomic-primops. | ||
|
||
module Main where | ||
|
||
import Data.Atomics -- import needed to test whether ghci linking error occurs | ||
import TemplateHaskellSplices (tmap) | ||
import Test.Framework (defaultMain) | ||
import Test.Framework.Providers.HUnit (testCase) | ||
|
||
main :: IO () | ||
main = defaultMain | ||
[ | ||
---------------------------------------- | ||
testCase "Template_Haskell_invocation" $ do | ||
putStrLn "Attempting Template Haskell implementation of map operation" | ||
print $ $(tmap 3 4) (+ 1) (1,2,3,4) -- comment out for compilation to succeed | ||
---------------------------------------- | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters