maybe now the bug is fixed

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-22 17:01:36 +01:00
parent 939d0807fb
commit 9f67b22aa2
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
3 changed files with 52 additions and 46 deletions

View file

@ -704,6 +704,14 @@ impl<'a> Codegen<'a> {
); );
debug_assert!(self.ci.nodes[region].kind != Kind::Stre); debug_assert!(self.ci.nodes[region].kind != Kind::Stre);
debug_assert!(
self.ci.nodes[region].kind != Kind::Stck
|| self.tys.size_of(self.ci.nodes[region].ty) >= self.tys.size_of(ty),
"{} {}",
self.ty_display(self.ci.nodes[region].ty),
self.ty_display(ty)
);
let (value_index, value_region) = self.ci.nodes.aclass_index(value); let (value_index, value_region) = self.ci.nodes.aclass_index(value);
if value_index != 0 { if value_index != 0 {
self.ci.nodes[value_region].aclass = 0; self.ci.nodes[value_region].aclass = 0;
@ -1260,7 +1268,7 @@ impl<'a> Codegen<'a> {
} }
} }
Expr::Index { base, index: &Expr::Range { start, end, pos } } => { Expr::Index { base, index: &Expr::Range { start, end, pos } } => {
let mut bs = self.ptr_expr(base)?; let bs = self.ptr_expr(base)?;
let start = match start { let start = match start {
Some(s) => self.checked_expr(s, ty::Id::UINT, "range start")?.id, Some(s) => self.checked_expr(s, ty::Id::UINT, "range start")?.id,
@ -1298,14 +1306,7 @@ impl<'a> Codegen<'a> {
let elem = match bs.ty.expand() { let elem = match bs.ty.expand() {
ty::Kind::Slice(s) => self.tys.ins.slices[s].elem, ty::Kind::Slice(s) => self.tys.ins.slices[s].elem,
ty::Kind::Ptr(_) => { ty::Kind::Ptr(_) => self.tys.base_of(bs.ty).unwrap_or(bs.ty),
if let Some(base) = self.tys.base_of(bs.ty) {
bs.ptr = true;
bs.ty = base;
}
bs.ty
}
_ => { _ => {
return self.error( return self.error(
base.pos(), base.pos(),
@ -1317,10 +1318,9 @@ impl<'a> Codegen<'a> {
} }
}; };
let ptr = match bs.ty.expand() { let mut ptr = match bs.ty.expand() {
ty::Kind::Slice(s) if let Some(_) = self.tys.ins.slices[s].len() => bs, ty::Kind::Slice(s) if let Some(_) = self.tys.ins.slices[s].len() => bs,
ty::Kind::Slice(_) => { ty::Kind::Slice(_) => {
// Might change
let off = self.offset(bs.id, SLICE_PTR_OFF); let off = self.offset(bs.id, SLICE_PTR_OFF);
let base = self.tys.make_ptr(elem); let base = self.tys.make_ptr(elem);
Value::new(self.load_mem(off, base)).ty(base) Value::new(self.load_mem(off, base)).ty(base)
@ -1328,15 +1328,23 @@ impl<'a> Codegen<'a> {
ty::Kind::Ptr(_) => bs, ty::Kind::Ptr(_) => bs,
_ => unreachable!(), _ => unreachable!(),
}; };
ptr.id = self.offset_ptr(ptr.id, elem, start).id;
ptr.ty = self.tys.make_ptr(elem);
self.ci.nodes.lock(ptr.id); self.ci.nodes.lock(ptr.id);
let ty = self.tys.make_array(elem, ArrayLen::MAX); let ty = self.tys.make_array(elem, ArrayLen::MAX);
let mem = self.new_stack(pos, ty); let mem = self.new_stack(pos, ty);
for (off, value) in [(SLICE_PTR_OFF, ptr), (SLICE_LEN_OFF, len)] {
let region = self.offset(mem, off); let (off, value) = (SLICE_PTR_OFF, ptr);
self.store_mem(region, value.ty, value.id); let region = self.offset(mem, off);
} self.store_mem(region, value.ty, value.id);
let (off, value) = (SLICE_LEN_OFF, len);
let region = self.offset(mem, off);
self.store_mem(region, value.ty, value.id);
self.ci.nodes.unlock(start); self.ci.nodes.unlock(start);
self.ci.nodes.unlock(len.id); self.ci.nodes.unlock(len.id);
self.ci.nodes.unlock(end); self.ci.nodes.unlock(end);
@ -4384,7 +4392,7 @@ mod tests {
fn generate(ident: &'static str, input: &'static str, output: &mut String) { fn generate(ident: &'static str, input: &'static str, output: &mut String) {
_ = log::set_logger(&crate::fs::Logger); _ = log::set_logger(&crate::fs::Logger);
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Info);
log::set_max_level(log::LevelFilter::Trace); //log::set_max_level(log::LevelFilter::Trace);
let mut ctx = CodegenCtx::default(); let mut ctx = CodegenCtx::default();
let (ref files, embeds) = crate::test_parse_files(ident, input, &mut ctx.parser); let (ref files, embeds) = crate::test_parse_files(ident, input, &mut ctx.parser);

View file

@ -1,41 +1,27 @@
main: main:
ADDI64 r254, r254, -120d ADDI64 r254, r254, -40d
ADDI64 r13, r254, 32d ST r0, r254, 0a, 8h
ST r0, r254, 32a, 8h LI64 r13, 1d
ADDI64 r14, r13, 8d ST r13, r254, 8a, 8h
LI64 r15, 1d LI64 r13, 2d
ST r15, r14, 0a, 8h
ADDI64 r15, r13, 16d
LI64 r16, 2d
ST r16, r15, 0a, 8h
LI64 r16, 3d
ADDI64 r17, r254, 112d
LI64 r18, 10d
ST r13, r254, 0a, 8h
ST r16, r254, 56a, 8h
ST r18, r254, 112a, 8h
ST r14, r254, 64a, 8h
LD r14, r254, 0a, 8h
LD r16, r254, 64a, 8h
ST r15, r254, 96a, 8h
ST r13, r254, 16a, 8h ST r13, r254, 16a, 8h
LD r13, r14, 0a, 8h LI64 r13, 3d
LD r14, r16, 0a, 8h LI64 r14, 10d
LD r15, r254, 96a, 8h ST r13, r254, 24a, 8h
LD r16, r254, 16a, 8h ST r14, r254, 32a, 8h
LD r13, r254, 0a, 8h
LD r14, r254, 8a, 8h
ADD64 r13, r14, r13 ADD64 r13, r14, r13
LD r14, r15, 0a, 8h LD r14, r254, 16a, 8h
ST r17, r254, 80a, 8h
ADD64 r13, r14, r13 ADD64 r13, r14, r13
LD r14, r16, 24a, 8h LD r14, r254, 24a, 8h
LD r15, r254, 80a, 8h
ADD64 r13, r14, r13 ADD64 r13, r14, r13
LD r14, r15, 0a, 8h LD r14, r254, 32a, 8h
ADDI64 r13, r13, 4d ADDI64 r13, r13, 4d
SUB64 r13, r13, r14 SUB64 r13, r13, r14
CP r1, r13 CP r1, r13
ADDI64 r254, r254, 120d ADDI64 r254, r254, 40d
JALA r0, r31, 0a JALA r0, r31, 0a
code size: 415 code size: 241
ret: 0 ret: 0
status: Ok(()) status: Ok(())

View file

@ -0,0 +1,12 @@
main:
LRA r13, r0, :"abcd\0"
ADDI64 r13, r13, 1d
LI64 r14, 37d
CP r2, r14
CP r3, r13
ECA
JALA r0, r31, 0a
bcd
code size: 59
ret: 0
status: Ok(())