| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
H2JVM.Builder.Code
Description
A monadic builder for JVM bytecode instructions.
Synopsis
- data CodeBuilder (m :: k) a
- emit :: forall (r :: [Effect]). (CodeBuilder :: (Type -> Type) -> Type -> Type) :> r => Instruction -> Eff r ()
- addCodeAttribute :: forall {k} (es :: [Effect]). (HasCallStack, (CodeBuilder :: (Type -> Type) -> Type -> Type) :> es) => CodeAttribute -> Eff es ()
- runCodeBuilder :: forall (r :: [(Type -> Type) -> Type -> Type]) a. HasCallStack => Eff ((CodeBuilder :: (Type -> Type) -> Type -> Type) ': r) a -> Eff r (a, [CodeAttribute], NonEmpty Instruction)
- newLabel :: forall {k} (es :: [Effect]). (HasCallStack, (CodeBuilder :: (Type -> Type) -> Type -> Type) :> es) => Eff es Label
Documentation
data CodeBuilder (m :: k) a Source #
The CodeBuilder effect, which allows emitting instructions and adding code attributes in a monadic style.
Instances
| type DispatchOf (CodeBuilder :: (Type -> Type) -> Type -> Type) Source # | |
Defined in H2JVM.Builder.Code | |
emit :: forall (r :: [Effect]). (CodeBuilder :: (Type -> Type) -> Type -> Type) :> r => Instruction -> Eff r () Source #
Emit a single instruction.
addCodeAttribute :: forall {k} (es :: [Effect]). (HasCallStack, (CodeBuilder :: (Type -> Type) -> Type -> Type) :> es) => CodeAttribute -> Eff es () Source #
Add a code attribute to the current code block. If an attribute of the same type already exists, it will be merged with the existing one using the merge function from the DataMergeable instance for that attribute type.
Arguments
| :: forall (r :: [(Type -> Type) -> Type -> Type]) a. HasCallStack | |
| => Eff ((CodeBuilder :: (Type -> Type) -> Type -> Type) ': r) a | |
| -> Eff r (a, [CodeAttribute], NonEmpty Instruction) | the result of the computation, the list of emitted code attributes, and the list of emitted instructions, in the order they were emitted. |
Run a CodeBuilder effect, returning the emitted code and attributes.
Throws an imprecise exception if no code was emitted, since a code block with no instructions is invalid.