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

Erik Stenman <>
Tue Sep 9 16:44:59 CEST 2003


I would suggest using the Icode language in the HiPE compiler,
It is a very simple language with realy 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.)

To write an interpreter for this language in Erlang or C should
be very easy.

A simple example:


-module(len).
-export([len/1]).

len([]) -> [];
len([_|R]) -> len(R).

----

bash> erlc +native +\{hipe,\[\{pp_icode,\{file,"len.icode"\}\}\]\}
bash> cat len.icode
len:len(v0) ->
%% Info:['Not a closure','Leaf function']
1:
    _ := redtest() (primop)
    goto 4
4:
    if is_cons(v0) then 3 (0.50) else 6
3:
    v5 := unsafe_hd(v0) (primop)
    v0 := unsafe_tl(v0) (primop)
    goto 1
6:
    if is_nil(v0) then 5 (0.50) else 2
5:
    v0 := 0
    return(v0)
2:
    v3 := function_clause
    fail(fault, [v3])
%% Data:
len:module_info() ->
%% Info:['Not a closure','Leaf function']
1:
    _ := redtest() (primop)
    goto 10
10:
    v0 := []
    return(v0)
%% Data:
len:module_info(v0) ->
%% Info:['Not a closure','Leaf function']
1:
    _ := redtest() (primop)
    goto 14
14:
    v0 := []
    return(v0)
%% Data:


---
I'll be glad to give anyone intrested in such a project more information
about Icode.

/Erik (Happi) Stenman


> -----Original Message-----
> From:  
> [mailto:] On Behalf Of Luke Gorrie
> Sent: den 9 september 2003 16:23
> To: James Hague
> Cc: 
> Subject: Re: BEAM documentation (was Re: Packages in Erlang...)
> 
> 
> "James Hague" <> writes:
> 
> > (One idea I've mused about is doing away with the C 
> implementation of
> > the BEAM emulator entirely, and writing the core in a custom mid-
> > level language implemented in Erlang.)
> 
> Have you considered using existing mid-level languages 
> instead? If so, are there any that seem particularly 
> qualified/disqualified?
> 
> Cheers,
> Luke
> 
> 




More information about the erlang-questions mailing list