[erlang-questions] Forget Erlang on the Java VM. More language on the Erlang VM are needed!
Fri Nov 30 10:14:57 CET 2007
"Robert Virding" <rvirding@REDACTED> writes:
> On 29/11/2007, James Hague <james.hague@REDACTED> wrote:
> The erlang VM is quite fantastic, but it is also quite restricted. There are
> many things it can NOT handle, for example destructive updates of objects.
> There are no instructions in the BEAM for doing that, at least there
> weren't. Björn?
There are no general destructive operations. Destructive operations would need a
write barrier in the GC, which it doesn't have.
There is a very limited destructive setelement instruction. It must be preceeded
by a call to the setelement/3 BIF (because of the lack of write barrier, it would
not be safe to use in other contexts). The compiler uses this instruction to
optimize record updates.
> This severely restricts which languages you can implement on
> it. For example you cannot do a complete Scheme as it has destructive
> operations. I am not thinking about set! which is easy as it only modifies
> the environment but functions like vector-set! and string-set! which
> actually destructively modifies the objects themselves.
> I think adding that type of operation to the BEAM could be quite difficult
> as the effects are quite profound.
Yes. Besides the lack of write barrier, message sending and storing into
ETS cannot cope with the cyclic data structures that are possible to create
using destructive updates. Same problem with term_to_binary/1.
> There are actually 4 different layers in the compiler to which you could
> - Erlang
> - Core Erlang
> - Kernel Erlang
> - BEAM code
> The kernel level is a low-level non BEAM specific layer which could be
> compiled to any register machine. It would probably work against a stack
> machine as well. It was a while since I worked on it so I can't remember ALL
> the details.
Don't use Kernel Erlang. It is an internal format that may change at any time, and
it is entirely undocumented.
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions