<commit_before>{-# LANGUAGE CPP #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}

-- | Type rewriting for Feldspar programs
module Feldspar.Compiler.CallConv
  ( rewriteType
  , expandTF
  , buildHaskellType
  , buildCType
  )
  where


import Language.Haskell.TH
import Language.Haskell.TH.ExpandSyns (expandSyns)

import Foreign.Ptr (Ptr)

import Feldspar (Syntactic(..))
import Feldspar.Plugin.TypeRewrite
import Foreign.Marshal.Class (Reference(..), Marshal(..))

-- | Normalize the type (expand type synonyms and type families)
rewriteType :: Type -> Q Type
rewriteType t = rewriteSyntactic t >>= expandTF

rewriteSyntactic :: Type -> Q Type
rewriteSyntactic typ = expandSyns typ >>= go
  where
    go t@(AppT c@(ConT _) x) = do
      inst <- isInstance ''Syntactic [t]
      if inst
        then appT [t|Internal|] (return t)
        else appT (return c) (go x)
    go (AppT t1 t2) = appT (go t1) (go t2)
    go t = return t

haskellCC :: CallConv<commit_msg>Use quasiquote to make GHC 7.4 happy<commit_after>{-# LANGUAGE CPP #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}

-- | Type rewriting for Feldspar programs
module Feldspar.Compiler.CallConv
  ( rewriteType
  , expandTF
  , buildHaskellType
  , buildCType
  )
  where


import Language.Haskell.TH
import Language.Haskell.TH.ExpandSyns (expandSyns)

import Foreign.Ptr (Ptr)

import Feldspar (Syntactic(..))
import Feldspar.Plugin.TypeRewrite
import Foreign.Marshal.Class (Reference(..), Marshal(..))

-- | Normalize the type (expand type synonyms and type families)
rewriteType :: Type -> Q Type
rewriteType t = rewriteSyntactic t >>= expandTF

rewriteSyntactic :: Type -> Q Type
rewriteSyntactic typ = expandSyns typ >>= go
  where
    go t@(AppT c@(ConT _) x) = do
      inst <- isInstance ''Syntactic [t]
      if inst
        then [t| Internal $(return t) |]
        else [t| $(return c) $(go x)  |]
    go (AppT t1 t2) = appT (go t1) (go t2)
    go t = return t

haskellCC :: CallConv
{'fraction_non_alphanumeric': 0.12221144519883609, 'fraction_numerical': 0.004849660523763337, 'mean_word_length': 3.436559139784946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6519592', 'n_tokens_mistral': 778, 'n_tokens_neox': 735, 'n_words': 211}