about summary refs log tree commit diff
path: root/src/eval.hh
blob: c1b2f21395856442eda12e0bd38fb04d81d575fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef __EVAL_H
#define __EVAL_H

extern "C" {
#include <aterm2.h>
}

#include "hash.hh"

using namespace std;


/* 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.

     File : String * 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.

     Derive : String * Expr * [Expr] * [String] -> Expr

   Derive(platform, builder, ins, outs) 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 and in an environment given by `ins'.

     Str : String -> Expr

   A string constant.

     Tup : Expr * Expr -> Expr

   Tuples of expressions.

     Regular : String -> Content
     Directory : [(String, Content)] -> Content
     Hash : String -> Content

   File content, given either explicitly or implicitly through a cryptographic hash.

   The set of expressions in {\em $f$-normal form} is as follows:

     File : String * Content * [FExpr] -> FExpr

   These are completely evaluated Nix expressions.

   The set of expressions in {\em $d$-normal form} is as follows:

     File : String * Content * [DExpr] -> DExpr
     Derive : String * DExpr * [Tup] * [String] -> DExpr

     Tup : Str * DExpr -> Tup
     Tup : Str * Str -> Tup

     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.

*/

typedef ATerm Expr;


/* Evaluate an expression. */
Expr evalValue(Expr e);

/* Return a canonical textual representation of an expression. */
string printExpr(Expr e);

/* Perform variable substitution. */
Expr substExpr(string x, Expr rep, Expr e);

/* Hash an expression. */
Hash hashExpr(Expr e);


#endif /* !__EVAL_H */