about summary refs log tree commit diff
path: root/tvix/eval/src/compiler/mod.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-16T16·48+0300
committertazjin <tazjin@tvl.su>2022-09-16T18·13+0000
commite86acd32122424f5ca2e8ee630d03991b9f9126b (patch)
tree0dc269b8d03ead60a834dcaebd623637262e2f94 /tvix/eval/src/compiler/mod.rs
parent20230e1e2ddea5fd6e65d6d263444c46dc5e43db (diff)
feat(tvix/eval): implement legacy let syntax r/4877
... and emit a warning if anyone decides to use.

Change-Id: Iaa6fe9fa932340e6d0fa9f357155e78823702576
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6611
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/compiler/mod.rs')
-rw-r--r--tvix/eval/src/compiler/mod.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs
index 90bc263bc8be..713ae2fdb2c7 100644
--- a/tvix/eval/src/compiler/mod.rs
+++ b/tvix/eval/src/compiler/mod.rs
@@ -188,10 +188,7 @@ impl Compiler<'_, '_> {
             // their value on the stack.
             ast::Expr::Paren(paren) => self.compile(slot, paren.expr().unwrap()),
 
-            ast::Expr::LegacyLet(_) => {
-                let span = self.span_for(&expr);
-                self.emit_error(span, ErrorKind::NotImplemented("legacy let syntax"));
-            }
+            ast::Expr::LegacyLet(legacy_let) => self.compile_legacy_let(slot, legacy_let),
 
             ast::Expr::Root(_) => unreachable!("there cannot be more than one root"),
             ast::Expr::Error(_) => unreachable!("compile is only called on validated trees"),
@@ -997,6 +994,17 @@ impl Compiler<'_, '_> {
         self.push_op(OpCode::OpCall, &node);
     }
 
+    fn compile_legacy_let(&mut self, slot: LocalIdx, node: ast::LegacyLet) {
+        self.scope_mut().begin_scope();
+        self.compile_recursive_scope(slot, true, &node);
+        self.push_op(OpCode::OpAttrs(Count(node.entries().count())), &node);
+        self.emit_constant(Value::String(SmolStr::new_inline("body").into()), &node);
+        self.push_op(OpCode::OpAttrsSelect, &node);
+
+        let warning_span = self.span_for(&node);
+        self.emit_warning(warning_span, WarningKind::DeprecatedLegacyLet);
+    }
+
     /// Compile an expression into a runtime thunk which should be
     /// lazily evaluated when accessed.
     // TODO: almost the same as Compiler::compile_lambda; unify?