From 645d0c06e541b57cf1b87877856f592c6fbf49ee Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 5 Nov 2022 19:50:31 -0400 Subject: feat(tvix/eval): Add a proc-macro for defining builtins Add a single new proc macro to a new proc-macro crate, `tvix-eval-proc-macros` for defining an inline module containing nix builtins, and automatically generating a function within that module which returns a list of those builtins as `tvix_eval::value::Builtin`. Change-Id: Ie4afae438914d2af93d15637151a49b4c68aa352 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7198 Reviewed-by: tazjin Reviewed-by: Adam Joseph Tested-by: BuildkiteCI --- tvix/eval/builtin-macros/tests/tests.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tvix/eval/builtin-macros/tests/tests.rs (limited to 'tvix/eval/builtin-macros/tests/tests.rs') diff --git a/tvix/eval/builtin-macros/tests/tests.rs b/tvix/eval/builtin-macros/tests/tests.rs new file mode 100644 index 000000000000..8f3e83b672ef --- /dev/null +++ b/tvix/eval/builtin-macros/tests/tests.rs @@ -0,0 +1,26 @@ +use tvix_eval_builtin_macros::builtins; + +mod value { + pub use tvix_eval::Builtin; +} + +#[builtins] +mod builtins { + use tvix_eval::{ErrorKind, Value, VM}; + + #[builtin("identity")] + pub fn builtin_identity(_vm: &mut VM, x: Value) -> Result { + Ok(x) + } + + #[builtin("tryEval")] + pub fn builtin_try_eval(_: &mut VM, #[lazy] _x: Value) -> Result { + todo!() + } +} + +#[test] +fn builtins() { + let builtins = builtins::builtins(); + assert_eq!(builtins.len(), 2); +} -- cgit 1.4.1