h2jvm
Safe HaskellNone
LanguageGHC2021

H2JVM.Builder.Code

Description

A monadic builder for JVM bytecode instructions.

Synopsis

Documentation

data CodeBuilder (m :: k) a Source #

The CodeBuilder effect, which allows emitting instructions and adding code attributes in a monadic style.

Instances

Instances details
type DispatchOf (CodeBuilder :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in H2JVM.Builder.Code

type DispatchOf (CodeBuilder :: (Type -> Type) -> Type -> Type) = 'Dynamic

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.

runCodeBuilder Source #

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.

newLabel :: forall {k} (es :: [Effect]). (HasCallStack, (CodeBuilder :: (Type -> Type) -> Type -> Type) :> es) => Eff es Label Source #

Create a new, unique Label.