making the pointered arrays work properly

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-21 17:36:42 +01:00
parent d220823d78
commit 418fd0039e
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
5 changed files with 33 additions and 21 deletions

View file

@ -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 {

View file

@ -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 => (".(", ")"),

View file

@ -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;

View file

@ -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(())

0
smh.hb Normal file
View file