2012-07-18 18:59:03 +00:00
|
|
|
#pragma once
|
2012-01-07 17:26:33 +00:00
|
|
|
|
|
|
|
#include "symbol-table.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
tInt = 1,
|
|
|
|
tBool,
|
|
|
|
tString,
|
|
|
|
tPath,
|
|
|
|
tNull,
|
|
|
|
tAttrs,
|
|
|
|
tList,
|
|
|
|
tThunk,
|
|
|
|
tApp,
|
|
|
|
tLambda,
|
|
|
|
tBlackhole,
|
|
|
|
tPrimOp,
|
|
|
|
tPrimOpApp,
|
|
|
|
} ValueType;
|
|
|
|
|
|
|
|
|
2014-01-21 17:29:55 +00:00
|
|
|
class Bindings;
|
2012-01-07 17:26:33 +00:00
|
|
|
struct Env;
|
|
|
|
struct Expr;
|
|
|
|
struct ExprLambda;
|
|
|
|
struct PrimOp;
|
|
|
|
struct PrimOp;
|
2014-01-21 17:29:55 +00:00
|
|
|
class Symbol;
|
2012-01-07 17:26:33 +00:00
|
|
|
|
|
|
|
|
2013-08-19 10:35:03 +00:00
|
|
|
typedef long NixInt;
|
|
|
|
|
|
|
|
|
2012-01-07 17:26:33 +00:00
|
|
|
struct Value
|
|
|
|
{
|
|
|
|
ValueType type;
|
2013-08-19 10:35:03 +00:00
|
|
|
union
|
2012-01-07 17:26:33 +00:00
|
|
|
{
|
2013-08-19 10:35:03 +00:00
|
|
|
NixInt integer;
|
2012-01-07 17:26:33 +00:00
|
|
|
bool boolean;
|
2013-08-19 10:35:03 +00:00
|
|
|
|
2013-08-06 12:15:11 +00:00
|
|
|
/* Strings in the evaluator carry a so-called `context' which
|
|
|
|
is a list of strings representing store paths. This is to
|
|
|
|
allow users to write things like
|
2012-01-07 17:26:33 +00:00
|
|
|
|
|
|
|
"--with-freetype2-library=" + freetype + "/lib"
|
|
|
|
|
|
|
|
where `freetype' is a derivation (or a source to be copied
|
|
|
|
to the store). If we just concatenated the strings without
|
|
|
|
keeping track of the referenced store paths, then if the
|
|
|
|
string is used as a derivation attribute, the derivation
|
|
|
|
will not have the correct dependencies in its inputDrvs and
|
|
|
|
inputSrcs.
|
|
|
|
|
|
|
|
The semantics of the context is as follows: when a string
|
|
|
|
with context C is used as a derivation attribute, then the
|
|
|
|
derivations in C will be added to the inputDrvs of the
|
|
|
|
derivation, and the other store paths in C will be added to
|
|
|
|
the inputSrcs of the derivations.
|
|
|
|
|
|
|
|
For canonicity, the store paths should be in sorted order. */
|
|
|
|
struct {
|
|
|
|
const char * s;
|
|
|
|
const char * * context; // must be in sorted order
|
|
|
|
} string;
|
2013-08-19 10:35:03 +00:00
|
|
|
|
2012-01-07 17:26:33 +00:00
|
|
|
const char * path;
|
|
|
|
Bindings * attrs;
|
|
|
|
struct {
|
|
|
|
unsigned int length;
|
|
|
|
Value * * elems;
|
|
|
|
} list;
|
|
|
|
struct {
|
|
|
|
Env * env;
|
|
|
|
Expr * expr;
|
|
|
|
} thunk;
|
|
|
|
struct {
|
|
|
|
Value * left, * right;
|
|
|
|
} app;
|
|
|
|
struct {
|
|
|
|
Env * env;
|
|
|
|
ExprLambda * fun;
|
|
|
|
} lambda;
|
|
|
|
PrimOp * primOp;
|
|
|
|
struct {
|
|
|
|
Value * left, * right;
|
|
|
|
} primOpApp;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* After overwriting an app node, be sure to clear pointers in the
|
|
|
|
Value to ensure that the target isn't kept alive unnecessarily. */
|
|
|
|
static inline void clearValue(Value & v)
|
|
|
|
{
|
|
|
|
v.app.right = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-19 10:35:03 +00:00
|
|
|
static inline void mkInt(Value & v, NixInt n)
|
2012-01-07 17:26:33 +00:00
|
|
|
{
|
|
|
|
clearValue(v);
|
|
|
|
v.type = tInt;
|
|
|
|
v.integer = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void mkBool(Value & v, bool b)
|
|
|
|
{
|
|
|
|
clearValue(v);
|
|
|
|
v.type = tBool;
|
|
|
|
v.boolean = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-18 21:22:35 +00:00
|
|
|
static inline void mkNull(Value & v)
|
|
|
|
{
|
|
|
|
v.type = tNull;
|
|
|
|
v.app.left = v.app.right = 00; // scrub
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-07 17:26:33 +00:00
|
|
|
static inline void mkApp(Value & v, Value & left, Value & right)
|
|
|
|
{
|
|
|
|
v.type = tApp;
|
|
|
|
v.app.left = &left;
|
|
|
|
v.app.right = &right;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void mkStringNoCopy(Value & v, const char * s)
|
|
|
|
{
|
|
|
|
v.type = tString;
|
|
|
|
v.string.s = s;
|
|
|
|
v.string.context = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void mkString(Value & v, const Symbol & s)
|
|
|
|
{
|
2012-12-13 05:13:26 +00:00
|
|
|
mkStringNoCopy(v, ((const string &) s).c_str());
|
2012-01-07 17:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mkString(Value & v, const char * s);
|
|
|
|
|
|
|
|
|
|
|
|
static inline void mkPathNoCopy(Value & v, const char * s)
|
|
|
|
{
|
|
|
|
clearValue(v);
|
|
|
|
v.type = tPath;
|
|
|
|
v.path = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mkPath(Value & v, const char * s);
|
|
|
|
|
|
|
|
|
2014-09-22 12:46:42 +00:00
|
|
|
/* Compute the size in bytes of the given value, including all values
|
|
|
|
and environments reachable from it. Static expressions (Exprs) are
|
|
|
|
not included. */
|
|
|
|
size_t valueSize(Value & v);
|
|
|
|
|
|
|
|
|
2012-01-07 17:26:33 +00:00
|
|
|
}
|