{-# LANGUAGE DataKinds          #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts   #-}
{-# LANGUAGE KindSignatures     #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# OPTIONS_GHC -Wno-unused-foralls #-}
{-# OPTIONS_GHC -fomit-interface-pragmas #-}
module PlutusTx.Plugin.Utils where

import Data.Proxy
import GHC.TypeLits
import PlutusTx.Code
import PlutusTx.Utils

{- Note [plc and Proxy]
It would be nice to use TypeApplications instead of passing a Proxy to plc.
However, this means we need to create a type application in the TH-generated code which calls it.
As of recent versions of GHC, this causes an error in the module where the splice appears if it
doesn't have TypeApplications enabled.

Generally we want to avoid forcing users to enable language extensions, so we use
a Proxy to avoid this.
-}

-- This needs to be defined here so we can reference it in the TH functions.
-- If we inline this then we won't be able to find it later!
{-# OPAQUE plc #-}
-- | Marks the given expression for compilation to PLC.
plc :: forall (loc::Symbol) a . Proxy loc -> a -> CompiledCode a
-- this constructor is only really there to get rid of the unused warning
plc :: forall (loc :: Symbol) a. Proxy loc -> a -> CompiledCode a
plc Proxy loc
_ a
_ = ByteString
-> Maybe ByteString
-> CoverageIndex
-> CompiledCodeIn DefaultUni DefaultFun a
forall (uni :: * -> *) fun a.
ByteString
-> Maybe ByteString -> CoverageIndex -> CompiledCodeIn uni fun a
SerializedCode (String -> ByteString
forall a. String -> a
mustBeReplaced String
"plc") (String -> Maybe ByteString
forall a. String -> a
mustBeReplaced String
"pir") (String -> CoverageIndex
forall a. String -> a
mustBeReplaced String
"covidx")