bratenburg

This commit is contained in:
mlokr 2024-09-13 20:31:05 +02:00
parent 16e2c32521
commit 2bc7a5c13f
No known key found for this signature in database
GPG key ID: DEA147DDEE644993
4 changed files with 29 additions and 3 deletions

View file

@ -913,3 +913,25 @@ main := fn(): int {
return back_buffer[1024 * 2]
}
```
#### something_somehow
```hb
foo := @use("foo.hb")
main := fn(): void {
foo.blue
foo.red
return
}
// in module: foo.hb
bar := @use("bar.hb")
default := bar
blue := default.blue
red := default.red
// in module: bar.hb
Color := struct {r: u8, g: u8, b: u8, a: u8}
red := Color.(255, 0, 0, 0)
blue := Color.(1, 0, 1, 0)
```

View file

@ -2547,7 +2547,7 @@ impl Codegen {
pub fn disasm(&mut self, output: &mut impl std::io::Write) -> std::io::Result<()> {
let mut bin = Vec::new();
self.tys.assemble(&mut bin);
self.assemble(&mut bin);
self.tys.disasm(&bin, &self.files, output, |_| {})
}
@ -2701,5 +2701,6 @@ mod tests {
writing_into_string => README;
request_page => README;
tests_ptr_to_ptr_copy => README;
something_somehow => README;
}
}

View file

@ -862,11 +862,11 @@ fn disasm(
let mut label_count = 0;
while let Some(&byte) = binary.first() {
let inst = instr_from_byte(byte)?;
let offset: i32 = (prev.len() - binary.len()).try_into().unwrap();
if offset as u32 == off + len {
break;
}
let Ok(inst) = instr_from_byte(byte) else { break };
instrs::parse_args(binary, inst, &mut buf).ok_or(std::io::ErrorKind::OutOfMemory)?;
for op in buf.drain(..) {
@ -903,11 +903,14 @@ fn disasm(
binary.take(..off as usize).unwrap();
while let Some(&byte) = binary.first() {
let inst = instr_from_byte(byte).unwrap();
let offset: i32 = (prev.len() - binary.len()).try_into().unwrap();
if offset as u32 == off + len {
break;
}
let Ok(inst) = instr_from_byte(byte) else {
writeln!(out, "invalid instr {byte}")?;
break;
};
instrs::parse_args(binary, inst, &mut buf).unwrap();
if let Some(label) = labels.get(&offset.try_into().unwrap()) {