From 80b05779ea40f98450f795e8badbfcb06512897c Mon Sep 17 00:00:00 2001 From: mlokr Date: Sun, 12 May 2024 12:21:40 +0200 Subject: [PATCH] adding struct syntax --- hblang/src/codegen.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index 2851bbc..bb164ed 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -251,7 +251,7 @@ struct Loop { } struct Struct { - name: Rc, + id: Ident, fields: Vec<(Rc, Type)>, } @@ -397,6 +397,18 @@ impl<'a> Codegen<'a> { fn expr(&mut self, expr: &'a parser::Expr<'a>, expeted: Option) -> Option { match *expr { + E::BinOp { + left: E::Ident { id, .. }, + op: T::Decl, + right: E::Struct { fields, .. }, + } => { + let fields = fields + .iter() + .map(|&(name, ty)| (name.into(), self.ty(&ty))) + .collect(); + self.records.push(Struct { id: *id, fields }); + None + } E::UnOp { op: T::Amp, val, .. } => {