From 9f5f85a1c1fe98e83fa57d58511675818cdb1871 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 1 Sep 2022 17:47:10 +0300 Subject: feat(tvix/eval): track source spans for identifier access Change-Id: I8e6ec0a84430d6e417fc7fd3e722a588913e4d18 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6394 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/compiler/mod.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'tvix/eval/src') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 21b2367616..fa4c56d493 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -772,7 +772,7 @@ impl Compiler<'_> { LocalPosition::Unknown => { // Are we possibly dealing with an upvalue? if let Some(idx) = self.resolve_upvalue(self.contexts.len() - 1, ident.text()) { - self.push_op_old(OpCode::OpGetUpvalue(idx)); + self.push_op(OpCode::OpGetUpvalue(idx), &node); return; } @@ -784,12 +784,12 @@ impl Compiler<'_> { // `with`-stack. This means we need to resolve // both in this scope, and in the upvalues. if self.scope().has_with() { - self.emit_constant_old(Value::String(ident.text().into())); - self.push_op_old(OpCode::OpResolveWithOrUpvalue(idx)); + self.emit_literal_ident(&node); + self.push_op(OpCode::OpResolveWithOrUpvalue(idx), &node); return; } - self.push_op_old(OpCode::OpGetUpvalue(idx)); + self.push_op(OpCode::OpGetUpvalue(idx), &node); return; } @@ -800,13 +800,13 @@ impl Compiler<'_> { // Variable needs to be dynamically resolved at // runtime. - self.emit_constant_old(Value::String(ident.text().into())); - self.push_op_old(OpCode::OpResolveWith); + self.emit_literal_ident(&node); + self.push_op(OpCode::OpResolveWith, &node); } LocalPosition::Known(idx) => { let stack_idx = self.scope().stack_index(idx); - self.push_op_old(OpCode::OpGetLocal(stack_idx)); + self.push_op(OpCode::OpGetLocal(stack_idx), &node); } // This identifier is referring to a value from the same @@ -815,9 +815,7 @@ impl Compiler<'_> { LocalPosition::Recursive(idx) => self.thunk(slot, move |compiler, _| { let upvalue_idx = compiler.add_upvalue(compiler.contexts.len() - 1, Upvalue::Local(idx)); - compiler - .chunk() - .push_op_old(OpCode::OpGetUpvalue(upvalue_idx)); + compiler.push_op(OpCode::OpGetUpvalue(upvalue_idx), &node); }), }; } -- cgit 1.4.1