diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-24T14·21+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-02T12·59+0000 |
commit | 5b98ece96b86f87723747d4b750a6aa64663cd90 (patch) | |
tree | d4db2b1d4af707545c16b693c7ac0d230d084944 /tvix/eval/src/builtins/mod.rs | |
parent | bd0fc69f0702d5682ea7fcba6c39a7dc09891368 (diff) |
feat(tvix/eval): implement type-checking builtins r/4594
Change-Id: I70d7d837beaaed7e10cdc7577d96130f9e1b6d39 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6260 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index a856538f0d8a..594263edb468 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -20,9 +20,37 @@ fn pure_builtins() -> Vec<Builtin> { ErrorKind::Abort(args.pop().unwrap().to_string()?.as_str().to_owned()).into(), ); }), + Builtin::new("isAttrs", 1, |args| { + Ok(Value::Bool(matches!(args[0], Value::Attrs(_)))) + }), + Builtin::new("isBool", 1, |args| { + Ok(Value::Bool(matches!(args[0], Value::Bool(_)))) + }), + Builtin::new("isFloat", 1, |args| { + Ok(Value::Bool(matches!(args[0], Value::Float(_)))) + }), + Builtin::new("isFunction", 1, |args| { + Ok(Value::Bool(match args[0] { + Value::Lambda(_) => true, + Value::Builtin(_) => true, + _ => false, + })) + }), + Builtin::new("isInt", 1, |args| { + Ok(Value::Bool(matches!(args[0], Value::Integer(_)))) + }), + Builtin::new("isList", 1, |args| { + Ok(Value::Bool(matches!(args[0], Value::List(_)))) + }), Builtin::new("isNull", 1, |args| { Ok(Value::Bool(matches!(args[0], Value::Null))) }), + Builtin::new("isPath", 1, |args| { + Ok(Value::Bool(matches!(args[0], Value::Path(_)))) + }), + Builtin::new("isString", 1, |args| { + Ok(Value::Bool(matches!(args[0], Value::String(_)))) + }), Builtin::new("throw", 1, |mut args| { return Err( ErrorKind::Throw(args.pop().unwrap().to_string()?.as_str().to_owned()).into(), |