{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE Trustworthy #-}

-- | The Futhark Prelude Library embedded embedded as strings read
-- during compilation of the Futhark compiler.  The advantage is that
-- the prelude can be accessed without reading it from disk, thus
-- saving users from include path headaches.
module Language.Futhark.Prelude (prelude) where

import Data.FileEmbed
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Futhark.Util (toPOSIX)
import qualified System.FilePath.Posix as Posix

-- | Prelude embedded as 'T.Text' values, one for every file.
prelude :: [(Posix.FilePath, T.Text)]
prelude :: [(FilePath, Text)]
prelude = ((FilePath, ByteString) -> (FilePath, Text))
-> [(FilePath, ByteString)] -> [(FilePath, Text)]
forall a b. (a -> b) -> [a] -> [b]
map (FilePath, ByteString) -> (FilePath, Text)
fixup [(FilePath, ByteString)]
prelude_bs
  where
    prelude_bs :: [(FilePath, ByteString)]
prelude_bs = $(embedDir "prelude")
    fixup :: (FilePath, ByteString) -> (FilePath, Text)
fixup (FilePath
path, ByteString
s) = (FilePath
"/prelude" FilePath -> FilePath -> FilePath
Posix.</> FilePath -> FilePath
toPOSIX FilePath
path, ByteString -> Text
T.decodeUtf8 ByteString
s)