feat(tvix/eval): Support builtins.{mul,div}

Multiplication and division :)

Change-Id: I79e76f3b55b7e9b8d1eb09b3d9741140b4d75742
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6406
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
William Carroll 2022-08-29 17:31:47 -07:00 committed by tazjin
parent b3097de75d
commit 15e2bc54f1
5 changed files with 28 additions and 0 deletions

View file

@ -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();

View file

@ -0,0 +1 @@
[ 3 7 0 1 0 0.5 0.5 0.5 ]

View file

@ -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)
]

View file

@ -0,0 +1 @@
[ 36 0 0 14 ]

View file

@ -0,0 +1,6 @@
[
(builtins.mul 4 9)
(builtins.mul 0 7)
(builtins.mul 7 0)
(builtins.mul 7 2)
]