From 9b0127f961cb27f6f40d02ff7c74a7fba913678b Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 19 Apr 2025 12:41:47 +0300 Subject: [PATCH] lookup variables --- src/twopass.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/twopass.rs b/src/twopass.rs index a8ec575..5a6cc04 100644 --- a/src/twopass.rs +++ b/src/twopass.rs @@ -124,7 +124,21 @@ impl BuildContext<'_> { } fn lookup(scope: &BuildContext<'_>, loc: &ast::Location) -> Location { - todo!() + match loc { + ast::Location::Variable { name } => { + if let Some(id) = scope.request(name) { + return Location::Variable { id }; + }; + let env = scope + .request(&"_ENV".into()) + .expect("_ENV must be always available"); + Location::Field { + table: Box::new(Location::Variable { id: env }), + index: Box::new(Expression::Constant(ast::Constant::String(name.clone()))), + } + } + ast::Location::Field { table, index } => todo!(), + } } fn build_expression(scope: &BuildContext<'_>, code: &ast::Expression) -> Expression {