summaryrefslogtreecommitdiff
path: root/testsuite/tests/codeGen/should_run/CgStaticPointers.hs
blob: 5576f431e8a146164b1dd9a509060db280d8d637 (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
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE StaticPointers     #-}

-- | A test to use symbols produced by the static form.
module Main(main) where

import Data.Typeable
import GHC.StaticPtr

main :: IO ()
main = do
  print $ lookupKey (static (id . id)) (1 :: Int)
  print $ lookupKey (static method :: StaticPtr (Char -> Int)) 'a'
  print $ deRefStaticPtr (static g)
  print $ deRefStaticPtr p0 'a'
  print $ deRefStaticPtr (static t_field) $ T 'b'

lookupKey :: StaticPtr a -> a
lookupKey p = case unsafeLookupStaticPtr (staticKey p) of
  Just p -> deRefStaticPtr p
  Nothing -> error $ "couldn't find " ++ show (staticPtrInfo p)

g :: String
g = "found"

p0 :: Typeable a => StaticPtr (a -> a)
p0 = static (\x -> x)

data T a = T { t_field :: a }
  deriving Typeable

class C1 a where
  method :: a -> Int

instance C1 Char where
  method = const 0