Safe Haskell | Safe |
---|---|
Language | Haskell98 |
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.
- 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
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.
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.
Floating point "register" for optimized floating point arithmetic. These are not treated as traditional stack registers.
The empty list.
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.
Turn a named function into a fun
, for use with make_fun2
.
Lambda | |
|
Reference a function from another module.
For example, Import "array" "map" 2
refers to the stdlib function: array:map/2
.
Import | |
|
Argument constraints
Either type of stack register, X
or Y
.
Instructions that work with this type, use IsRegister
for convenience.
class IsRegister a where Source #
toRegister :: a -> Register Source #
Memory for manipulating F
, for use with fmove
.
Instructions that work with this type, use IsRegisterF
for convenience.
class IsRegisterF a where Source #
toRegisterF :: a -> RegisterF Source #
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.