From 337d626f0024fe0aa732acf6c0f595a327f2a468 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 17 Sep 2022 19:08:02 +0300 Subject: refactor(tvix/eval): clean up implementation of `compile_literal` Suggested by sterni in cl/6231 Change-Id: I58bbc8a922d360ea79a4dacb76cf8aa1fad93757 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6622 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/compiler/mod.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'tvix/eval/src/compiler') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 0322733676a2..52b6e8e542ee 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -190,20 +190,17 @@ impl Compiler<'_, '_> { } fn compile_literal(&mut self, node: ast::Literal) { - match node.kind() { - ast::LiteralKind::Float(f) => { - self.emit_constant(Value::Float(f.value().unwrap()), &node); - } - - ast::LiteralKind::Integer(i) => { - self.emit_constant(Value::Integer(i.value().unwrap()), &node); - } + let value = match node.kind() { + ast::LiteralKind::Float(f) => Value::Float(f.value().unwrap()), + ast::LiteralKind::Integer(i) => Value::Integer(i.value().unwrap()), ast::LiteralKind::Uri(u) => { self.emit_warning(&node, WarningKind::DeprecatedLiteralURL); - self.emit_constant(Value::String(u.syntax().text().into()), &node); + Value::String(u.syntax().text().into()) } - } + }; + + self.emit_constant(value, &node); } fn compile_path(&mut self, node: ast::Path) { -- cgit 1.4.1