Remove non-method mk<X> functions

This commit is contained in:
Eelco Dolstra 2022-01-04 18:40:39 +01:00
parent cc08364315
commit 263a8d293c
9 changed files with 99 additions and 121 deletions

View file

@ -613,7 +613,7 @@ Value * EvalState::addPrimOp(const string & name,
auto vPrimOp = allocValue(); auto vPrimOp = allocValue();
vPrimOp->mkPrimOp(new PrimOp { .fun = primOp, .arity = 1, .name = sym }); vPrimOp->mkPrimOp(new PrimOp { .fun = primOp, .arity = 1, .name = sym });
Value v; Value v;
mkApp(v, *vPrimOp, *vPrimOp); v.mkApp(vPrimOp, vPrimOp);
return addConstant(name, v); return addConstant(name, v);
} }
@ -635,7 +635,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
auto vPrimOp = allocValue(); auto vPrimOp = allocValue();
vPrimOp->mkPrimOp(new PrimOp(std::move(primOp))); vPrimOp->mkPrimOp(new PrimOp(std::move(primOp)));
Value v; Value v;
mkApp(v, *vPrimOp, *vPrimOp); v.mkApp(vPrimOp, vPrimOp);
return addConstant(primOp.name, v); return addConstant(primOp.name, v);
} }
@ -887,7 +887,7 @@ void EvalState::mkPos(Value & v, ptr<Pos> pos)
attrs.alloc(sColumn).mkInt(pos->column); attrs.alloc(sColumn).mkInt(pos->column);
v.mkAttrs(attrs); v.mkAttrs(attrs);
} else } else
mkNull(v); v.mkNull();
} }
@ -1258,14 +1258,14 @@ void ExprOpHasAttr::eval(EvalState & state, Env & env, Value & v)
if (vAttrs->type() != nAttrs || if (vAttrs->type() != nAttrs ||
(j = vAttrs->attrs->find(name)) == vAttrs->attrs->end()) (j = vAttrs->attrs->find(name)) == vAttrs->attrs->end())
{ {
mkBool(v, false); v.mkBool(false);
return; return;
} else { } else {
vAttrs = j->value; vAttrs = j->value;
} }
} }
mkBool(v, true); v.mkBool(true);
} }
@ -1544,7 +1544,7 @@ void ExprAssert::eval(EvalState & state, Env & env, Value & v)
void ExprOpNot::eval(EvalState & state, Env & env, Value & v) void ExprOpNot::eval(EvalState & state, Env & env, Value & v)
{ {
mkBool(v, !state.evalBool(env, e)); v.mkBool(!state.evalBool(env, e));
} }
@ -1552,7 +1552,7 @@ void ExprOpEq::eval(EvalState & state, Env & env, Value & v)
{ {
Value v1; e1->eval(state, env, v1); Value v1; e1->eval(state, env, v1);
Value v2; e2->eval(state, env, v2); Value v2; e2->eval(state, env, v2);
mkBool(v, state.eqValues(v1, v2)); v.mkBool(state.eqValues(v1, v2));
} }
@ -1560,25 +1560,25 @@ void ExprOpNEq::eval(EvalState & state, Env & env, Value & v)
{ {
Value v1; e1->eval(state, env, v1); Value v1; e1->eval(state, env, v1);
Value v2; e2->eval(state, env, v2); Value v2; e2->eval(state, env, v2);
mkBool(v, !state.eqValues(v1, v2)); v.mkBool(!state.eqValues(v1, v2));
} }
void ExprOpAnd::eval(EvalState & state, Env & env, Value & v) void ExprOpAnd::eval(EvalState & state, Env & env, Value & v)
{ {
mkBool(v, state.evalBool(env, e1, pos) && state.evalBool(env, e2, pos)); v.mkBool(state.evalBool(env, e1, pos) && state.evalBool(env, e2, pos));
} }
void ExprOpOr::eval(EvalState & state, Env & env, Value & v) void ExprOpOr::eval(EvalState & state, Env & env, Value & v)
{ {
mkBool(v, state.evalBool(env, e1, pos) || state.evalBool(env, e2, pos)); v.mkBool(state.evalBool(env, e1, pos) || state.evalBool(env, e2, pos));
} }
void ExprOpImpl::eval(EvalState & state, Env & env, Value & v) void ExprOpImpl::eval(EvalState & state, Env & env, Value & v)
{ {
mkBool(v, !state.evalBool(env, e1, pos) || state.evalBool(env, e2, pos)); v.mkBool(!state.evalBool(env, e1, pos) || state.evalBool(env, e2, pos));
} }
@ -1705,9 +1705,9 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
} }
if (firstType == nInt) if (firstType == nInt)
mkInt(v, n); v.mkInt(n);
else if (firstType == nFloat) else if (firstType == nFloat)
mkFloat(v, nf); v.mkFloat(nf);
else if (firstType == nPath) { else if (firstType == nPath) {
if (!context.empty()) if (!context.empty())
throwEvalError(pos, "a string that refers to a store path cannot be appended to a path"); throwEvalError(pos, "a string that refers to a store path cannot be appended to a path");

View file

@ -76,39 +76,42 @@ class JSONSax : nlohmann::json_sax<json> {
EvalState & state; EvalState & state;
std::unique_ptr<JSONState> rs; std::unique_ptr<JSONState> rs;
template<typename T, typename... Args> inline bool handle_value(T f, Args... args)
{
f(rs->value(state), args...);
rs->add();
return true;
}
public: public:
JSONSax(EvalState & state, Value & v) : state(state), rs(new JSONState(&v)) {}; JSONSax(EvalState & state, Value & v) : state(state), rs(new JSONState(&v)) {};
bool null() bool null()
{ {
return handle_value(mkNull); rs->value(state).mkNull();
rs->add();
return true;
} }
bool boolean(bool val) bool boolean(bool val)
{ {
return handle_value(mkBool, val); rs->value(state).mkBool(val);
rs->add();
return true;
} }
bool number_integer(number_integer_t val) bool number_integer(number_integer_t val)
{ {
return handle_value(mkInt, val); rs->value(state).mkInt(val);
rs->add();
return true;
} }
bool number_unsigned(number_unsigned_t val) bool number_unsigned(number_unsigned_t val)
{ {
return handle_value(mkInt, val); rs->value(state).mkInt(val);
rs->add();
return true;
} }
bool number_float(number_float_t val, const string_t & s) bool number_float(number_float_t val, const string_t & s)
{ {
return handle_value(mkFloat, val); rs->value(state).mkFloat(val);
rs->add();
return true;
} }
bool string(string_t & val) bool string(string_t & val)

View file

@ -94,7 +94,7 @@ struct ExprInt : Expr
{ {
NixInt n; NixInt n;
Value v; Value v;
ExprInt(NixInt n) : n(n) { mkInt(v, n); }; ExprInt(NixInt n) : n(n) { v.mkInt(n); };
COMMON_METHODS COMMON_METHODS
Value * maybeThunk(EvalState & state, Env & env); Value * maybeThunk(EvalState & state, Env & env);
}; };
@ -103,7 +103,7 @@ struct ExprFloat : Expr
{ {
NixFloat nf; NixFloat nf;
Value v; Value v;
ExprFloat(NixFloat nf) : nf(nf) { mkFloat(v, nf); }; ExprFloat(NixFloat nf) : nf(nf) { v.mkFloat(nf); };
COMMON_METHODS COMMON_METHODS
Value * maybeThunk(EvalState & state, Env & env); Value * maybeThunk(EvalState & state, Env & env);
}; };

View file

@ -196,7 +196,7 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
} }
state.forceFunction(**state.vImportedDrvToDerivation, pos); state.forceFunction(**state.vImportedDrvToDerivation, pos);
mkApp(v, **state.vImportedDrvToDerivation, *w); v.mkApp(*state.vImportedDrvToDerivation, w);
state.forceAttrs(v, pos); state.forceAttrs(v, pos);
} }
@ -430,7 +430,7 @@ static RegisterPrimOp primop_typeOf({
static void prim_isNull(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isNull(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nNull); v.mkBool(args[0]->type() == nNull);
} }
static RegisterPrimOp primop_isNull({ static RegisterPrimOp primop_isNull({
@ -450,7 +450,7 @@ static RegisterPrimOp primop_isNull({
static void prim_isFunction(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isFunction(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nFunction); v.mkBool(args[0]->type() == nFunction);
} }
static RegisterPrimOp primop_isFunction({ static RegisterPrimOp primop_isFunction({
@ -466,7 +466,7 @@ static RegisterPrimOp primop_isFunction({
static void prim_isInt(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isInt(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nInt); v.mkBool(args[0]->type() == nInt);
} }
static RegisterPrimOp primop_isInt({ static RegisterPrimOp primop_isInt({
@ -482,7 +482,7 @@ static RegisterPrimOp primop_isInt({
static void prim_isFloat(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isFloat(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nFloat); v.mkBool(args[0]->type() == nFloat);
} }
static RegisterPrimOp primop_isFloat({ static RegisterPrimOp primop_isFloat({
@ -498,7 +498,7 @@ static RegisterPrimOp primop_isFloat({
static void prim_isString(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isString(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nString); v.mkBool(args[0]->type() == nString);
} }
static RegisterPrimOp primop_isString({ static RegisterPrimOp primop_isString({
@ -514,7 +514,7 @@ static RegisterPrimOp primop_isString({
static void prim_isBool(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isBool(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nBool); v.mkBool(args[0]->type() == nBool);
} }
static RegisterPrimOp primop_isBool({ static RegisterPrimOp primop_isBool({
@ -530,7 +530,7 @@ static RegisterPrimOp primop_isBool({
static void prim_isPath(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isPath(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nPath); v.mkBool(args[0]->type() == nPath);
} }
static RegisterPrimOp primop_isPath({ static RegisterPrimOp primop_isPath({
@ -685,7 +685,7 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
/* Call the `operator' function with `e' as argument. */ /* Call the `operator' function with `e' as argument. */
Value call; Value call;
mkApp(call, *op->value, *e); call.mkApp(op->value, e);
state.forceList(call, pos); state.forceList(call, pos);
/* Add the values returned by the operator to the work set. */ /* Add the values returned by the operator to the work set. */
@ -761,7 +761,7 @@ static RegisterPrimOp primop_addErrorContext(RegisterPrimOp::Info {
static void prim_ceil(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_ceil(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
auto value = state.forceFloat(*args[0], args[0]->determinePos(pos)); auto value = state.forceFloat(*args[0], args[0]->determinePos(pos));
mkInt(v, ceil(value)); v.mkInt(ceil(value));
} }
static RegisterPrimOp primop_ceil({ static RegisterPrimOp primop_ceil({
@ -780,7 +780,7 @@ static RegisterPrimOp primop_ceil({
static void prim_floor(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_floor(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
auto value = state.forceFloat(*args[0], args[0]->determinePos(pos)); auto value = state.forceFloat(*args[0], args[0]->determinePos(pos));
mkInt(v, floor(value)); v.mkInt(floor(value));
} }
static RegisterPrimOp primop_floor({ static RegisterPrimOp primop_floor({
@ -804,10 +804,10 @@ static void prim_tryEval(EvalState & state, const Pos & pos, Value * * args, Val
try { try {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
attrs.insert(state.sValue, args[0]); attrs.insert(state.sValue, args[0]);
mkBool(attrs.alloc("success"), true); attrs.alloc("success").mkBool(true);
} catch (AssertionError & e) { } catch (AssertionError & e) {
mkBool(attrs.alloc(state.sValue), false); attrs.alloc(state.sValue).mkBool(false);
mkBool(attrs.alloc("success"), false); attrs.alloc("success").mkBool(false);
} }
v.mkAttrs(attrs); v.mkAttrs(attrs);
} }
@ -1395,13 +1395,13 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
} }
try { try {
mkBool(v, pathExists(state.checkSourcePath(path))); v.mkBool(pathExists(state.checkSourcePath(path)));
} catch (SysError & e) { } catch (SysError & e) {
/* Don't give away info from errors while canonicalising /* Don't give away info from errors while canonicalising
path in restricted mode. */ path in restricted mode. */
mkBool(v, false); v.mkBool(false);
} catch (RestrictedPathError & e) { } catch (RestrictedPathError & e) {
mkBool(v, false); v.mkBool(false);
} }
} }
@ -2213,7 +2213,7 @@ static void prim_unsafeGetAttrPos(EvalState & state, const Pos & pos, Value * *
state.forceAttrs(*args[1], pos); state.forceAttrs(*args[1], pos);
Bindings::iterator i = args[1]->attrs->find(state.symbols.create(attr)); Bindings::iterator i = args[1]->attrs->find(state.symbols.create(attr));
if (i == args[1]->attrs->end()) if (i == args[1]->attrs->end())
mkNull(v); v.mkNull();
else else
state.mkPos(v, i->pos); state.mkPos(v, i->pos);
} }
@ -2229,7 +2229,7 @@ static void prim_hasAttr(EvalState & state, const Pos & pos, Value * * args, Val
{ {
string attr = state.forceStringNoCtx(*args[0], pos); string attr = state.forceStringNoCtx(*args[0], pos);
state.forceAttrs(*args[1], pos); state.forceAttrs(*args[1], pos);
mkBool(v, args[1]->attrs->find(state.symbols.create(attr)) != args[1]->attrs->end()); v.mkBool(args[1]->attrs->find(state.symbols.create(attr)) != args[1]->attrs->end());
} }
static RegisterPrimOp primop_hasAttr({ static RegisterPrimOp primop_hasAttr({
@ -2247,7 +2247,7 @@ static RegisterPrimOp primop_hasAttr({
static void prim_isAttrs(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isAttrs(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nAttrs); v.mkBool(args[0]->type() == nAttrs);
} }
static RegisterPrimOp primop_isAttrs({ static RegisterPrimOp primop_isAttrs({
@ -2446,7 +2446,7 @@ static void prim_functionArgs(EvalState & state, const Pos & pos, Value * * args
auto attrs = state.buildBindings(args[0]->lambda.fun->formals->formals.size()); auto attrs = state.buildBindings(args[0]->lambda.fun->formals->formals.size());
for (auto & i : args[0]->lambda.fun->formals->formals) for (auto & i : args[0]->lambda.fun->formals->formals)
// !!! should optimise booleans (allocate only once) // !!! should optimise booleans (allocate only once)
mkBool(attrs.alloc(i.name, ptr(&i.pos)), i.def); attrs.alloc(i.name, ptr(&i.pos)).mkBool(i.def);
v.mkAttrs(attrs); v.mkAttrs(attrs);
} }
@ -2478,8 +2478,8 @@ static void prim_mapAttrs(EvalState & state, const Pos & pos, Value * * args, Va
Value * vName = state.allocValue(); Value * vName = state.allocValue();
Value * vFun2 = state.allocValue(); Value * vFun2 = state.allocValue();
mkString(*vName, i.name); mkString(*vName, i.name);
mkApp(*vFun2, *args[0], *vName); vFun2->mkApp(args[0], vName);
mkApp(*state.allocAttr(v, i.name), *vFun2, *i.value); state.allocAttr(v, i.name)->mkApp(vFun2, i.value);
} }
} }
@ -2542,10 +2542,10 @@ static void prim_zipAttrsWith(EvalState & state, const Pos & pos, Value * * args
for (auto & attr : *v.attrs) { for (auto & attr : *v.attrs) {
Value * name = state.allocValue(); Value * name = state.allocValue();
mkString(*name, attr.name); mkString(*name, attr.name);
Value * call1 = state.allocValue(); auto call1 = state.allocValue();
mkApp(*call1, *args[0], *name); call1->mkApp(args[0], name);
Value * call2 = state.allocValue(); auto call2 = state.allocValue();
mkApp(*call2, *call1, *attr.value); call2->mkApp(call1, attr.value);
attr.value = call2; attr.value = call2;
} }
} }
@ -2592,7 +2592,7 @@ static RegisterPrimOp primop_zipAttrsWith({
static void prim_isList(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_isList(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
mkBool(v, args[0]->type() == nList); v.mkBool(args[0]->type() == nList);
} }
static RegisterPrimOp primop_isList({ static RegisterPrimOp primop_isList({
@ -2690,8 +2690,8 @@ static void prim_map(EvalState & state, const Pos & pos, Value * * args, Value &
state.mkList(v, args[1]->listSize()); state.mkList(v, args[1]->listSize());
for (unsigned int n = 0; n < v.listSize(); ++n) for (unsigned int n = 0; n < v.listSize(); ++n)
mkApp(*(v.listElems()[n] = state.allocValue()), (v.listElems()[n] = state.allocValue())->mkApp(
*args[0], *args[1]->listElems()[n]); args[0], args[1]->listElems()[n]);
} }
static RegisterPrimOp primop_map({ static RegisterPrimOp primop_map({
@ -2760,7 +2760,7 @@ static void prim_elem(EvalState & state, const Pos & pos, Value * * args, Value
res = true; res = true;
break; break;
} }
mkBool(v, res); v.mkBool(res);
} }
static RegisterPrimOp primop_elem({ static RegisterPrimOp primop_elem({
@ -2793,7 +2793,7 @@ static RegisterPrimOp primop_concatLists({
static void prim_length(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_length(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
state.forceList(*args[0], pos); state.forceList(*args[0], pos);
mkInt(v, args[0]->listSize()); v.mkInt(args[0]->listSize());
} }
static RegisterPrimOp primop_length({ static RegisterPrimOp primop_length({
@ -2850,12 +2850,12 @@ static void anyOrAll(bool any, EvalState & state, const Pos & pos, Value * * arg
state.callFunction(*args[0], *elem, vTmp, pos); state.callFunction(*args[0], *elem, vTmp, pos);
bool res = state.forceBool(vTmp, pos); bool res = state.forceBool(vTmp, pos);
if (res == any) { if (res == any) {
mkBool(v, any); v.mkBool(any);
return; return;
} }
} }
mkBool(v, !any); v.mkBool(!any);
} }
@ -2902,9 +2902,9 @@ static void prim_genList(EvalState & state, const Pos & pos, Value * * args, Val
state.mkList(v, len); state.mkList(v, len);
for (unsigned int n = 0; n < (unsigned int) len; ++n) { for (unsigned int n = 0; n < (unsigned int) len; ++n) {
Value * arg = state.allocValue(); auto arg = state.allocValue();
mkInt(*arg, n); arg->mkInt(n);
mkApp(*(v.listElems()[n] = state.allocValue()), *args[0], *arg); (v.listElems()[n] = state.allocValue())->mkApp(args[0], arg);
} }
} }
@ -3140,9 +3140,9 @@ static void prim_add(EvalState & state, const Pos & pos, Value * * args, Value &
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
state.forceValue(*args[1], pos); state.forceValue(*args[1], pos);
if (args[0]->type() == nFloat || args[1]->type() == nFloat) if (args[0]->type() == nFloat || args[1]->type() == nFloat)
mkFloat(v, state.forceFloat(*args[0], pos) + state.forceFloat(*args[1], pos)); v.mkFloat(state.forceFloat(*args[0], pos) + state.forceFloat(*args[1], pos));
else else
mkInt(v, state.forceInt(*args[0], pos) + state.forceInt(*args[1], pos)); v.mkInt(state.forceInt(*args[0], pos) + state.forceInt(*args[1], pos));
} }
static RegisterPrimOp primop_add({ static RegisterPrimOp primop_add({
@ -3159,9 +3159,9 @@ static void prim_sub(EvalState & state, const Pos & pos, Value * * args, Value &
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
state.forceValue(*args[1], pos); state.forceValue(*args[1], pos);
if (args[0]->type() == nFloat || args[1]->type() == nFloat) if (args[0]->type() == nFloat || args[1]->type() == nFloat)
mkFloat(v, state.forceFloat(*args[0], pos) - state.forceFloat(*args[1], pos)); v.mkFloat(state.forceFloat(*args[0], pos) - state.forceFloat(*args[1], pos));
else else
mkInt(v, state.forceInt(*args[0], pos) - state.forceInt(*args[1], pos)); v.mkInt(state.forceInt(*args[0], pos) - state.forceInt(*args[1], pos));
} }
static RegisterPrimOp primop_sub({ static RegisterPrimOp primop_sub({
@ -3178,9 +3178,9 @@ static void prim_mul(EvalState & state, const Pos & pos, Value * * args, Value &
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
state.forceValue(*args[1], pos); state.forceValue(*args[1], pos);
if (args[0]->type() == nFloat || args[1]->type() == nFloat) if (args[0]->type() == nFloat || args[1]->type() == nFloat)
mkFloat(v, state.forceFloat(*args[0], pos) * state.forceFloat(*args[1], pos)); v.mkFloat(state.forceFloat(*args[0], pos) * state.forceFloat(*args[1], pos));
else else
mkInt(v, state.forceInt(*args[0], pos) * state.forceInt(*args[1], pos)); v.mkInt(state.forceInt(*args[0], pos) * state.forceInt(*args[1], pos));
} }
static RegisterPrimOp primop_mul({ static RegisterPrimOp primop_mul({
@ -3205,7 +3205,7 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
}); });
if (args[0]->type() == nFloat || args[1]->type() == nFloat) { if (args[0]->type() == nFloat || args[1]->type() == nFloat) {
mkFloat(v, state.forceFloat(*args[0], pos) / state.forceFloat(*args[1], pos)); v.mkFloat(state.forceFloat(*args[0], pos) / state.forceFloat(*args[1], pos));
} else { } else {
NixInt i1 = state.forceInt(*args[0], pos); NixInt i1 = state.forceInt(*args[0], pos);
NixInt i2 = state.forceInt(*args[1], pos); NixInt i2 = state.forceInt(*args[1], pos);
@ -3216,7 +3216,7 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
.errPos = pos .errPos = pos
}); });
mkInt(v, i1 / i2); v.mkInt(i1 / i2);
} }
} }
@ -3231,7 +3231,7 @@ static RegisterPrimOp primop_div({
static void prim_bitAnd(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_bitAnd(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
mkInt(v, state.forceInt(*args[0], pos) & state.forceInt(*args[1], pos)); v.mkInt(state.forceInt(*args[0], pos) & state.forceInt(*args[1], pos));
} }
static RegisterPrimOp primop_bitAnd({ static RegisterPrimOp primop_bitAnd({
@ -3245,7 +3245,7 @@ static RegisterPrimOp primop_bitAnd({
static void prim_bitOr(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_bitOr(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
mkInt(v, state.forceInt(*args[0], pos) | state.forceInt(*args[1], pos)); v.mkInt(state.forceInt(*args[0], pos) | state.forceInt(*args[1], pos));
} }
static RegisterPrimOp primop_bitOr({ static RegisterPrimOp primop_bitOr({
@ -3259,7 +3259,7 @@ static RegisterPrimOp primop_bitOr({
static void prim_bitXor(EvalState & state, const Pos & pos, Value * * args, Value & v) static void prim_bitXor(EvalState & state, const Pos & pos, Value * * args, Value & v)
{ {
mkInt(v, state.forceInt(*args[0], pos) ^ state.forceInt(*args[1], pos)); v.mkInt(state.forceInt(*args[0], pos) ^ state.forceInt(*args[1], pos));
} }
static RegisterPrimOp primop_bitXor({ static RegisterPrimOp primop_bitXor({
@ -3276,7 +3276,7 @@ static void prim_lessThan(EvalState & state, const Pos & pos, Value * * args, Va
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
state.forceValue(*args[1], pos); state.forceValue(*args[1], pos);
CompareValues comp{state}; CompareValues comp{state};
mkBool(v, comp(args[0], args[1])); v.mkBool(comp(args[0], args[1]));
} }
static RegisterPrimOp primop_lessThan({ static RegisterPrimOp primop_lessThan({
@ -3374,7 +3374,7 @@ static void prim_stringLength(EvalState & state, const Pos & pos, Value * * args
{ {
PathSet context; PathSet context;
string s = state.coerceToString(pos, *args[0], context); string s = state.coerceToString(pos, *args[0], context);
mkInt(v, s.size()); v.mkInt(s.size());
} }
static RegisterPrimOp primop_stringLength({ static RegisterPrimOp primop_stringLength({
@ -3440,7 +3440,7 @@ void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
std::smatch match; std::smatch match;
if (!std::regex_match(str, match, regex->second)) { if (!std::regex_match(str, match, regex->second)) {
mkNull(v); v.mkNull();
return; return;
} }
@ -3449,7 +3449,7 @@ void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
state.mkList(v, len); state.mkList(v, len);
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
if (!match[i+1].matched) if (!match[i+1].matched)
mkNull(*(v.listElems()[i] = state.allocValue())); (v.listElems()[i] = state.allocValue())->mkNull();
else else
(v.listElems()[i] = state.allocValue())->mkString(match[i + 1].str()); (v.listElems()[i] = state.allocValue())->mkString(match[i + 1].str());
} }
@ -3547,7 +3547,7 @@ static void prim_split(EvalState & state, const Pos & pos, Value * * args, Value
state.mkList(*elem, slen); state.mkList(*elem, slen);
for (size_t si = 0; si < slen; ++si) { for (size_t si = 0; si < slen; ++si) {
if (!match[si + 1].matched) if (!match[si + 1].matched)
mkNull(*(elem->listElems()[si] = state.allocValue())); (elem->listElems()[si] = state.allocValue())->mkNull();
else else
(elem->listElems()[si] = state.allocValue())->mkString(match[si + 1].str()); (elem->listElems()[si] = state.allocValue())->mkString(match[si + 1].str());
} }
@ -3750,7 +3750,7 @@ static void prim_compareVersions(EvalState & state, const Pos & pos, Value * * a
{ {
string version1 = state.forceStringNoCtx(*args[0], pos); string version1 = state.forceStringNoCtx(*args[0], pos);
string version2 = state.forceStringNoCtx(*args[1], pos); string version2 = state.forceStringNoCtx(*args[1], pos);
mkInt(v, compareVersions(version1, version2)); v.mkInt(compareVersions(version1, version2));
} }
static RegisterPrimOp primop_compareVersions({ static RegisterPrimOp primop_compareVersions({
@ -3832,17 +3832,17 @@ void EvalState::createBaseEnv()
mkAttrs(v, 128); mkAttrs(v, 128);
addConstant("builtins", v); addConstant("builtins", v);
mkBool(v, true); v.mkBool(true);
addConstant("true", v); addConstant("true", v);
mkBool(v, false); v.mkBool(false);
addConstant("false", v); addConstant("false", v);
mkNull(v); v.mkNull();
addConstant("null", v); addConstant("null", v);
if (!evalSettings.pureEval) { if (!evalSettings.pureEval) {
mkInt(v, time(0)); v.mkInt(time(0));
addConstant("__currentTime", v); addConstant("__currentTime", v);
v.mkString(settings.thisSystem.get()); v.mkString(settings.thisSystem.get());
@ -3859,7 +3859,7 @@ void EvalState::createBaseEnv()
language feature gets added. It's not necessary to increase it language feature gets added. It's not necessary to increase it
when primops get added, because you can just use `builtins ? when primops get added, because you can just use `builtins ?
primOp' to check. */ primOp' to check. */
mkInt(v, 6); v.mkInt(6);
addConstant("__langVersion", v); addConstant("__langVersion", v);
// Miscellaneous // Miscellaneous

View file

@ -17,7 +17,7 @@ static void prim_hasContext(EvalState & state, const Pos & pos, Value * * args,
{ {
PathSet context; PathSet context;
state.forceString(*args[0], context, pos); state.forceString(*args[0], context, pos);
mkBool(v, !context.empty()); v.mkBool(!context.empty());
} }
static RegisterPrimOp primop_hasContext("__hasContext", 1, prim_hasContext); static RegisterPrimOp primop_hasContext("__hasContext", 1, prim_hasContext);
@ -109,9 +109,9 @@ static void prim_getContext(EvalState & state, const Pos & pos, Value * * args,
for (const auto & info : contextInfos) { for (const auto & info : contextInfos) {
auto infoAttrs = state.buildBindings(3); auto infoAttrs = state.buildBindings(3);
if (info.second.path) if (info.second.path)
mkBool(infoAttrs.alloc(sPath), true); infoAttrs.alloc(sPath).mkBool(true);
if (info.second.allOutputs) if (info.second.allOutputs)
mkBool(infoAttrs.alloc(sAllOutputs), true); infoAttrs.alloc(sAllOutputs).mkBool(true);
if (!info.second.outputs.empty()) { if (!info.second.outputs.empty()) {
auto & outputsVal = infoAttrs.alloc(state.sOutputs); auto & outputsVal = infoAttrs.alloc(state.sOutputs);
state.mkList(outputsVal, info.second.outputs.size()); state.mkList(outputsVal, info.second.outputs.size());

View file

@ -43,13 +43,13 @@ static void prim_fromTOML(EvalState & state, const Pos & pos, Value * * args, Va
} }
break;; break;;
case toml::value_t::boolean: case toml::value_t::boolean:
mkBool(v, toml::get<bool>(t)); v.mkBool(toml::get<bool>(t));
break;; break;;
case toml::value_t::integer: case toml::value_t::integer:
mkInt(v, toml::get<int64_t>(t)); v.mkInt(toml::get<int64_t>(t));
break;; break;;
case toml::value_t::floating: case toml::value_t::floating:
mkFloat(v, toml::get<NixFloat>(t)); v.mkFloat(toml::get<NixFloat>(t));
break;; break;;
case toml::value_t::string: case toml::value_t::string:
v.mkString(toml::get<std::string>(t)); v.mkString(toml::get<std::string>(t));
@ -62,7 +62,7 @@ static void prim_fromTOML(EvalState & state, const Pos & pos, Value * * args, Va
throw std::runtime_error("Dates and times are not supported"); throw std::runtime_error("Dates and times are not supported");
break;; break;;
case toml::value_t::empty: case toml::value_t::empty:
mkNull(v); v.mkNull();
break;; break;;
} }

View file

@ -393,31 +393,6 @@ public:
// TODO: Remove these static functions, replace call sites with v.mk* instead // TODO: Remove these static functions, replace call sites with v.mk* instead
static inline void mkInt(Value & v, NixInt n)
{
v.mkInt(n);
}
static inline void mkFloat(Value & v, NixFloat n)
{
v.mkFloat(n);
}
static inline void mkBool(Value & v, bool b)
{
v.mkBool(b);
}
static inline void mkNull(Value & v)
{
v.mkNull();
}
static inline void mkApp(Value & v, Value & left, Value & right)
{
v.mkApp(&left, &right);
}
static inline void mkString(Value & v, const Symbol & s) static inline void mkString(Value & v, const Symbol & s)
{ {
v.mkString(((const string &) s).c_str()); v.mkString(((const string &) s).c_str());

View file

@ -408,7 +408,7 @@ static void queryInstSources(EvalState & state,
Expr * eFun = state.parseExprFromString(i, absPath(".")); Expr * eFun = state.parseExprFromString(i, absPath("."));
Value vFun, vTmp; Value vFun, vTmp;
state.eval(eFun, vFun); state.eval(eFun, vFun);
mkApp(vTmp, vFun, vArg); vTmp.mkApp(&vFun, &vArg);
getDerivations(state, vTmp, "", *instSource.autoArgs, elems, true); getDerivations(state, vTmp, "", *instSource.autoArgs, elems, true);
} }

View file

@ -16,9 +16,9 @@ static GlobalConfig::Register rs(&mySettings);
static void prim_anotherNull (EvalState & state, const Pos & pos, Value ** args, Value & v) static void prim_anotherNull (EvalState & state, const Pos & pos, Value ** args, Value & v)
{ {
if (mySettings.settingSet) if (mySettings.settingSet)
mkNull(v); v.mkNull();
else else
mkBool(v, false); v.mkBool(false);
} }
static RegisterPrimOp rp("anotherNull", 0, prim_anotherNull); static RegisterPrimOp rp("anotherNull", 0, prim_anotherNull);