summaryrefslogtreecommitdiff
path: root/testsuite/tests/simplCore/T9646/Main.hs
blob: 352dd03266e41de85a706c9397b304a6cdaeffc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE CPP #-}

#include "MachDeps.h"

#if __GLASGOW_HASKELL__ < 709
import GHC.Types
#endif

import StrictPrim
import Type
import Natural


main :: IO ()
main = do
    let (a, b) = (1234, 2345)
        (na, nb) = (mkSingletonNat a, mkSingletonNat b)
        nc = timesNatural na nb

    print $ fromNatural na
    print $ fromNatural nb
    print $ fromNatural nc
    checkEtaCount


checkEtaCount :: IO ()
checkEtaCount = do
    text <- readFile "Natural.dump-simpl"
    let etaCount = length . filter (== "eta") $ words text
    if etaCount > 0
        then error $ "Error : Eta count (" ++ show etaCount ++ ") should 0."
        else putStrLn "Test passed!"


mkSingletonNat :: Word -> Natural
mkSingletonNat x = runStrictPrim mkNat
  where
    mkNat :: StrictPrim s Natural
    mkNat = do
        marr <- newWordArray 1
        writeWordArray marr 0 x
        narr <- unsafeFreezeWordArray marr
        return $ Natural 1 narr


fromNatural :: Natural -> Word
fromNatural (Natural _ arr) = indexWordArray arr 0