2003-06-16 15:33:38 +02:00
|
|
|
#ifndef __EVAL_H
|
|
|
|
#define __EVAL_H
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <aterm2.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "hash.hh"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2003-06-27 11:55:31 +02:00
|
|
|
/* \section{Abstract syntax of Nix expressions}
|
2003-06-25 17:50:37 +02:00
|
|
|
|
|
|
|
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 11:55:31 +02:00
|
|
|
File : Path * Content * [Expr] -> Expr
|
2003-06-25 17:50:37 +02:00
|
|
|
|
|
|
|
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 11:55:31 +02:00
|
|
|
Derive : String * Path * [Expr] * [Expr] * [Expr] -> Expr
|
2003-06-25 17:50:37 +02:00
|
|
|
|
2003-06-27 11:55:31 +02: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.
|
2003-06-25 17:50:37 +02:00
|
|
|
|
|
|
|
Str : String -> Expr
|
|
|
|
|
|
|
|
A string constant.
|
|
|
|
|
|
|
|
Tup : Expr * Expr -> Expr
|
|
|
|
|
|
|
|
Tuples of expressions.
|
|
|
|
|
2003-06-27 11:55:31 +02:00
|
|
|
[ !!! NOT IMPLEMENTED
|
|
|
|
Regular : String -> Content
|
|
|
|
Directory : [(String, Content)] -> Content
|
|
|
|
(this complicates unambiguous normalisation)
|
|
|
|
]
|
|
|
|
CHash : Hash -> Content
|
2003-06-25 17:50:37 +02:00
|
|
|
|
2003-06-27 11:55:31 +02: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-25 17:50:37 +02:00
|
|
|
|
2003-06-27 11:55:31 +02: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-25 17:50:37 +02:00
|
|
|
|
|
|
|
|
2003-06-27 11:55:31 +02:00
|
|
|
\section{Reduction rules}
|
|
|
|
|
|
|
|
...
|
|
|
|
|
2003-06-25 17:50:37 +02:00
|
|
|
|
2003-06-27 11:55:31 +02: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:
|
2003-06-25 17:50:37 +02:00
|
|
|
|
|
|
|
File : String * Content * [DExpr] -> DExpr
|
2003-06-27 11:55:31 +02:00
|
|
|
Derive : String * Path * [Tup] * [Tup2] -> DExpr
|
2003-06-25 17:50:37 +02:00
|
|
|
|
|
|
|
Tup : Str * DExpr -> Tup
|
|
|
|
Tup : Str * Str -> Tup
|
|
|
|
|
2003-06-27 11:55:31 +02:00
|
|
|
Tup : Str * Str -> Tup2
|
|
|
|
|
2003-06-25 17:50:37 +02:00
|
|
|
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 11:55:31 +02: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.
|
|
|
|
|
2003-06-16 15:33:38 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef ATerm Expr;
|
2003-06-27 11:55:31 +02:00
|
|
|
typedef ATerm Content;
|
|
|
|
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2003-06-27 11:55:31 +02:00
|
|
|
/* Expression normalisation. */
|
|
|
|
Expr whNormalise(Expr e);
|
|
|
|
Expr dNormalise(Expr e);
|
|
|
|
Expr fNormalise(Expr e);
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2003-06-27 11:55:31 +02:00
|
|
|
/* Realise a $f$-normalised expression in the file system. */
|
|
|
|
void realise(Expr e);
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2003-06-17 15:37:44 +02:00
|
|
|
/* Return a canonical textual representation of an expression. */
|
|
|
|
string printExpr(Expr e);
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2003-06-18 14:36:12 +02:00
|
|
|
/* Perform variable substitution. */
|
|
|
|
Expr substExpr(string x, Expr rep, Expr e);
|
|
|
|
|
2003-06-17 15:37:44 +02:00
|
|
|
/* Hash an expression. */
|
|
|
|
Hash hashExpr(Expr e);
|
2003-06-16 15:33:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* !__EVAL_H */
|