From 5b98ece96b86f87723747d4b750a6aa64663cd90 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 24 Aug 2022 17:21:26 +0300 Subject: feat(tvix/eval): implement type-checking builtins Change-Id: I70d7d837beaaed7e10cdc7577d96130f9e1b6d39 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6260 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/builtins/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tvix') 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 { 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(), -- cgit 1.4.1