forked from AbleOS/holey-bytes
making the pointered arrays work properly
Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
parent
d220823d78
commit
418fd0039e
|
@ -721,6 +721,15 @@ main := fn(): uint {
|
||||||
|
|
||||||
### Incomplete Examples
|
### 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
|
#### comptime_pointers
|
||||||
```hb
|
```hb
|
||||||
main := fn(): uint {
|
main := fn(): uint {
|
||||||
|
|
|
@ -372,7 +372,7 @@ impl<'a> Formatter<'a> {
|
||||||
),
|
),
|
||||||
Expr::Ctor { ty, fields, trailing_comma, .. } => {
|
Expr::Ctor { ty, fields, trailing_comma, .. } => {
|
||||||
if let Some(ty) = ty {
|
if let Some(ty) = ty {
|
||||||
self.fmt_paren(ty, f, unary)?;
|
self.fmt_paren(ty, f, postfix)?;
|
||||||
}
|
}
|
||||||
f.write_str(".{")?;
|
f.write_str(".{")?;
|
||||||
self.fmt_list(
|
self.fmt_list(
|
||||||
|
@ -409,7 +409,7 @@ impl<'a> Formatter<'a> {
|
||||||
),
|
),
|
||||||
Expr::List { ty, kind: term, fields, trailing_comma, .. } => {
|
Expr::List { ty, kind: term, fields, trailing_comma, .. } => {
|
||||||
if let Some(ty) = ty {
|
if let Some(ty) = ty {
|
||||||
self.fmt_paren(ty, f, unary)?;
|
self.fmt_paren(ty, f, postfix)?;
|
||||||
}
|
}
|
||||||
let (start, end) = match term {
|
let (start, end) = match term {
|
||||||
ListKind::Tuple => (".(", ")"),
|
ListKind::Tuple => (".(", ")"),
|
||||||
|
|
|
@ -845,27 +845,21 @@ impl<'a> Codegen<'a> {
|
||||||
}
|
}
|
||||||
Expr::Ident { id, .. }
|
Expr::Ident { id, .. }
|
||||||
if let Some(vl) = {
|
if let Some(vl) = {
|
||||||
let mut piter = self.ci.parent;
|
|
||||||
let f = self.file();
|
let f = self.file();
|
||||||
loop {
|
if let Some((captures, capture_tuple)) = self.tys.captures_of(self.ci.parent, f)
|
||||||
if let Some((captures, capture_tuple)) = self.tys.captures_of(piter, f)
|
&& let Some(idx) = captures.iter().position(|&cid| cid.id == id)
|
||||||
&& let Some(idx) = captures.iter().position(|&cid| cid.id == id)
|
{
|
||||||
{
|
if captures[idx].is_ct {
|
||||||
if captures[idx].is_ct {
|
let ty = self.tys.ins.args[capture_tuple.range().start + idx];
|
||||||
let ty = self.tys.ins.args[capture_tuple.range().start + idx];
|
Some(self.ci.nodes.new_const_lit(ty::Id::TYPE, ty))
|
||||||
break Some(self.ci.nodes.new_const_lit(ty::Id::TYPE, ty));
|
} else {
|
||||||
} else {
|
Some(
|
||||||
break Some(
|
Value::new(NEVER)
|
||||||
Value::new(NEVER)
|
.ty(self.tys.ins.args[capture_tuple.range().start + idx]),
|
||||||
.ty(self.tys.ins.args[capture_tuple.range().start + idx]),
|
)
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
piter = match self.tys.parent_of(piter) {
|
None
|
||||||
Some(p) => p,
|
|
||||||
None => break None,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
} =>
|
} =>
|
||||||
{
|
{
|
||||||
|
@ -4350,6 +4344,7 @@ mod tests {
|
||||||
fb_driver;
|
fb_driver;
|
||||||
|
|
||||||
// Purely Testing Examples;
|
// Purely Testing Examples;
|
||||||
|
string_array;
|
||||||
proper_ident_propagation;
|
proper_ident_propagation;
|
||||||
method_receiver_by_value;
|
method_receiver_by_value;
|
||||||
comparing_floating_points;
|
comparing_floating_points;
|
||||||
|
|
8
lang/tests/son_tests_string_array.txt
Normal file
8
lang/tests/son_tests_string_array.txt
Normal 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(())
|
Loading…
Reference in a new issue