Skip to content

Instantly share code, notes, and snippets.

@RyanGlScott
Created July 5, 2024 19:44
Show Gist options
  • Save RyanGlScott/094af8c083e39a4f0502851f92861700 to your computer and use it in GitHub Desktop.
Save RyanGlScott/094af8c083e39a4f0502851f92861700 to your computer and use it in GitHub Desktop.
A Copilot specification involving an update to a struct containing arrays
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main (main) where
import Language.Copilot
import Copilot.Compile.C99
data SoA = SoA
{ arr :: Field "arr" (Array 2 Word32)
}
instance Struct SoA where
typeName _ = "soa"
toValues soa = [Value typeOf (arr soa)]
instance Typed SoA where
typeOf = Struct $ SoA $ Field undefined
spec :: Spec
spec = do
let soa :: Stream SoA
soa = constant $ SoA $ Field $ array [0, 0]
trigger
"arrays"
((((soa #! arr) (constant (array [1, 2])) # arr) .!! 0) ==
(((soa #! arr) (constant (array [2, 1])) # arr) .!! 1))
[arg soa]
main :: IO ()
main = do
spec' <- reify spec
compile "structs_of_arrays" spec'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment