2003-06-16 13:33:38 +00:00
|
|
|
#ifndef __EVAL_H
|
|
|
|
#define __EVAL_H
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <aterm2.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "hash.hh"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
/* Abstract syntax of Nix values:
|
|
|
|
|
2003-06-17 15:45:43 +00:00
|
|
|
e := Deref(e) -- external expression
|
|
|
|
| Hash(h) -- value reference
|
2003-06-16 13:33:38 +00:00
|
|
|
| Str(s) -- string constant
|
|
|
|
| Bool(b) -- boolean constant
|
2003-06-17 15:45:43 +00:00
|
|
|
| Var(x) -- variable
|
2003-06-16 13:33:38 +00:00
|
|
|
| App(e, e) -- application
|
|
|
|
| Lam(x, e) -- lambda abstraction
|
2003-06-17 13:37:44 +00:00
|
|
|
| Exec(platform, e, [Arg(e, e)])
|
2003-06-16 13:33:38 +00:00
|
|
|
-- primitive; execute e with args e* on platform
|
|
|
|
;
|
|
|
|
|
2003-06-17 15:45:43 +00:00
|
|
|
TODO: Deref(e) allows computed external expressions, which might be
|
|
|
|
too expressive; perhaps this should be Deref(h).
|
|
|
|
|
2003-06-16 13:33:38 +00:00
|
|
|
Semantics
|
|
|
|
|
2003-06-17 13:37:44 +00:00
|
|
|
Each rule given as eval(e) => e', i.e., expression e has a normal
|
|
|
|
form e'.
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-06-17 15:45:43 +00:00
|
|
|
eval(Deref(Hash(h))) => eval(loadExpr(h))
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-06-17 15:45:43 +00:00
|
|
|
eval(Hash(h)) => Hash(h) # idem for Str, Bool
|
2003-06-16 13:33:38 +00:00
|
|
|
|
|
|
|
eval(App(e1, e2)) => eval(App(e1', e2))
|
2003-06-17 13:37:44 +00:00
|
|
|
where e1' = eval(e1)
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-06-17 13:37:44 +00:00
|
|
|
eval(App(Lam(var, body), arg)) =>
|
|
|
|
eval(subst(var, arg, body))
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-06-17 15:45:43 +00:00
|
|
|
eval(Exec(platform, prog, args)) => Hash(h)
|
2003-06-16 13:33:38 +00:00
|
|
|
where
|
2003-06-17 13:37:44 +00:00
|
|
|
fn = ... name of the output (random or by hashing expr) ...
|
2003-06-16 13:33:38 +00:00
|
|
|
h =
|
2003-06-17 13:37:44 +00:00
|
|
|
if exec( fn
|
|
|
|
, eval(platform) => Str(...)
|
|
|
|
, getFile(eval(prog))
|
2003-06-16 13:33:38 +00:00
|
|
|
, map(makeArg . eval, args)
|
|
|
|
) then
|
2003-06-17 15:45:43 +00:00
|
|
|
hashPath(fn)
|
2003-06-16 13:33:38 +00:00
|
|
|
else
|
|
|
|
undef
|
2003-06-17 13:37:44 +00:00
|
|
|
... register ...
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-06-17 15:45:43 +00:00
|
|
|
makeArg(Arg(Str(nm), (Hash(h), h))) => (nm, getFile(h))
|
2003-06-17 13:37:44 +00:00
|
|
|
makeArg(Arg(Str(nm), (Str(s), _))) => (nm, s)
|
|
|
|
makeArg(Arg(Str(nm), (Bool(True), _))) => (nm, "1")
|
|
|
|
makeArg(Arg(Str(nm), (Bool(False), _))) => (nm, undef)
|
2003-06-16 13:33:38 +00:00
|
|
|
|
|
|
|
getFile :: Hash -> FileName
|
|
|
|
loadExpr :: Hash -> FileName
|
|
|
|
hashExpr :: Expr -> Hash
|
2003-06-17 15:45:43 +00:00
|
|
|
hashPath :: FileName -> Hash
|
2003-06-17 13:37:44 +00:00
|
|
|
exec :: FileName -> Platform -> FileName -> [(String, String)] -> Status
|
2003-06-16 13:33:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef ATerm Expr;
|
|
|
|
|
|
|
|
|
2003-06-17 13:37:44 +00:00
|
|
|
/* Evaluate an expression. */
|
|
|
|
Expr evalValue(Expr e);
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-06-17 13:37:44 +00:00
|
|
|
/* Return a canonical textual representation of an expression. */
|
|
|
|
string printExpr(Expr e);
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-06-17 13:37:44 +00:00
|
|
|
/* Hash an expression. */
|
|
|
|
Hash hashExpr(Expr e);
|
2003-06-16 13:33:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* !__EVAL_H */
|