hs-java-0.4.1: Java .class files assembler/disassembler

Safe HaskellNone
LanguageHaskell98

JVM.Builder.Monad

Contents

Description

This module defines Generate[IO] monad, which helps generating JVM code and creating Java class constants pool.

Code generation could be done using one of two monads: Generate and GenerateIO. Generate monad is pure (simply State monad), while GenerateIO is IO-related. In GenerateIO additional actions are available, such as setting up ClassPath and loading classes (from .class files or JAR archives).

Synopsis

Documentation

data GState Source #

Generator state

Constructors

GState 

Fields

Instances
Eq GState Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

(==) :: GState -> GState -> Bool #

(/=) :: GState -> GState -> Bool #

Show GState Source # 
Instance details

Defined in JVM.Builder.Monad

MonadState GState (GenerateIO e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

get :: GenerateIO e GState #

put :: GState -> GenerateIO e () #

state :: (GState -> (a, GState)) -> GenerateIO e a #

MonadState GState (Generate e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

get :: Generate e GState #

put :: GState -> Generate e () #

state :: (GState -> (a, GState)) -> Generate e a #

MonadIO (EMT e (StateT GState IO)) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

liftIO :: IO a -> EMT e (StateT GState IO) a #

emptyGState :: GState Source #

Empty generator state

class Monad m => GeneratorMonad m where Source #

Instances
(Monad m, MonadState GState m) => GeneratorMonad m Source # 
Instance details

Defined in JVM.Builder.Monad

class (Monad (g e), GeneratorMonad (g e)) => Generator e g where Source #

Methods

throwG :: (Exception x, Throws x e) => x -> g e a Source #

Instances
MonadState GState (EMT e (State GState)) => Generator e Generate Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

throwG :: (Exception x, Throws x e) => x -> Generate e a Source #

Generator e GenerateIO Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

throwG :: (Exception x, Throws x e) => x -> GenerateIO e a Source #

newtype Generate e a Source #

Generate monad

Constructors

Generate 

Fields

Instances
MonadState GState (EMT e (State GState)) => Generator e Generate Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

throwG :: (Exception x, Throws x e) => x -> Generate e a Source #

MonadState GState (Generate e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

get :: Generate e GState #

put :: GState -> Generate e () #

state :: (GState -> (a, GState)) -> Generate e a #

Monad (Generate e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

(>>=) :: Generate e a -> (a -> Generate e b) -> Generate e b #

(>>) :: Generate e a -> Generate e b -> Generate e b #

return :: a -> Generate e a #

fail :: String -> Generate e a #

Functor (Generate e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

fmap :: (a -> b) -> Generate e a -> Generate e b #

(<$) :: a -> Generate e b -> Generate e a #

Applicative (Generate e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

pure :: a -> Generate e a #

(<*>) :: Generate e (a -> b) -> Generate e a -> Generate e b #

liftA2 :: (a -> b -> c) -> Generate e a -> Generate e b -> Generate e c #

(*>) :: Generate e a -> Generate e b -> Generate e b #

(<*) :: Generate e a -> Generate e b -> Generate e a #

newtype GenerateIO e a Source #

IO version of Generate monad

Constructors

GenerateIO 

Fields

Instances
Generator e GenerateIO Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

throwG :: (Exception x, Throws x e) => x -> GenerateIO e a Source #

MonadState GState (GenerateIO e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

get :: GenerateIO e GState #

put :: GState -> GenerateIO e () #

state :: (GState -> (a, GState)) -> GenerateIO e a #

Monad (GenerateIO e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

(>>=) :: GenerateIO e a -> (a -> GenerateIO e b) -> GenerateIO e b #

(>>) :: GenerateIO e a -> GenerateIO e b -> GenerateIO e b #

return :: a -> GenerateIO e a #

fail :: String -> GenerateIO e a #

Functor (GenerateIO e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

fmap :: (a -> b) -> GenerateIO e a -> GenerateIO e b #

(<$) :: a -> GenerateIO e b -> GenerateIO e a #

Applicative (GenerateIO e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

pure :: a -> GenerateIO e a #

(<*>) :: GenerateIO e (a -> b) -> GenerateIO e a -> GenerateIO e b #

liftA2 :: (a -> b -> c) -> GenerateIO e a -> GenerateIO e b -> GenerateIO e c #

(*>) :: GenerateIO e a -> GenerateIO e b -> GenerateIO e b #

(<*) :: GenerateIO e a -> GenerateIO e b -> GenerateIO e a #

MonadIO (GenerateIO e) Source # 
Instance details

Defined in JVM.Builder.Monad

Methods

liftIO :: IO a -> GenerateIO e a #

addToPool :: Generator e g => Constant Direct -> g e Word16 Source #

Add a constant into pool

i0 :: Generator e g => Instruction -> g e () Source #

Generate one (zero-arguments) instruction

i1 :: Generator e g => (Word16 -> Instruction) -> Constant Direct -> g e () Source #

Generate one one-argument instruction

i8 :: Generator e g => (Word8 -> Instruction) -> Constant Direct -> g e () Source #

Generate one one-argument instruction

newMethod Source #

Arguments

:: (Generator e g, Throws UnexpectedEndMethod e) 
=> [AccessFlag]

Access flags for method (public, static etc)

-> ByteString

Method name

-> [ArgumentSignature]

Signatures of method arguments

-> ReturnSignature

Method return signature

-> g e ()

Generator for method code

-> g e (NameType (Method Direct)) 

Generate new method

setStackSize :: Generator e g => Word16 -> g e () Source #

Set maximum stack size for current method

setMaxLocals :: Generator e g => Word16 -> g e () Source #

Set maximum number of local variables for current method

withClassPath :: ClassPath () -> GenerateIO e () Source #

Update ClassPath

getClassField :: (Throws ENotFound e, Throws ENotLoaded e) => String -> ByteString -> GenerateIO e (NameType (Field Direct)) Source #

Get class field signature from current ClassPath

getClassMethod :: (Throws ENotFound e, Throws ENotLoaded e) => String -> ByteString -> GenerateIO e (NameType (Method Direct)) Source #

Get class method signature from current ClassPath

Orphan instances

MonadState st (EMT e (State st)) Source # 
Instance details

Methods

get :: EMT e (State st) st #

put :: st -> EMT e (State st) () #

state :: (st -> (a, st)) -> EMT e (State st) a #

MonadState st (EMT e (StateT st IO)) Source # 
Instance details

Methods

get :: EMT e (StateT st IO) st #

put :: st -> EMT e (StateT st IO) () #

state :: (st -> (a, st)) -> EMT e (StateT st IO) a #