BEAM documentation (was Re: Packages in Erlang...)

Erik Stenman <>
Thu Sep 11 11:50:53 CEST 2003


Luke Gorrie wrote:
> "Erik Stenman" <> writes:
> 
> > I would suggest using the Icode language in the HiPE 
> > compiler, It is a very simple language with really only 
> > 15 different instructions. And 
> > there is already a compiler from Erlang or BEAM to Icode. (An 
> > Erlang->Core Erlang->Icode compiler is on its way.)
> 
> Do you implement e.g. the bit syntax in Icode, or is that 
> done in the runtime system? And will those 15 ops be enough 
> or do you fear Icode feature-creep?

Yes and no. Icode is really just a control flow language.
All interesting operations are performed by the call 
instruction. 

In this sense the bit syntax is not implemented in Icode.

The call instruction can call 'primops' these are implemented
by the runtime system (or compiler backend). The bit syntax is 
handled by calling primops specifically designed for this purpose.

In this way Icode is extensible, just add a new primop. 
The primop can be implemented by the virtual machine as an
extra instruction or as a C or Erlang function that can be called. 

Therefore the 15 ops should be enough and I do not fear feature-creep.
Icode has been enough for the HiPE compiler which handles all of
Erlang including bit syntax and inlined fp operations. 

Advantages of using Icode:
A working (bug free ;) compiler Erlang to Icode already exists.
A compiler Icode to x86 and SPARC exists. (With some changes
one can actually produce .S files that can be assembled and
linked into a runtime system. (linking of atoms in the code
has to be solved...) In this case the runtime system has to
be compatible with (read identical to) the current OTP system.)
Few instructions -- easy to implement a prototype VM.

Disadvantages of using Icode:
You have to understand some quirks in the language.
There are quite a few primops that have to be implemented somehow.
Icode only handles Erlang values (no real support for untagged 
values) this might be an advantage if you want to write a VM in
Erlang for educational purposes.

> One thing I find attractive about James's idea of using a 
> "mid-level" language as the target is that it makes it easy 
> to write things like the bit syntax: you take the bit-pattern 
> and generate straight forward code e.g. in terms of logand, 
> bitshift, etc. Then you let the mid-level-language compiler 
> worry about making _that_ fast.

Well, you can't really do that kind of low level stuff in Icode.
In that case I suggest using the HiPE RTL ;)
This is a Register Transfer Language suitable which the HiPE
compiler uses for implementing some primops and doing tagging
and untagging of Erlang values. RTL is a little bit bigger 
than Icode (27 instructions) but much more low-level.

 RTL instructions:
 move multimove alu load store load_address branch switch alub 
 call enter return gctest load_atom load_word_index goto_index 
 label restore_catch comment goto fail_to fload fstore fmov fp 
 fp_unop fconv

/Erik -- always ready to provide you with more information about 
         HiPE than you wanted.
-------------------------------------- 
I'm Happi, you should be happy.
Praeterea censeo "0xCA" scribere Erlang posse.




More information about the erlang-questions mailing list