Erlang bytecodes and/or VM description?

Thomas Lindgren <>
Thu Jun 1 11:19:07 CEST 2006



--- Andrew Lentvorski <> wrote:

> Is there a concise reference of the Erlang
> bytescodes and/or VM 
> description somewhere?
> 
> It seems like I have to go back to about R7B to look
> at an emulator that 
> is clean (as opposed to having lots of HiPE stuff
> scattered inside).

It depends on what you want to do. There used to be a
BEAM bytecode reference, but I think the format and
instructions change mildly every now and then, both
with new releases and with different targets. 

For example, I believe some instruction sequences can
be merged into superinstructions by the loader, and/or
otherwise specialized or optimized. This can lead to
hundreds of nearly identical instruction variants, so
some patience and experience is needed to decipher
them.

If you just want to learn the high level BEAM
instruction set, then that is more straightforward. To
see what code compiles to, use "erlc +S mod.erl",
which emits a file "mod.S" with symbolic BEAM code in
it.

Historically, the BEAM instruction set has its root in
the elegant and subtle Warren Abstract Machine (for
Prolog). Bogdan Hausman, the original designer, has
his roots in the Prolog world, and started from a
simplification of the WAM instruction set. Here is one
of the original documents:

http://www.erlang.se/publications/Erlang_to_C.pdf

But basically it's not so hard: the VM is register
based, and there are two kinds of temporaries,
"registers" (x-regs) and "stack slots" (y-regs). There
are instructions to dispatch on register value or
type, to speed up clause selection. There are function
calls, including last calls (jumps with arguments).
There are instructions to take apart and put together
terms. And maybe a few more that I've forgotten about.

If you want to learn about the ancestral WAM, Hassan
Ait-Kaci wrote a good tutorial (MIT Press, 1991),
which can be found here:

http://archive.bibalex.org/web/*/http://www.isg.sfu.ca/~hak/documents/wambook.pdf

Best,
Thomas


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the erlang-questions mailing list