1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 22:01:15 +02:00

Merge pull request #2157 from volth/bitwise

add builtins: __bitAnd,  __bitOr,  __bitXor
This commit is contained in:
Eelco Dolstra 2018-05-24 15:00:39 +02:00 committed by GitHub
commit 743359bc8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 1 deletions

View file

@ -1676,6 +1676,20 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
}
}
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));
}
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));
}
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));
}
static void prim_lessThan(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
@ -2221,6 +2235,9 @@ void EvalState::createBaseEnv()
addPrimOp("__sub", 2, prim_sub);
addPrimOp("__mul", 2, prim_mul);
addPrimOp("__div", 2, prim_div);
addPrimOp("__bitAnd", 2, prim_bitAnd);
addPrimOp("__bitOr", 2, prim_bitOr);
addPrimOp("__bitXor", 2, prim_bitXor);
addPrimOp("__lessThan", 2, prim_lessThan);
// String manipulation