From 418fd0039eda7fd4052c8086373b1e1257d573c8 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 21 Dec 2024 17:36:42 +0100 Subject: [PATCH] making the pointered arrays work properly Signed-off-by: Jakub Doka --- lang/README.md | 9 ++++++++ lang/src/fmt.rs | 4 ++-- lang/src/son.rs | 33 ++++++++++++--------------- lang/tests/son_tests_string_array.txt | 8 +++++++ smh.hb | 0 5 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 lang/tests/son_tests_string_array.txt create mode 100644 smh.hb diff --git a/lang/README.md b/lang/README.md index cf3e655..43c5505 100644 --- a/lang/README.md +++ b/lang/README.md @@ -721,6 +721,15 @@ main := fn(): uint { ### Incomplete Examples +#### string_array +```hb +strings := (^u8).["abcdefshijklmnop\0", "abcdefghijklnnop\0", "abcdefshijklmnop\0", "abcdefghijklmnop\0", "abcdefghijflmnop\0", "dbcdefghijklmnop\0", "abcdefghijklmnop\0"] + +main := fn(): uint { + return @bitcast(strings[0]) +} +``` + #### comptime_pointers ```hb main := fn(): uint { diff --git a/lang/src/fmt.rs b/lang/src/fmt.rs index 7bf14a9..97a287a 100644 --- a/lang/src/fmt.rs +++ b/lang/src/fmt.rs @@ -372,7 +372,7 @@ impl<'a> Formatter<'a> { ), Expr::Ctor { ty, fields, trailing_comma, .. } => { if let Some(ty) = ty { - self.fmt_paren(ty, f, unary)?; + self.fmt_paren(ty, f, postfix)?; } f.write_str(".{")?; self.fmt_list( @@ -409,7 +409,7 @@ impl<'a> Formatter<'a> { ), Expr::List { ty, kind: term, fields, trailing_comma, .. } => { if let Some(ty) = ty { - self.fmt_paren(ty, f, unary)?; + self.fmt_paren(ty, f, postfix)?; } let (start, end) = match term { ListKind::Tuple => (".(", ")"), diff --git a/lang/src/son.rs b/lang/src/son.rs index f9242fa..868e817 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -845,27 +845,21 @@ impl<'a> Codegen<'a> { } Expr::Ident { id, .. } if let Some(vl) = { - let mut piter = self.ci.parent; let f = self.file(); - loop { - if let Some((captures, capture_tuple)) = self.tys.captures_of(piter, f) - && let Some(idx) = captures.iter().position(|&cid| cid.id == id) - { - if captures[idx].is_ct { - let ty = self.tys.ins.args[capture_tuple.range().start + idx]; - break Some(self.ci.nodes.new_const_lit(ty::Id::TYPE, ty)); - } else { - break Some( - Value::new(NEVER) - .ty(self.tys.ins.args[capture_tuple.range().start + idx]), - ); - } + if let Some((captures, capture_tuple)) = self.tys.captures_of(self.ci.parent, f) + && let Some(idx) = captures.iter().position(|&cid| cid.id == id) + { + if captures[idx].is_ct { + let ty = self.tys.ins.args[capture_tuple.range().start + idx]; + Some(self.ci.nodes.new_const_lit(ty::Id::TYPE, ty)) + } else { + Some( + Value::new(NEVER) + .ty(self.tys.ins.args[capture_tuple.range().start + idx]), + ) } - - piter = match self.tys.parent_of(piter) { - Some(p) => p, - None => break None, - }; + } else { + None } } => { @@ -4350,6 +4344,7 @@ mod tests { fb_driver; // Purely Testing Examples; + string_array; proper_ident_propagation; method_receiver_by_value; comparing_floating_points; diff --git a/lang/tests/son_tests_string_array.txt b/lang/tests/son_tests_string_array.txt new file mode 100644 index 0000000..bd54d44 --- /dev/null +++ b/lang/tests/son_tests_string_array.txt @@ -0,0 +1,8 @@ +main: + LRA r13, r0, :strings + LD r13, r13, 0a, 8h + CP r1, r13 + JALA r0, r31, 0a +code size: 98 +ret: 134998808175692 +status: Ok(()) diff --git a/smh.hb b/smh.hb new file mode 100644 index 0000000..e69de29