summaryrefslogtreecommitdiff
path: root/testsuite/tests/codeGen/should_run/setByteArray.hs
blob: c9a1012ccdbd1f277b46157d2bf42f4aecfb917a (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
{-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-}
{-# OPTIONS_GHC -Wall #-}

module Main ( main ) where

import GHC.Base

data BA = BA ByteArray#

-- Checks that setByteArray# works
main :: IO ()
main = do BA ba <- IO $ \s0 ->
                        case newByteArray# 8# s0 of
                        (# !s1, !mba #) ->
                            case setByteArray# mba 0# 8# 65# s1 of -- ASCII 'A'
                            !s2 ->
                                case setByteArray# mba 1# 6# 67# s2 of -- ASCII 'B'
                                !s3 ->
                                    -- N.B. 0-length should be a no-op
                                    case setByteArray# mba 2# 0# 68# s3 of -- ASCII 'C'
                                    !s4 ->
                                        case unsafeFreezeByteArray# mba s4 of
                                        (# s5, ba #) -> (# s5, BA ba #)
          let f (I# i) = putStrLn [C# (indexCharArray# ba i)]
          mapM_ f [0..7]