feat(tvix/eval): Support builtins.tail

TL;DR:
- support `builtins.tail`
- define `ErrorKind::TailEmptyList` and canonical error code
- support basic unit tests

Unsure whether or not the error should be a dedicated `ErrorKind`...

Change-Id: Iae90fda1bb21ce7bdb1aaa2aeb2b8c1e6dcb0f05
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6545
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
William Carroll 2022-09-05 11:42:53 -07:00 committed by clbot
parent 2fe18e4486
commit fefa8c55c4
4 changed files with 21 additions and 0 deletions

View file

@ -221,6 +221,16 @@ fn pure_builtins() -> Vec<Builtin> {
x.as_str()[(beg as usize)..(end as usize)].into(),
))
}),
Builtin::new("tail", 1, |args, vm| {
let xs = args[0].force(vm)?.to_list()?;
if xs.len() == 0 {
Err(ErrorKind::TailEmptyList)
} else {
let output = xs.into_iter().skip(1).collect::<Vec<_>>();
Ok(Value::List(NixList::construct(output.len(), output)))
}
}),
Builtin::new("throw", 1, |mut args, _| {
return Err(ErrorKind::Throw(
args.pop().unwrap().to_str()?.as_str().to_owned(),