From 562c50fadd5e439eeed4039eb9dc119b07fe8722 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 10 Oct 2022 19:16:30 -0400 Subject: feat(tvix/eval): Implement builtins.trace This is currently implemented with a simple println inline, but in the future we could hook into this via something pluggable on the VM. Change-Id: Idd9cc3b34aa13d6ebc64c02aade81ecdf439656a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6938 Autosubmit: grfn Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/builtins/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tvix/eval/src/builtins') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 1fc833641766..c603264c1e27 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -431,6 +431,18 @@ fn pure_builtins() -> Vec { Builtin::new("throw", &[true], |args: Vec, _: &mut VM| { Err(ErrorKind::Throw(args[0].to_str()?.to_string())) }), + Builtin::new( + "trace", + &[true, true], + |mut args: Vec, _: &mut VM| { + let value = args.pop().unwrap(); + let trace_value = args.pop().unwrap(); + // TODO(grfn): `trace` should be pluggable and capturable, probably via a method on + // the VM + println!("trace: {} :: {}", trace_value, trace_value.type_of()); + Ok(value) + }, + ), Builtin::new("tryEval", &[false], |args: Vec, vm: &mut VM| { let mut res = BTreeMap::new(); match args[0].force(vm) { -- cgit 1.4.1