the items accesed outside the nested scope no longer get duplicated

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-14 18:50:13 +01:00
parent 91e35b72ee
commit dc96c8b10a
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
5 changed files with 73 additions and 31 deletions

View file

@ -734,7 +734,7 @@ main := fn(): uint {
#### method_receiver_by_value
```hb
$log := fn(ptr: ^u8): void return @eca(0, ptr)
$log := fn(ptr: ^u8): void return @eca(37, ptr)
Struct := struct {
ptr: ^u8,
print := fn(self: Self, rhs: Self): void {

View file

@ -1138,7 +1138,7 @@ pub fn test_run_vm(out: &[u8], output: &mut String) {
match vm.run() {
Ok(hbvm::VmRunOk::End) => break Ok(()),
Ok(hbvm::VmRunOk::Ecall) => match vm.read_reg(2).0 {
0 => writeln!(
37 => writeln!(
output,
"{}",
unsafe { CStr::from_ptr(vm.read_reg(3).0 as _) }.to_str().unwrap()

View file

@ -5641,7 +5641,7 @@ impl<'a> Codegen<'a> {
};
};
let ty = if let Some(&ty) = self.tys.syms.get(SymKey::Decl(parent, name), &self.tys.ins)
let ty = if let Some(&ty) = self.tys.syms.get(SymKey::Decl(piter, name), &self.tys.ins)
{
ty
} else {
@ -5651,13 +5651,18 @@ impl<'a> Codegen<'a> {
self.tys
.ins
.consts
.push(ConstData { ast: ExprRef::new(expr), name, file, parent })
.push(ConstData {
ast: ExprRef::new(expr),
name,
file,
parent: piter,
})
.into()
} else {
self.parse_ty(
TyScope {
file,
parent,
parent: piter,
name: Some(name),
alloc_const: true,
is_ct,
@ -5667,7 +5672,7 @@ impl<'a> Codegen<'a> {
}
})
.unwrap_or_else(|_| unreachable!());
self.tys.syms.insert(SymKey::Decl(parent, name), ty, &self.tys.ins);
self.tys.syms.insert(SymKey::Decl(piter, name), ty, &self.tys.ins);
ty
};

View file

@ -43,18 +43,6 @@ free:
CP r5, r15
ECA
JALA r0, r31, 0a
free:
CP r13, r2
CP r14, r3
CP r15, r4
LRA r16, r0, :free_sys_call
LD r16, r16, 0a, 8h
CP r2, r16
CP r3, r13
CP r4, r14
CP r5, r15
ECA
JALA r0, r31, 0a
main:
ADDI64 r254, r254, -96d
ST r31, r254, 48a, 48h
@ -99,18 +87,6 @@ malloc:
CP r13, r1
CP r1, r13
JALA r0, r31, 0a
malloc:
CP r13, r2
CP r14, r3
LRA r15, r0, :malloc_sys_call
LD r15, r15, 0a, 8h
CP r2, r15
CP r3, r13
CP r4, r14
ECA
CP r13, r1
CP r1, r13
JALA r0, r31, 0a
new:
ADDI64 r254, r254, -24d
CP r15, r1
@ -242,6 +218,6 @@ push:
4: LD r31, r254, 0a, 88h
ADDI64 r254, r254, 88d
JALA r0, r31, 0a
code size: 1757
code size: 1635
ret: 69
status: Ok(())

View file

@ -0,0 +1,61 @@
main:
ADDI64 r254, r254, -72d
ST r31, r254, 32a, 40h
ADDI64 r32, r254, 8d
LRA r33, r0, :"Goodbye, World!\0"
ADDI64 r34, r254, 24d
LRA r35, r0, :"Hello, World!\0"
ST r33, r254, 8a, 8h
ST r35, r254, 24a, 8h
LD r2, r34, 0a, 8h
LD r3, r32, 0a, 8h
JAL r31, r0, :print
ADDI64 r32, r254, 0d
ADDI64 r34, r254, 16d
ST r33, r254, 0a, 8h
ST r35, r254, 16a, 8h
CP r2, r34
CP r3, r32
JAL r31, r0, :print2
LD r31, r254, 32a, 40h
ADDI64 r254, r254, 72d
JALA r0, r31, 0a
print:
ADDI64 r254, r254, -16d
ST r2, r254, 8a, 8h
ADDI64 r2, r254, 8d
CP r13, r2
ST r3, r254, 0a, 8h
ADDI64 r3, r254, 0d
CP r14, r3
LD r13, r13, 0a, 8h
LI64 r15, 37d
CP r2, r15
CP r3, r13
ECA
LD r13, r14, 0a, 8h
CP r2, r15
CP r3, r13
ECA
ADDI64 r254, r254, 16d
JALA r0, r31, 0a
print2:
CP r13, r2
CP r14, r3
LD r13, r13, 0a, 8h
LI64 r15, 37d
CP r2, r15
CP r3, r13
ECA
LD r13, r14, 0a, 8h
CP r2, r15
CP r3, r13
ECA
JALA r0, r31, 0a
Hello, World!
Goodbye, World!
Hello, World!
Goodbye, World!
code size: 457
ret: 0
status: Ok(())