1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +02:00

* Builtin function `add' to add integers.

* Put common test functions in tests/lang/lib.nix.
This commit is contained in:
Eelco Dolstra 2006-09-22 15:29:21 +00:00
parent d315210612
commit 2ab4bc44c7
11 changed files with 68 additions and 26 deletions

View file

@ -176,6 +176,16 @@ Path evalPath(EvalState & state, Expr e)
}
int evalInt(EvalState & state, Expr e)
{
e = evalExpr(state, e);
int i;
if (!matchInt(e, i))
throw TypeError(format("value is %1% while an integer was expected") % showType(e));
return i;
}
bool evalBool(EvalState & state, Expr e)
{
e = evalExpr(state, e);

View file

@ -62,6 +62,7 @@ Expr strictEvalExpr(EvalState & state, Expr e,
/* Specific results. */
string evalString(EvalState & state, Expr e);
Path evalPath(EvalState & state, Expr e);
int evalInt(EvalState & state, Expr e);
bool evalBool(EvalState & state, Expr e);
ATermList evalList(EvalState & state, Expr e);
ATerm coerceToString(Expr e);

View file

@ -771,6 +771,14 @@ static Expr primRelativise(EvalState & state, const ATermVector & args)
}
static Expr primAdd(EvalState & state, const ATermVector & args)
{
int i1 = evalInt(state, args[0]);
int i2 = evalInt(state, args[1]);
return makeInt(i1 + i2);
}
void EvalState::addPrimOps()
{
addPrimOp("builtins", 0, primBuiltins);
@ -801,6 +809,7 @@ void EvalState::addPrimOps()
addPrimOp("__hasAttr", 2, primHasAttr);
addPrimOp("removeAttrs", 2, primRemoveAttrs);
addPrimOp("relativise", 2, primRelativise);
addPrimOp("__add", 2, primAdd);
}