diff --git a/lang/README.md b/lang/README.md index cf3e655b..43c55052 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 7bf14a99..97a287a0 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 f9242fa5..868e8173 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 00000000..bd54d443 --- /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 00000000..e69de29b