about summary refs log tree commit diff
path: root/tvix/eval/builtin-macros/tests/tests.rs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-11-05T23·50-0400
committergrfn <grfn@gws.fyi>2022-11-08T13·42+0000
commit645d0c06e541b57cf1b87877856f592c6fbf49ee (patch)
tree80aaa76e2e724fabc5b7614bb03735b7d41dd0d2 /tvix/eval/builtin-macros/tests/tests.rs
parentcf82a545eb68b57ceb940ebd467e669ca19d7483 (diff)
feat(tvix/eval): Add a proc-macro for defining builtins r/5263
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 <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/builtin-macros/tests/tests.rs')
-rw-r--r--tvix/eval/builtin-macros/tests/tests.rs26
1 files changed, 26 insertions, 0 deletions
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<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);
+}