From 4b3b6af70eb84d513b9fa926dd8c36e1dba88713 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Fri, 20 Dec 2024 11:59:21 +0100 Subject: [PATCH] adding habdler for tuples with known type Signed-off-by: Jakub Doka --- lang/src/son.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lang/src/son.rs b/lang/src/son.rs index 9e361e95..862166d6 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -1151,9 +1151,11 @@ impl<'a> Codegen<'a> { Some(Value::new(self.gen_null_check(cmped, ty, op)).ty(ty::Id::BOOL)) } - Expr::BinOp { left, pos, op, right } - if !matches!(op, TokenKind::Assign | TokenKind::Decl) => - { + Expr::BinOp { left, pos, op, right } => { + debug_assert!(!matches!( + op, + TokenKind::Assign | TokenKind::Decl | TokenKind::Colon + )); let mut lhs = self.ptr_expr_ctx(left, ctx)?; self.implicit_unwrap(left.pos(), &mut lhs); @@ -1768,6 +1770,25 @@ impl<'a> Codegen<'a> { Some(Value::ptr(mem).ty(aty)) } + (Some(ty::Kind::Tuple(tupl)), ListKind::Tuple) => { + let mem = self.new_stack(pos, tupl.into()); + let mut offs = OffsetIter::new(tupl, self.tys); + for field in fields { + let Some((ty, offset)) = offs.next_ty(self.tys) else { + self.error( + field.pos(), + "this init argumen overflows the field count", + ); + break; + }; + + let value = self.checked_expr(field, ty, "tuple field")?; + let mem = self.offset(mem, offset); + self.store_mem(mem, ty, value.id); + } + + Some(Value::ptr(mem).ty(tupl.into())) + } (Some(t), ListKind::Tuple) => self.error( pos, fa!(