From a43c7b8d4f0a1dbbc8225b15ef45bce77453019a Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 29 Mar 2020 14:10:06 +0800 Subject: [PATCH] support assignments --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index 428c3166c..e03e88d1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -219,6 +219,21 @@ impl<'ctx> CodeGen<'ctx> { use ast::StatementType::*; match &statement.node { + Assign { targets, value } => { + let value = self.compile_expression(value)?; + for target in targets.iter() { + self.set_source_location(target.location); + if let ast::ExpressionType::Identifier { name } = &target.node { + if let Some(existing) = self.namespace.insert(name.clone(), value) { + if existing.get_type() != value.get_type() { + return Err(self.compile_error(CompileErrorKind::IncompatibleTypes)); + } + } + } else { + return Err(self.compile_error(CompileErrorKind::Unsupported("assignment target must be an identifier"))) + } + } + } Return { value: Some(value) } => { if let Some(return_type) = return_type { let value = self.compile_expression(value)?;