feat(tvix/eval): add builtins.{floor,ceil}
Change-Id: I4e6c4f96f6f5097a5c637eb3dbbd7bb8b34b7d52 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7032 Autosubmit: j4m3s <james.landrein@gmail.com> Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su> Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
parent
bd0bf6ea7d
commit
8425c2016c
7 changed files with 13 additions and 0 deletions
|
@ -134,6 +134,9 @@ fn pure_builtins() -> Vec<Builtin> {
|
||||||
Ok(Value::List(NixList::construct(output.len(), output)))
|
Ok(Value::List(NixList::construct(output.len(), output)))
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Builtin::new("ceil", &[true], |args: Vec<Value>, _: &mut VM| {
|
||||||
|
Ok(Value::Integer(args[0].as_float()?.ceil() as i64))
|
||||||
|
}),
|
||||||
Builtin::new(
|
Builtin::new(
|
||||||
"compareVersions",
|
"compareVersions",
|
||||||
&[true, true],
|
&[true, true],
|
||||||
|
@ -269,6 +272,9 @@ fn pure_builtins() -> Vec<Builtin> {
|
||||||
.map(|list| Value::List(NixList::from(list)))
|
.map(|list| Value::List(NixList::from(list)))
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}),
|
}),
|
||||||
|
Builtin::new("floor", &[true], |args: Vec<Value>, _: &mut VM| {
|
||||||
|
Ok(Value::Integer(args[0].as_float()?.floor() as i64))
|
||||||
|
}),
|
||||||
Builtin::new(
|
Builtin::new(
|
||||||
"foldl'",
|
"foldl'",
|
||||||
&[true, false, true],
|
&[true, false, true],
|
||||||
|
|
1
tvix/eval/src/tests/tvix_tests/eval-okay-ceil.exp
Normal file
1
tvix/eval/src/tests/tvix_tests/eval-okay-ceil.exp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[ 4 ]
|
1
tvix/eval/src/tests/tvix_tests/eval-okay-ceil.nix
Normal file
1
tvix/eval/src/tests/tvix_tests/eval-okay-ceil.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[ (builtins.ceil 3.4) ]
|
1
tvix/eval/src/tests/tvix_tests/eval-okay-floor.exp
Normal file
1
tvix/eval/src/tests/tvix_tests/eval-okay-floor.exp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[ 3 ]
|
1
tvix/eval/src/tests/tvix_tests/eval-okay-floor.nix
Normal file
1
tvix/eval/src/tests/tvix_tests/eval-okay-floor.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[ (builtins.floor 3.4) ]
|
|
@ -293,6 +293,7 @@ impl Value {
|
||||||
|
|
||||||
gen_cast!(as_bool, bool, "bool", Value::Bool(b), *b);
|
gen_cast!(as_bool, bool, "bool", Value::Bool(b), *b);
|
||||||
gen_cast!(as_int, i64, "int", Value::Integer(x), *x);
|
gen_cast!(as_int, i64, "int", Value::Integer(x), *x);
|
||||||
|
gen_cast!(as_float, f64, "float", Value::Float(x), *x);
|
||||||
gen_cast!(to_str, NixString, "string", Value::String(s), s.clone());
|
gen_cast!(to_str, NixString, "string", Value::String(s), s.clone());
|
||||||
gen_cast!(to_attrs, Rc<NixAttrs>, "set", Value::Attrs(a), a.clone());
|
gen_cast!(to_attrs, Rc<NixAttrs>, "set", Value::Attrs(a), a.clone());
|
||||||
gen_cast!(to_list, NixList, "list", Value::List(l), l.clone());
|
gen_cast!(to_list, NixList, "list", Value::List(l), l.clone());
|
||||||
|
|
|
@ -46,7 +46,9 @@ let
|
||||||
# Ordering change after 2.3
|
# Ordering change after 2.3
|
||||||
"eval-okay-xml.nix" = [ nix ];
|
"eval-okay-xml.nix" = [ nix ];
|
||||||
# Missing builtins in Nix 2.3
|
# Missing builtins in Nix 2.3
|
||||||
|
"eval-okay-ceil.nix" = [ nix ];
|
||||||
"eval-okay-floor-ceil.nix" = [ nix ];
|
"eval-okay-floor-ceil.nix" = [ nix ];
|
||||||
|
"eval-okay-floor.nix" = [ nix ];
|
||||||
"eval-okay-groupBy.nix" = [ nix ];
|
"eval-okay-groupBy.nix" = [ nix ];
|
||||||
"eval-okay-zipAttrsWith.nix" = [ nix ];
|
"eval-okay-zipAttrsWith.nix" = [ nix ];
|
||||||
# Comparable lists are not in Nix 2.3
|
# Comparable lists are not in Nix 2.3
|
||||||
|
|
Loading…
Reference in a new issue