1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-20 11:11:03 -04:00
nix/src/eval.hh

123 lines
3.3 KiB
C++
Raw Normal View History

#ifndef __EVAL_H
#define __EVAL_H
extern "C" {
#include <aterm2.h>
}
#include "hash.hh"
using namespace std;
2003-06-27 05:55:31 -04:00
/* \section{Abstract syntax of Nix expressions}
An expression describes a (partial) state of the file system in a
referentially transparent way. The operational effect of
evaluating an expression is that the state described by the
expression is realised.
2003-06-27 05:55:31 -04:00
File : Path * Content * [Expr] -> Expr
File(path, content, refs) specifies a file object (its full path
and contents), along with all file objects referenced by it (that
is, that it has pointers to). We assume that all files are
self-referential. This prevents us from having to deal with
cycles.
2003-06-27 05:55:31 -04:00
Derive : String * Path * [Expr] * [Expr] * [Expr] -> Expr
2003-06-27 05:55:31 -04:00
Derive(platform, builder, ins, outs, env) specifies the creation of
new file objects (in paths declared by `outs') by the execution of
a program `builder' on a platform `platform'. This execution takes
place in a file system state given by `ins'. `env' specifies a
mapping of strings to strings.
Str : String -> Expr
A string constant.
Tup : Expr * Expr -> Expr
Tuples of expressions.
2003-06-27 05:55:31 -04:00
[ !!! NOT IMPLEMENTED
Regular : String -> Content
Directory : [(String, Content)] -> Content
(this complicates unambiguous normalisation)
]
CHash : Hash -> Content
2003-06-27 05:55:31 -04:00
File content, given either in situ, or through an external reference
to the file system or url-space decorated with a hash to preserve purity.
2003-06-27 05:55:31 -04:00
DISCUSSION: the idea is that a Regular/Directory is interchangeable
with its CHash. This would appear to break referential
transparency, e.g., Derive(..., ..., [...CHash(h)...], ...) can
only be reduced in a context were the Regular/Directory equivalent
of Hash(h) is known. However, CHash should be viewed strictly as a
shorthand; that is, when we export an expression containing a
CHash, we should also export the file object referenced by that
CHash.
2003-06-27 05:55:31 -04:00
\section{Reduction rules}
...
2003-06-27 05:55:31 -04:00
\section{Normals forms}
An expression is in {\em weak head normal form} if it is a lambda,
a string or boolean value, or a File or Derive value.
An expression is in {\em $d$-normal form} if it matches the
signature FExpr:
File : String * Content * [DExpr] -> DExpr
2003-06-27 05:55:31 -04:00
Derive : String * Path * [Tup] * [Tup2] -> DExpr
Tup : Str * DExpr -> Tup
Tup : Str * Str -> Tup
2003-06-27 05:55:31 -04:00
Tup : Str * Str -> Tup2
Str : String -> Str
These are Nix expressions in which the file system result of Derive
expressions has not yet been computed. This is useful for, e.g.,
querying dependencies.
2003-06-27 05:55:31 -04:00
An expression is in {\em $f$-normal form} if it matches the
signature FExpr:
File : String * Content * [FExpr] -> FExpr
These are completely evaluated Nix expressions.
*/
typedef ATerm Expr;
2003-06-27 05:55:31 -04:00
typedef ATerm Content;
2003-06-27 05:55:31 -04:00
/* Expression normalisation. */
Expr whNormalise(Expr e);
Expr dNormalise(Expr e);
Expr fNormalise(Expr e);
2003-06-27 05:55:31 -04:00
/* Realise a $f$-normalised expression in the file system. */
void realise(Expr e);
2003-06-17 09:37:44 -04:00
/* Return a canonical textual representation of an expression. */
string printExpr(Expr e);
/* Perform variable substitution. */
Expr substExpr(string x, Expr rep, Expr e);
2003-06-17 09:37:44 -04:00
/* Hash an expression. */
Hash hashExpr(Expr e);
#endif /* !__EVAL_H */