mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Merge 4eed1b32d9
into 42ea2724a8
This commit is contained in:
commit
4c0c4d102f
3 changed files with 50 additions and 0 deletions
6
doc/manual/rl-next/bit-shift-builtins.md
Normal file
6
doc/manual/rl-next/bit-shift-builtins.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
synopsis: Add bit shifting built-ins
|
||||||
|
issues: [13000]
|
||||||
|
---
|
||||||
|
|
||||||
|
Added left and right bit shifting built-ins.
|
|
@ -534,6 +534,16 @@ namespace nix {
|
||||||
ASSERT_THAT(v, IsIntEq(1));
|
ASSERT_THAT(v, IsIntEq(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, bitShiftLeft) {
|
||||||
|
auto v = eval("builtins.bitShiftLeft 3 2");
|
||||||
|
ASSERT_THAT(v, IsIntEq(12));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, bitShiftRight) {
|
||||||
|
auto v = eval("builtins.bitShiftRight 17 3");
|
||||||
|
ASSERT_THAT(v, IsIntEq(2));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(PrimOpTest, lessThanFalse) {
|
TEST_F(PrimOpTest, lessThanFalse) {
|
||||||
auto v = eval("builtins.lessThan 3 1");
|
auto v = eval("builtins.lessThan 3 1");
|
||||||
ASSERT_THAT(v, IsFalse());
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
|
|
@ -4083,6 +4083,40 @@ static RegisterPrimOp primop_bitXor({
|
||||||
.fun = prim_bitXor,
|
.fun = prim_bitXor,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static void prim_bitShiftLeft(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
|
{
|
||||||
|
auto i1 = state.forceInt(*args[0], pos, "while evaluating the first argument passed to builtins.bitShiftLeft");
|
||||||
|
auto i2 = state.forceInt(*args[1], pos, "while evaluating the second argument passed to builtins.bitShiftLeft");
|
||||||
|
|
||||||
|
v.mkInt(i1.value << i2.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static RegisterPrimOp primop_bitShiftLeft({
|
||||||
|
.name = "__bitShiftLeft",
|
||||||
|
.args = {"e1", "e2"},
|
||||||
|
.doc = R"(
|
||||||
|
Return the integer *e1* shifted left by *e2*.
|
||||||
|
)",
|
||||||
|
.fun = prim_bitShiftLeft,
|
||||||
|
});
|
||||||
|
|
||||||
|
static void prim_bitShiftRight(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
|
{
|
||||||
|
auto i1 = state.forceInt(*args[0], pos, "while evaluating the first argument passed to builtins.bitShiftRight");
|
||||||
|
auto i2 = state.forceInt(*args[1], pos, "while evaluating the second argument passed to builtins.bitShiftRight");
|
||||||
|
|
||||||
|
v.mkInt(i1.value >> i2.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static RegisterPrimOp primop_bitShiftRight({
|
||||||
|
.name = "__bitShiftRight",
|
||||||
|
.args = {"e1", "e2"},
|
||||||
|
.doc = R"(
|
||||||
|
Return the integer *e1* shifted right by *e2*.
|
||||||
|
)",
|
||||||
|
.fun = prim_bitShiftRight,
|
||||||
|
});
|
||||||
|
|
||||||
static void prim_lessThan(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_lessThan(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
state.forceValue(*args[0], pos);
|
state.forceValue(*args[0], pos);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue