| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusTx.Plugin.Common
Synopsis
- data PluginCtx = PluginCtx {}
- installCorePlugin ∷ Name → [CommandLineOption] → [CoreToDo] → CoreM [CoreToDo]
- plinthcModName ∷ String
- anchorName ∷ String
- injectAnchors ∷ TcGblEnv → TcM TcGblEnv
- anchorExpr ∷ Id → LHsExpr GhcTc → LHsExpr GhcTc
- isAnchorWorthy ∷ Id → HsExpr GhcTc → Bool
- isTick ∷ HsExpr GhcTc → Bool
- isAnchorApp ∷ Id → HsExpr GhcTc → Bool
- mkSimplPass ∷ DynFlags → CoreToDo
- mkPluginPass ∷ Name → PluginOptions → CoreToDo
- type PluginM uni fun = ReaderT PluginCtx (ExceptT (CompileError uni fun Ann) CoreM)
- runPluginM ∷ ∀ uni fun a. (PrettyUni uni, Pretty fun) ⇒ PluginCtx → PluginM uni fun a → CoreM a
- getSourceSnippet ∷ RealSrcSpan → IO (Maybe (Doc ann))
- formatSourceSnippet ∷ Int → Int → Int → String → Doc ann
- compileBind ∷ CoreBind → PluginM DefaultUni DefaultFun CoreBind
- compileMarkedExprs ∷ CoreExpr → PluginM DefaultUni DefaultFun CoreExpr
- compileMarkedExprOrDefer ∷ String → Type → CoreExpr → PluginM DefaultUni DefaultFun CoreExpr
- emitRuntimeError ∷ (PrettyUni uni, Pretty fun) ⇒ Type → CompileError uni fun Ann → PluginM uni fun CoreExpr
- compileMarkedExpr ∷ String → Type → CoreExpr → PluginM DefaultUni DefaultFun CoreExpr
- runCompiler ∷ ∀ uni fun m. (uni ~ DefaultUni, fun ~ DefaultFun, MonadReader (CompileContext uni fun) m, MonadState CompileState m, MonadWriter CoverageIndex m, MonadQuote m, MonadError (CompileError uni fun Ann) m, MonadIO m) ⇒ String → PluginOptions → CoreExpr → m (PIRProgram uni fun, UPLCProgram uni fun)
- thNameToGhcNameOrFail ∷ Name → PluginM uni fun Name
- makeByteStringLiteral ∷ ByteString → PluginM uni fun CoreExpr
- stripTicks ∷ CoreExpr → CoreExpr
- stripAnchors ∷ Name → CoreExpr → CoreExpr
- mkCompiledCode ∷ ∀ a. ByteString → ByteString → ByteString → CompiledCode a
- makePrimitiveNameInfo ∷ [Name] → PluginM uni fun NameInfo
- makeRewriteRules ∷ PluginOptions → RewriteRules DefaultUni DefaultFun
Documentation
Constructors
| PluginCtx | |
installCorePlugin ∷ Name → [CommandLineOption] → [CoreToDo] → CoreM [CoreToDo] Source #
injectAnchors ∷ TcGblEnv → TcM TcGblEnv Source #
Wrap certain HsExprs in the typed checked module with anchor.
mkSimplPass ∷ DynFlags → CoreToDo Source #
A simplifier pass, implemented by GHC
mkPluginPass ∷ Name → PluginOptions → CoreToDo Source #
Our plugin works at haskell-module level granularity; the plugin looks at the module's top-level bindings for markers and compiles their right-hand-side core expressions.
type PluginM uni fun = ReaderT PluginCtx (ExceptT (CompileError uni fun Ann) CoreM) Source #
The monad where the plugin runs in for each module. It is a core->core compiler monad, called PluginM, augmented with pure errors.
runPluginM ∷ ∀ uni fun a. (PrettyUni uni, Pretty fun) ⇒ PluginCtx → PluginM uni fun a → CoreM a Source #
Runs the plugin monad in a given context; throws a Ghc.Exception when compilation fails.
getSourceSnippet ∷ RealSrcSpan → IO (Maybe (Doc ann)) Source #
compileBind ∷ CoreBind → PluginM DefaultUni DefaultFun CoreBind Source #
Compiles all the marked expressions in the given binder into PLC literals.
compileMarkedExprs ∷ CoreExpr → PluginM DefaultUni DefaultFun CoreExpr Source #
Compiles all the core-expressions surrounded by the marker in the given expression into PLC literals.
compileMarkedExprOrDefer ∷ String → Type → CoreExpr → PluginM DefaultUni DefaultFun CoreExpr Source #
Behaves the same as compileMarkedExpr, unless a compilation error occurs ;
if a compilation error happens and the 'defer-errors' option is turned on,
the compilation error is suppressed and the original hs expression is replaced with a
haskell runtime-error expression.
emitRuntimeError ∷ (PrettyUni uni, Pretty fun) ⇒ Type → CompileError uni fun Ann → PluginM uni fun CoreExpr Source #
Given an expected Haskell type a, it generates Haskell code which throws a GHC runtime error
"as" 'CompiledCode a'.
compileMarkedExpr ∷ String → Type → CoreExpr → PluginM DefaultUni DefaultFun CoreExpr Source #
Compile the core expression that is surrounded by a plc marker,
and return a core expression which evaluates to the compiled plc AST as a serialized bytestring,
to be injected back to the Haskell program.
runCompiler ∷ ∀ uni fun m. (uni ~ DefaultUni, fun ~ DefaultFun, MonadReader (CompileContext uni fun) m, MonadState CompileState m, MonadWriter CoverageIndex m, MonadQuote m, MonadError (CompileError uni fun Ann) m, MonadIO m) ⇒ String → PluginOptions → CoreExpr → m (PIRProgram uni fun, UPLCProgram uni fun) Source #
The GHC.Core to PIR to PLC compiler pipeline. Returns both the PIR and PLC output. It invokes the whole compiler chain: Core expr -> PIR expr -> PLC expr -> UPLC expr.
makeByteStringLiteral ∷ ByteString → PluginM uni fun CoreExpr Source #
Create a GHC Core expression that will evaluate to the given ByteString at runtime.
mkCompiledCode ∷ ∀ a. ByteString → ByteString → ByteString → CompiledCode a Source #
Helper to avoid doing too much construction of Core ourselves