[Nix-dev] Compiling Nix code

Ludovic Courtès ludo at gnu.org
Thu Feb 25 14:38:55 CET 2010


Hi,

Eelco Dolstra <e.dolstra at tudelft.nl>
writes:

> Or you compile to some byte-code representation
> where variables point to closures in the heap that are overwritten by their
> normal forms when entered.  I'm sort of leaning towards that approach (compile
> to Parrot or Guile or whatever).

Of course, I’m somewhat biased as to which solution you should choose
;-), but here’s how it could work with Guile:

  - There’d be a compiler front-end for the Nix language.  It would
    compile to the ‘Tree-IL’ language, which is roughly residual Scheme
    code after macro expansion [0].

  - The lexer and parser themselves can be translated from Flex/Bison to
    SILex [1] and ‘parse-lalr’ [2].

  - Since Tree-IL is call-by-value, parameters in a function call would
    need to wrapped in a R5RS ‘delay’ form or rather a SRFI-45 ‘lazy’
    form [2].  If need be, promises can be made more efficient by adding
    special VM support.

  - Guile bindings for Nix’ libstore, etc., would have to be implemented
    so that the compiled Nix code can use them.  (There’s a C API to
    libguile and a new “dynamic FFI”, which allows the implementation of
    bindings for C code without writing a single line of C.)

  - Attribute sets could be implemented on top of Bagwell’s vlist-based
    hash lists, a purely functional dictionary type [4].

As a bonus Nix programs would be able to use other Guile libraries.
Imagine yourself writing a multi-threaded, Unicode-capable, GTK+ or
networking app in Nix!  :-)

Thanks,
Ludo’.

[0] http://www.gnu.org/software/guile/docs/master/guile.html/Tree_002dIL.html
[1] http://www.iro.umontreal.ca/~dube/ (works for Guile.)
[2] http://code.google.com/p/lalr-scm/ (available in Guile.)
[3] http://srfi.schemers.org/srfi-45/srfi-45.html (not yet available in Guile.)
[4] http://hydra.nixos.org/build/278519/download/2/guile.html/VHashes.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20100225/71d28d74/attachment.bin 


More information about the nix-dev mailing list