libexpr: Replace Value::mkInt with constructor calls
Change-Id: I09b8e3aa61042a60c2ae767fc44c26b66a6a6964
This commit is contained in:
@@ -528,7 +528,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||
}
|
||||
|
||||
if (firstType == nInt) {
|
||||
v.mkInt(n);
|
||||
v = {NewValueAs::integer, n};
|
||||
} else if (firstType == nFloat) {
|
||||
v = {NewValueAs::floating, nf};
|
||||
} else if (firstType == nPath) {
|
||||
|
||||
@@ -1010,11 +1010,14 @@ void prim_parseFlakeRef(
|
||||
for (const auto & [key, value] : attrs) {
|
||||
auto s = state.ctx.symbols.create(key);
|
||||
auto & vv = binds.alloc(s);
|
||||
std::visit(overloaded {
|
||||
[&vv](const std::string & value) { vv.mkString(value); },
|
||||
[&vv](const uint64_t & value) { vv.mkInt(value); },
|
||||
[&vv](const Explicit<bool> & value) { vv.mkBool(value.t); }
|
||||
}, value);
|
||||
std::visit(
|
||||
overloaded{
|
||||
[&vv](const std::string & value) { vv.mkString(value); },
|
||||
[&vv](const uint64_t & value) { vv = {NewValueAs::integer, NixInt::Inner(value)}; },
|
||||
[&vv](const Explicit<bool> & value) { vv.mkBool(value.t); }
|
||||
},
|
||||
value
|
||||
);
|
||||
}
|
||||
v = {NewValueAs::attrs, binds};
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
|
||||
bool number_integer(number_integer_t val) override
|
||||
{
|
||||
rs->value().mkInt(val);
|
||||
rs->value() = {NewValueAs::integer, val};
|
||||
rs->add();
|
||||
return true;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
return number_float(static_cast<number_float_t>(val_), "");
|
||||
}
|
||||
NixInt::Inner val = val_;
|
||||
rs->value().mkInt(val);
|
||||
rs->value() = {NewValueAs::integer, val};
|
||||
rs->add();
|
||||
return true;
|
||||
}
|
||||
|
||||
+22
-21
@@ -686,13 +686,13 @@ static void prim_ceil(EvalState & state, Value * * args, Value & v)
|
||||
{
|
||||
auto value = state.forceFloat(*args[0], noPos,
|
||||
"while evaluating the first argument passed to builtins.ceil");
|
||||
v.mkInt(ceil(value));
|
||||
v = {NewValueAs::integer, NixInt::Inner(ceil(value))};
|
||||
}
|
||||
|
||||
static void prim_floor(EvalState & state, Value * * args, Value & v)
|
||||
{
|
||||
auto value = state.forceFloat(*args[0], noPos, "while evaluating the first argument passed to builtins.floor");
|
||||
v.mkInt(floor(value));
|
||||
v = {NewValueAs::integer, NixInt::Inner(floor(value))};
|
||||
}
|
||||
|
||||
/* Try evaluating the argument. Success => {success=true; value=something;},
|
||||
@@ -1889,15 +1889,16 @@ static void prim_unsafeGetAttrPos(EvalState & state, Value * * args, Value & v)
|
||||
// as with black holes this cost is too high to justify another thunk type to check
|
||||
// for in the very hot path that is forceValue.
|
||||
static struct LazyPosAcessors {
|
||||
PrimOp primop_lineOfPos{{.arity = 1, .fun = [](EvalState & state, Value ** args, Value & v) {
|
||||
v.mkInt(state.ctx.positions[PosIdx(args[0]->integer().value)].line
|
||||
);
|
||||
}}};
|
||||
PrimOp primop_columnOfPos{{.arity = 1, .fun = [](EvalState & state, Value ** args, Value & v) {
|
||||
v.mkInt(
|
||||
state.ctx.positions[PosIdx(args[0]->integer().value)].column
|
||||
);
|
||||
}}};
|
||||
PrimOp primop_lineOfPos{
|
||||
{.arity = 1, .fun = [](EvalState & state, Value ** args, Value & v) {
|
||||
v = {NewValueAs::integer, state.ctx.positions[PosIdx(args[0]->integer().value)].line};
|
||||
}}
|
||||
};
|
||||
PrimOp primop_columnOfPos{
|
||||
{.arity = 1, .fun = [](EvalState & state, Value ** args, Value & v) {
|
||||
v = {NewValueAs::integer, state.ctx.positions[PosIdx(args[0]->integer().value)].column};
|
||||
}}
|
||||
};
|
||||
|
||||
Value lineOfPos, columnOfPos;
|
||||
|
||||
@@ -2340,7 +2341,7 @@ static void prim_concatLists(EvalState & state, Value * * args, Value & v)
|
||||
static void prim_length(EvalState & state, Value * * args, Value & v)
|
||||
{
|
||||
state.forceList(*args[0], noPos, "while evaluating the first argument passed to builtins.length");
|
||||
v.mkInt(args[0]->listSize());
|
||||
v = {NewValueAs::integer, NixInt::Inner(args[0]->listSize())};
|
||||
}
|
||||
|
||||
/* Reduce a list by applying a binary operator, from left to
|
||||
@@ -2592,7 +2593,7 @@ static void prim_add(EvalState & state, Value * * args, Value & v)
|
||||
|
||||
auto result_ = i1 + i2;
|
||||
if (auto result = result_.valueChecked(); result.has_value()) {
|
||||
v.mkInt(*result);
|
||||
v = {NewValueAs::integer, *result};
|
||||
} else {
|
||||
state.ctx.errors.make<EvalError>("integer overflow in adding %1% + %2%", i1, i2).debugThrow();
|
||||
}
|
||||
@@ -2616,7 +2617,7 @@ static void prim_sub(EvalState & state, Value * * args, Value & v)
|
||||
auto result_ = i1 - i2;
|
||||
|
||||
if (auto result = result_.valueChecked(); result.has_value()) {
|
||||
v.mkInt(*result);
|
||||
v = {NewValueAs::integer, *result};
|
||||
} else {
|
||||
state.ctx.errors.make<EvalError>("integer overflow in subtracting %1% - %2%", i1, i2).debugThrow();
|
||||
}
|
||||
@@ -2642,7 +2643,7 @@ static void prim_mul(EvalState & state, Value * * args, Value & v)
|
||||
auto result_ = i1 * i2;
|
||||
|
||||
if (auto result = result_.valueChecked(); result.has_value()) {
|
||||
v.mkInt(*result);
|
||||
v = {NewValueAs::integer, *result};
|
||||
} else {
|
||||
state.ctx.errors.make<EvalError>("integer overflow in multiplying %1% * %2%", i1, i2).debugThrow();
|
||||
}
|
||||
@@ -2669,7 +2670,7 @@ static void prim_div(EvalState & state, Value * * args, Value & v)
|
||||
/* Avoid division overflow as it might raise SIGFPE. */
|
||||
auto result_ = i1 / i2;
|
||||
if (auto result = result_.valueChecked(); result.has_value()) {
|
||||
v.mkInt(*result);
|
||||
v = {NewValueAs::integer, *result};
|
||||
} else {
|
||||
state.ctx.errors.make<EvalError>("integer overflow in dividing %1% / %2%", i1, i2).debugThrow();
|
||||
}
|
||||
@@ -2680,7 +2681,7 @@ static void prim_bitAnd(EvalState & state, Value * * args, Value & v)
|
||||
{
|
||||
auto i1 = state.forceInt(*args[0], noPos, "while evaluating the first argument passed to builtins.bitAnd");
|
||||
auto i2 = state.forceInt(*args[1], noPos, "while evaluating the second argument passed to builtins.bitAnd");
|
||||
v.mkInt(i1.value & i2.value);
|
||||
v = {NewValueAs::integer, i1.value & i2.value};
|
||||
}
|
||||
|
||||
static void prim_bitOr(EvalState & state, Value * * args, Value & v)
|
||||
@@ -2688,7 +2689,7 @@ static void prim_bitOr(EvalState & state, Value * * args, Value & v)
|
||||
auto i1 = state.forceInt(*args[0], noPos, "while evaluating the first argument passed to builtins.bitOr");
|
||||
auto i2 = state.forceInt(*args[1], noPos, "while evaluating the second argument passed to builtins.bitOr");
|
||||
|
||||
v.mkInt(i1.value | i2.value);
|
||||
v = {NewValueAs::integer, i1.value | i2.value};
|
||||
}
|
||||
|
||||
static void prim_bitXor(EvalState & state, Value * * args, Value & v)
|
||||
@@ -2696,7 +2697,7 @@ static void prim_bitXor(EvalState & state, Value * * args, Value & v)
|
||||
auto i1 = state.forceInt(*args[0], noPos, "while evaluating the first argument passed to builtins.bitXor");
|
||||
auto i2 = state.forceInt(*args[1], noPos, "while evaluating the second argument passed to builtins.bitXor");
|
||||
|
||||
v.mkInt(i1.value ^ i2.value);
|
||||
v = {NewValueAs::integer, i1.value ^ i2.value};
|
||||
}
|
||||
|
||||
static void prim_lessThan(EvalState & state, Value * * args, Value & v)
|
||||
@@ -2778,7 +2779,7 @@ static void prim_stringLength(EvalState & state, Value * * args, Value & v)
|
||||
{
|
||||
NixStringContext context;
|
||||
auto s = state.coerceToString(noPos, *args[0], context, "while evaluating the argument passed to builtins.stringLength");
|
||||
v.mkInt(NixInt::Inner(s->size()));
|
||||
v = {NewValueAs::integer, NixInt::Inner(s->size())};
|
||||
}
|
||||
|
||||
/* Return the cryptographic hash of a string in base-16. */
|
||||
@@ -3029,7 +3030,7 @@ static void prim_compareVersions(EvalState & state, Value * * args, Value & v)
|
||||
auto version1 = state.forceStringNoCtx(*args[0], noPos, "while evaluating the first argument passed to builtins.compareVersions");
|
||||
auto version2 = state.forceStringNoCtx(*args[1], noPos, "while evaluating the second argument passed to builtins.compareVersions");
|
||||
auto result = compareVersions(version1, version2);
|
||||
v.mkInt(result < 0 ? -1 : result > 0 ? 1 : 0);
|
||||
v = {NewValueAs::integer, result < 0 ? -1 : result > 0 ? 1 : 0};
|
||||
}
|
||||
|
||||
static void prim_splitVersion(EvalState & state, Value * * args, Value & v)
|
||||
|
||||
@@ -97,7 +97,7 @@ void prim_fetchMercurial(EvalState & state, Value ** args, Value & v)
|
||||
attrs2.alloc("rev").mkString(rev2.gitRev());
|
||||
attrs2.alloc("shortRev").mkString(rev2.gitRev().substr(0, 12));
|
||||
if (auto revCount = input2.getRevCount())
|
||||
attrs2.alloc("revCount").mkInt(*revCount);
|
||||
attrs2.alloc("revCount") = {NewValueAs::integer, NixInt::Inner(*revCount)};
|
||||
v = {NewValueAs::attrs, attrs2};
|
||||
|
||||
state.ctx.paths.allowPath(tree.storePath);
|
||||
|
||||
@@ -51,10 +51,9 @@ void emitTreeAttrs(
|
||||
}
|
||||
|
||||
if (auto revCount = input.getRevCount())
|
||||
attrs.alloc("revCount").mkInt(*revCount);
|
||||
attrs.alloc("revCount") = {NewValueAs::integer, NixInt::Inner(*revCount)};
|
||||
else if (emptyRevFallback)
|
||||
attrs.alloc("revCount").mkInt(0);
|
||||
|
||||
attrs.alloc("revCount") = {NewValueAs::integer, 0};
|
||||
}
|
||||
|
||||
if (auto dirtyRev = fetchers::maybeGetStrAttr(input.attrs, "dirtyRev")) {
|
||||
@@ -63,7 +62,7 @@ void emitTreeAttrs(
|
||||
}
|
||||
|
||||
if (auto lastModified = input.getLastModified()) {
|
||||
attrs.alloc("lastModified").mkInt(*lastModified);
|
||||
attrs.alloc("lastModified") = {NewValueAs::integer, *lastModified};
|
||||
attrs.alloc("lastModifiedDate").mkString(
|
||||
fmt("%s", std::put_time(std::gmtime(&*lastModified), "%Y%m%d%H%M%S")));
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ void prim_fromTOML(EvalState & state, Value ** args, Value & val)
|
||||
v.mkBool(toml::get<bool>(t));
|
||||
break;
|
||||
case toml::value_t::integer:
|
||||
v.mkInt(toml::get<int64_t>(t));
|
||||
v = {NewValueAs::integer, toml::get<int64_t>(t)};
|
||||
break;
|
||||
case toml::value_t::floating:
|
||||
v = {NewValueAs::floating, toml::get<NixFloat>(t)};
|
||||
|
||||
+4
-10
@@ -405,6 +405,10 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructs a nix language value of type "int", with the integral value
|
||||
/// of @ref i.
|
||||
Value(integer_t, NixInt::Inner i) : Value(NewValueAs::integer, NixInt{i}) {}
|
||||
|
||||
/// Constructs a nix language value of type "int", with the integral value
|
||||
/// of @ref i.
|
||||
Value(integer_t, NixInt i)
|
||||
@@ -771,16 +775,6 @@ public:
|
||||
*/
|
||||
inline ValueType type(bool invalidIsThunk = false) const;
|
||||
|
||||
inline void mkInt(NixInt::Inner n)
|
||||
{
|
||||
mkInt(NixInt{n});
|
||||
}
|
||||
|
||||
inline void mkInt(NixInt n)
|
||||
{
|
||||
*this = {NewValueAs::integer, n};
|
||||
}
|
||||
|
||||
inline void mkBool(bool b)
|
||||
{
|
||||
raw = tag(tBool, b);
|
||||
|
||||
@@ -33,14 +33,12 @@ namespace nix {
|
||||
}
|
||||
|
||||
TEST_F(JSONValueTest, IntPositive) {
|
||||
Value v;
|
||||
v.mkInt(100);
|
||||
Value v = {NewValueAs::integer, 100};
|
||||
ASSERT_EQ(getJSONValue(v), "100");
|
||||
}
|
||||
|
||||
TEST_F(JSONValueTest, IntNegative) {
|
||||
Value v;
|
||||
v.mkInt(-100);
|
||||
Value v = {NewValueAs::integer, -100};
|
||||
ASSERT_EQ(getJSONValue(v), "-100");
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ struct ValuePrintingTests : LibExprTest
|
||||
|
||||
TEST_F(ValuePrintingTests, tInt)
|
||||
{
|
||||
Value vInt;
|
||||
vInt.mkInt(10);
|
||||
Value vInt = {NewValueAs::integer, 10};
|
||||
test(vInt, "10");
|
||||
}
|
||||
|
||||
@@ -58,11 +57,9 @@ TEST_F(ValuePrintingTests, tNull)
|
||||
|
||||
TEST_F(ValuePrintingTests, tAttrs)
|
||||
{
|
||||
Value vOne;
|
||||
vOne.mkInt(1);
|
||||
Value vOne = {NewValueAs::integer, 1};
|
||||
|
||||
Value vTwo;
|
||||
vTwo.mkInt(2);
|
||||
Value vTwo = {NewValueAs::integer, 2};
|
||||
|
||||
BindingsBuilder builder = evaluator.buildBindings(10);
|
||||
builder.insert(evaluator.symbols.create("one"), vOne);
|
||||
@@ -75,11 +72,9 @@ TEST_F(ValuePrintingTests, tAttrs)
|
||||
|
||||
TEST_F(ValuePrintingTests, tList)
|
||||
{
|
||||
Value vOne;
|
||||
vOne.mkInt(1);
|
||||
Value vOne = {NewValueAs::integer, 1};
|
||||
|
||||
Value vTwo;
|
||||
vTwo.mkInt(2);
|
||||
Value vTwo = {NewValueAs::integer, 2};
|
||||
|
||||
auto vList = evaluator.mem.newList(5);
|
||||
vList->elems[0] = vOne;
|
||||
@@ -193,14 +188,11 @@ TEST_F(ValuePrintingTests, vBlackhole)
|
||||
|
||||
TEST_F(ValuePrintingTests, depthAttrs)
|
||||
{
|
||||
Value vZero;
|
||||
vZero.mkInt(0);
|
||||
Value vZero = {NewValueAs::integer, 0};
|
||||
|
||||
Value vOne;
|
||||
vOne.mkInt(1);
|
||||
Value vOne = {NewValueAs::integer, 1};
|
||||
|
||||
Value vTwo;
|
||||
vTwo.mkInt(2);
|
||||
Value vTwo = {NewValueAs::integer, 2};
|
||||
|
||||
BindingsBuilder builderEmpty = evaluator.buildBindings(0);
|
||||
Value vAttrsEmpty = {NewValueAs::attrs, builderEmpty.finish()};
|
||||
@@ -232,11 +224,9 @@ TEST_F(ValuePrintingTests, depthAttrs)
|
||||
|
||||
TEST_F(ValuePrintingTests, depthList)
|
||||
{
|
||||
Value vOne;
|
||||
vOne.mkInt(1);
|
||||
Value vOne = {NewValueAs::integer, 1};
|
||||
|
||||
Value vTwo;
|
||||
vTwo.mkInt(2);
|
||||
Value vTwo = {NewValueAs::integer, 2};
|
||||
|
||||
BindingsBuilder builder = evaluator.buildBindings(10);
|
||||
builder.insert(evaluator.symbols.create("one"), vOne);
|
||||
@@ -319,8 +309,7 @@ TEST_F(ValuePrintingTests, attrsTypeFirst)
|
||||
|
||||
TEST_F(ValuePrintingTests, ansiColorsInt)
|
||||
{
|
||||
Value v;
|
||||
v.mkInt(10);
|
||||
Value v = {NewValueAs::integer, 10};
|
||||
|
||||
test(v,
|
||||
ANSI_CYAN "10" ANSI_NORMAL,
|
||||
@@ -402,11 +391,9 @@ TEST_F(ValuePrintingTests, ansiColorsNull)
|
||||
|
||||
TEST_F(ValuePrintingTests, ansiColorsAttrs)
|
||||
{
|
||||
Value vOne;
|
||||
vOne.mkInt(1);
|
||||
Value vOne = {NewValueAs::integer, 1};
|
||||
|
||||
Value vTwo;
|
||||
vTwo.mkInt(2);
|
||||
Value vTwo = {NewValueAs::integer, 2};
|
||||
|
||||
BindingsBuilder builder = evaluator.buildBindings(10);
|
||||
builder.insert(evaluator.symbols.create("one"), vOne);
|
||||
@@ -513,11 +500,9 @@ TEST_F(ValuePrintingTests, ansiColorsAssert)
|
||||
|
||||
TEST_F(ValuePrintingTests, ansiColorsList)
|
||||
{
|
||||
Value vOne;
|
||||
vOne.mkInt(1);
|
||||
Value vOne = {NewValueAs::integer, 1};
|
||||
|
||||
Value vTwo;
|
||||
vTwo.mkInt(2);
|
||||
Value vTwo = {NewValueAs::integer, 2};
|
||||
|
||||
auto vList = evaluator.mem.newList(5);
|
||||
vList->elems[0] = vOne;
|
||||
@@ -622,8 +607,7 @@ TEST_F(ValuePrintingTests, ansiColorsBlackhole)
|
||||
|
||||
TEST_F(ValuePrintingTests, ansiColorsAttrsRepeated)
|
||||
{
|
||||
Value vZero;
|
||||
vZero.mkInt(0);
|
||||
Value vZero = {NewValueAs::integer, 0};
|
||||
|
||||
BindingsBuilder innerBuilder = evaluator.buildBindings(1);
|
||||
innerBuilder.insert(evaluator.symbols.create("x"), vZero);
|
||||
@@ -645,8 +629,7 @@ TEST_F(ValuePrintingTests, ansiColorsAttrsRepeated)
|
||||
|
||||
TEST_F(ValuePrintingTests, ansiColorsListRepeated)
|
||||
{
|
||||
Value vZero;
|
||||
vZero.mkInt(0);
|
||||
Value vZero = {NewValueAs::integer, 0};
|
||||
|
||||
BindingsBuilder innerBuilder = evaluator.buildBindings(1);
|
||||
innerBuilder.insert(evaluator.symbols.create("x"), vZero);
|
||||
@@ -667,8 +650,7 @@ TEST_F(ValuePrintingTests, ansiColorsListRepeated)
|
||||
|
||||
TEST_F(ValuePrintingTests, listRepeated)
|
||||
{
|
||||
Value vZero;
|
||||
vZero.mkInt(0);
|
||||
Value vZero = {NewValueAs::integer, 0};
|
||||
|
||||
BindingsBuilder innerBuilder = evaluator.buildBindings(1);
|
||||
innerBuilder.insert(evaluator.symbols.create("x"), vZero);
|
||||
@@ -691,11 +673,9 @@ TEST_F(ValuePrintingTests, listRepeated)
|
||||
|
||||
TEST_F(ValuePrintingTests, ansiColorsAttrsElided)
|
||||
{
|
||||
Value vOne;
|
||||
vOne.mkInt(1);
|
||||
Value vOne = {NewValueAs::integer, 1};
|
||||
|
||||
Value vTwo;
|
||||
vTwo.mkInt(2);
|
||||
Value vTwo = {NewValueAs::integer, 2};
|
||||
|
||||
BindingsBuilder builder = evaluator.buildBindings(10);
|
||||
builder.insert(evaluator.symbols.create("one"), vOne);
|
||||
@@ -710,8 +690,7 @@ TEST_F(ValuePrintingTests, ansiColorsAttrsElided)
|
||||
.maxAttrs = 1
|
||||
});
|
||||
|
||||
Value vThree;
|
||||
vThree.mkInt(3);
|
||||
Value vThree = {NewValueAs::integer, 3};
|
||||
|
||||
builder.insert(evaluator.symbols.create("three"), vThree);
|
||||
vAttrs = {NewValueAs::attrs, builder.finish()};
|
||||
@@ -726,11 +705,9 @@ TEST_F(ValuePrintingTests, ansiColorsAttrsElided)
|
||||
|
||||
TEST_F(ValuePrintingTests, ansiColorsListElided)
|
||||
{
|
||||
Value vOne;
|
||||
vOne.mkInt(1);
|
||||
Value vOne = {NewValueAs::integer, 1};
|
||||
|
||||
Value vTwo;
|
||||
vTwo.mkInt(2);
|
||||
Value vTwo = {NewValueAs::integer, 2};
|
||||
|
||||
auto list = evaluator.mem.newList(4);
|
||||
Value vList{NewValueAs::list, list};
|
||||
@@ -745,8 +722,7 @@ TEST_F(ValuePrintingTests, ansiColorsListElided)
|
||||
.maxListItems = 1
|
||||
});
|
||||
|
||||
Value vThree;
|
||||
vThree.mkInt(3);
|
||||
Value vThree = {NewValueAs::integer, 3};
|
||||
|
||||
list->elems[2] = vThree;
|
||||
list->size = 3;
|
||||
|
||||
Reference in New Issue
Block a user