2023-01-13 12:18:01 +01:00
|
|
|
pub use tvix_eval::{Builtin, BuiltinArgument, Value, VM};
|
2022-11-06 00:50:31 +01:00
|
|
|
use tvix_eval_builtin_macros::builtins;
|
|
|
|
|
|
|
|
#[builtins]
|
|
|
|
mod builtins {
|
2023-01-13 12:18:01 +01:00
|
|
|
use tvix_eval::{ErrorKind, Value, VM};
|
2022-11-06 00:50:31 +01:00
|
|
|
|
2022-12-19 11:23:51 +01:00
|
|
|
/// Test docstring.
|
|
|
|
///
|
|
|
|
/// It has multiple lines!
|
2022-11-06 00:50:31 +01:00
|
|
|
#[builtin("identity")]
|
|
|
|
pub fn builtin_identity(_vm: &mut VM, x: Value) -> Result<Value, ErrorKind> {
|
|
|
|
Ok(x)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[builtin("tryEval")]
|
|
|
|
pub fn builtin_try_eval(_: &mut VM, #[lazy] _x: Value) -> Result<Value, ErrorKind> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn builtins() {
|
|
|
|
let builtins = builtins::builtins();
|
|
|
|
assert_eq!(builtins.len(), 2);
|
2022-11-06 16:46:56 +01:00
|
|
|
|
2023-01-13 12:18:01 +01:00
|
|
|
let (_, identity) = builtins
|
|
|
|
.iter()
|
|
|
|
.find(|(name, _)| *name == "identity")
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match identity {
|
|
|
|
Value::Builtin(identity) => assert_eq!(
|
|
|
|
identity.documentation(),
|
|
|
|
Some(
|
|
|
|
r#" Test docstring.
|
2022-12-19 11:23:51 +01:00
|
|
|
|
|
|
|
It has multiple lines!"#
|
2023-01-13 12:18:01 +01:00
|
|
|
)
|
|
|
|
),
|
|
|
|
|
|
|
|
_ => panic!("builtin was not a builtin"),
|
|
|
|
}
|
2022-11-06 00:50:31 +01:00
|
|
|
}
|