[erlang-questions] Crazy Question: C -> Erlang Core

Alceste Scalas alceste@REDACTED
Thu Nov 13 14:51:19 CET 2008


Il giorno lun, 10/11/2008 alle 21.33 +0100, Robert Virding ha scritto:
> Yes, it would be possible [to compile C in Core Erlang] but there
> would be quite severe restrictions on the C you could write. Three
> main ones are:
> 
> - no destructive operations on data as all data is immutable in Erlang

You could simulate destructive operations by using fresh variables.  In
other words, you could convert your C code into SSA (Static Single
Assignment) form [1] and then compile it almost directly into Core
Erlang.

That's what we are doing for compiling a Matlab-like language into Core
Erlang.  See [2].


> - global data is tricky

...and very slow (you could simulate global variables using a server
process).


> - many of the basic C data structures don't map easily to Erlang

Furthermore, if you need something like pointer arithmetics, you will
need to simulate the memory as a global variable.  Not very fun...

Regards,

alceste

References:

  [1] Ron Cytron, Jeanne Ferrante, Barry K. Rosen, Mark N. Wegman,
        and F. Kenneth Zadeck.  Efficiently computing static single
        assignment form and the control dependence graph.  ACM
        Transactions on Programming Languages and Systems (TOPLAS),
        13(4):451-490, 1991.

  [2] Alceste Scalas, Giovanni Casu and Piero Pili.  High-performance
        Technical Computing with Erlang.  Presentation at the VII ACM
        SIGPLAN Erlang Workshop, Victoria, British Columbia, Canada,
        September 27, 2008.
        http://www.erlang.org/workshop/2008/Sess23.pdf

-- 
Alceste Scalas <alceste@REDACTED>
CRS4 - http://www.crs4.it/




More information about the erlang-questions mailing list