| Safe Haskell | Safe |
|---|---|
| Language | Haskell98 |
Codec.Beam
Description
If this is your first exposure to BEAM, __I highly recommend Erik Stenman's book: https://happi.github.io/theBeamBook__, which discusses BEAM's architecture in much more detail.
Synopsis
- encode :: (Foldable f1, Foldable f2) => Text -> f1 Metadata -> f2 Op -> ByteString
- data Metadata
- export :: Text -> Int -> Metadata
- insertModuleInfo :: Metadata
- data Op
- newtype X = X Int
- newtype Y = Y Int
- newtype F = F Int
- data Nil = Nil
- newtype Label = Label Int
- data Literal
- data Lambda = Lambda {}
- data Import = Import {}
- data Register
- class IsRegister a where
- data Source
- class IsSource a where
- data RegisterF
- class IsRegisterF a where
- data SourceF
- class IsSourceF a where
- importBif0 :: Bif0 a => a -> Import
- importBif1 :: Bif1 a => a -> Import
- importBif2 :: Bif2 a => a -> Import
- importBif3 :: Bif3 a => a -> Import
- importBif4 :: Bif4 a => a -> Import
Documentation
Arguments
| :: (Foldable f1, Foldable f2) | |
| => Text | module name |
| -> f1 Metadata | |
| -> f2 Op | instructions |
| -> ByteString |
Create code for a BEAM module.
insertModuleInfo :: Metadata Source #
The Erlang compiler inserts two functions when compiling source files:
module_info/0 and module_info/1.
Some pieces of the Erlang toolchain expect this function to exist.
For instance, the shell will crash if you try to use TAB (for auto-completion)
on a BEAM module without these functions present.
These functions have the same implementation, so you can use this Metadata
to have the library generate and export them for you.
Syntax
A virtual machine instruction—the main unit this library deals with. There are a finite number of instructions, enumerated in Codec.Beam.Instructions. Each new release of Erlang/OTP might introduce a few more and deprecate old ones.
A stack register. These are used to pass function arguments, and X 0 stores return values.
Instances
| Eq X Source # | |
| Ord X Source # | |
| Show X Source # | |
| IsSourceF X Source # | |
| IsRegisterF X Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegisterF :: X -> RegisterF Source # | |
| IsSource X Source # | |
| IsRegister X Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegister :: X -> Register Source # | |
A stack register for saving values across function calls.
Anything you put in a X register can be overwritten inside a function call
(or inside a function call inside a function call).
Y registers let you avoid that—they must be allocated and de-allocated though.
Instances
| Eq Y Source # | |
| Ord Y Source # | |
| Show Y Source # | |
| IsSourceF Y Source # | |
| IsRegisterF Y Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegisterF :: Y -> RegisterF Source # | |
| IsSource Y Source # | |
| IsRegister Y Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegister :: Y -> Register Source # | |
Floating point "register" for optimized floating point arithmetic. These are not treated as traditional stack registers.
The empty list.
Constructors
| Nil |
Mark a spot in the code, so that you can jump to it with a function or condition.
Start with Label 1 and go up from there.
Erlang literals, stored on the heap.
Constructors
| Integer Int | |
| Float Double | |
| Atom Text | |
| Binary ByteString | |
| Tuple [Literal] | |
| List [Literal] | |
| Map [(Literal, Literal)] | |
| ExternalFun Import |
Turn a named function into a fun, for use with make_fun2.
Constructors
| Lambda | |
Fields
| |
Reference a function from another module.
For example, Import "array" "map" 2 refers to the stdlib function: array:map/2.
Constructors
| Import | |
Fields
| |
Argument constraints
Either type of stack register, X or Y.
Instructions that work with this type, use IsRegister for convenience.
Instances
| IsRegister Register Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegister :: Register -> Register Source # | |
class IsRegister a where Source #
Minimal complete definition
Methods
toRegister :: a -> Register Source #
Instances
| IsRegister Register Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegister :: Register -> Register Source # | |
| IsRegister Y Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegister :: Y -> Register Source # | |
| IsRegister X Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegister :: X -> Register Source # | |
class IsSource a where Source #
Minimal complete definition
Memory for manipulating F, for use with fmove.
Instructions that work with this type, use IsRegisterF for convenience.
Instances
| IsRegisterF RegisterF Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegisterF :: RegisterF -> RegisterF Source # | |
class IsRegisterF a where Source #
Minimal complete definition
Methods
toRegisterF :: a -> RegisterF Source #
Instances
| IsRegisterF RegisterF Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegisterF :: RegisterF -> RegisterF Source # | |
| IsRegisterF F Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegisterF :: F -> RegisterF Source # | |
| IsRegisterF Y Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegisterF :: Y -> RegisterF Source # | |
| IsRegisterF X Source # | |
Defined in Codec.Beam.Internal.Syntax Methods toRegisterF :: X -> RegisterF Source # | |
class IsSourceF a where Source #
Minimal complete definition
BIF helpers
importBif0 :: Bif0 a => a -> Import Source #
Convert BIF to a normal import with zero arguments,
which can be used with call and friends.
importBif1 :: Bif1 a => a -> Import Source #
Convert BIF to a normal import with one argument.
importBif2 :: Bif2 a => a -> Import Source #
Convert BIF to a normal import with two arguments.
importBif3 :: Bif3 a => a -> Import Source #
Convert BIF to a normal import with three arguments.
importBif4 :: Bif4 a => a -> Import Source #
Convert BIF to a normal import with four arguments.