diff options
author | William Carroll <wpcarro@gmail.com> | 2022-09-06T05·17-0700 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-09-15T21·47+0000 |
commit | 031ca653a34bd0ca7c3c3714239459d4069e6464 (patch) | |
tree | 51c16269ac9a6723349aef2353ff8a4c40ecfb03 | |
parent | f5f6bd319db3b224aa603d5eaa74e1d61f071f50 (diff) |
feat(tvix/eval): Support builtins.bitOr r/4868
Bitwise `or` on integers. Change-Id: I45b0897331d1a9b6840f9d0feedcf10acc67fcec Reviewed-on: https://cl.tvl.fyi/c/depot/+/6549 Autosubmit: wpcarro <wpcarro@gmail.com> Reviewed-by: wpcarro <wpcarro@gmail.com> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 7 | ||||
-rw-r--r-- | tvix/eval/src/tests/tvix_tests/eval-okay-builtins-bitor.exp | 1 | ||||
-rw-r--r-- | tvix/eval/src/tests/tvix_tests/eval-okay-builtins-bitor.nix | 10 |
3 files changed, 18 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 009758fe0f33..ebbc5e336c21 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -108,6 +108,13 @@ fn pure_builtins() -> Vec<Builtin> { }) }) }), + Builtin::new("bitOr", 2, |args, vm| { + force!(vm, &args[0], x, { + force!(vm, &args[1], y, { + Ok(Value::Integer(x.as_int()? | y.as_int()?)) + }) + }) + }), Builtin::new("catAttrs", 2, |mut args, _| { let list = args.pop().unwrap().to_list()?; let key = args.pop().unwrap().to_str()?; diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-bitor.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-bitor.exp new file mode 100644 index 000000000000..2556b4183c77 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-bitor.exp @@ -0,0 +1 @@ +[ 0 1 1 1 8 8 8 8 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-bitor.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-bitor.nix new file mode 100644 index 000000000000..9c28f6d7acee --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-bitor.nix @@ -0,0 +1,10 @@ +[ + (builtins.bitOr 0 0) + (builtins.bitOr 1 0) + (builtins.bitOr 0 1) + (builtins.bitOr 1 1) + (builtins.bitOr 8 8) + (builtins.bitOr 8 (builtins.add 4 4)) + (builtins.bitOr (builtins.add 4 4) 8) + (builtins.bitOr (builtins.add 4 4) (builtins.add 4 4)) +] |