diff options
Diffstat (limited to 'tvix/eval/src')
5 files changed, 28 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index a0ada0233c59..1a0443cb6012 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -40,6 +40,11 @@ fn pure_builtins() -> Vec<Builtin> { Ok(Value::List(NixList::construct(output.len(), output))) }), + Builtin::new("div", 2, |mut args| { + let b = args.pop().unwrap(); + let a = args.pop().unwrap(); + Ok(arithmetic_op!(a, b, /)) + }), Builtin::new("isAttrs", 1, |args| { Ok(Value::Bool(matches!(args[0], Value::Attrs(_)))) }), @@ -70,6 +75,11 @@ fn pure_builtins() -> Vec<Builtin> { Builtin::new("isString", 1, |args| { Ok(Value::Bool(matches!(args[0], Value::String(_)))) }), + Builtin::new("mul", 2, |mut args| { + let b = args.pop().unwrap(); + let a = args.pop().unwrap(); + Ok(arithmetic_op!(a, b, *)) + }), Builtin::new("sub", 2, |mut args| { let b = args.pop().unwrap(); let a = args.pop().unwrap(); diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp new file mode 100644 index 000000000000..d71bbb7a060b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp @@ -0,0 +1 @@ +[ 3 7 0 1 0 0.5 0.5 0.5 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix new file mode 100644 index 000000000000..622ce889daa9 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix @@ -0,0 +1,10 @@ +[ + (builtins.div 9 3) + (builtins.div 7 1) + (builtins.div 3 9) + (builtins.div 4 4) + (builtins.div 1 2) + (builtins.div 1.0 2) + (builtins.div 1 2.0) + (builtins.div 1.0 2.0) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mul.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mul.exp new file mode 100644 index 000000000000..5ed8b8e2bd83 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mul.exp @@ -0,0 +1 @@ +[ 36 0 0 14 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mul.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mul.nix new file mode 100644 index 000000000000..5b61e387a622 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mul.nix @@ -0,0 +1,6 @@ +[ + (builtins.mul 4 9) + (builtins.mul 0 7) + (builtins.mul 7 0) + (builtins.mul 7 2) +] |