From cc0692a34cd1ecea3ec806198cdf56e98482b5c2 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Mon, 9 Aug 2021 16:19:20 +0800 Subject: [PATCH] modified alloca --- nac3core/src/codegen/stmt.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nac3core/src/codegen/stmt.rs b/nac3core/src/codegen/stmt.rs index 897cf1b7..b66825cd 100644 --- a/nac3core/src/codegen/stmt.rs +++ b/nac3core/src/codegen/stmt.rs @@ -9,12 +9,8 @@ use rustpython_parser::ast::{Expr, ExprKind, Stmt, StmtKind}; impl<'ctx> CodeGenContext<'ctx> { fn gen_var(&mut self, ty: Type) -> PointerValue<'ctx> { + // should we build the alloca in an initial block? let ty = self.get_llvm_type(ty); - let ty = if let BasicTypeEnum::PointerType(ty) = ty { - ty.get_element_type().try_into().unwrap() - } else { - ty - }; self.builder.build_alloca(ty, "tmp") } @@ -76,6 +72,12 @@ impl<'ctx> CodeGenContext<'ctx> { StmtKind::Expr { value } => { self.gen_expr(&value); } + StmtKind::AnnAssign { target, value, .. } => { + if let Some(value) = value { + let value = self.gen_expr(&value); + self.gen_assignment(target, value); + } + } StmtKind::Assign { targets, value, .. } => { let value = self.gen_expr(&value); for target in targets.iter() {