1
0
Fork 0
forked from koniifer/ableos

bratenburg

This commit is contained in:
mlokr 2024-09-13 20:31:05 +02:00
parent b85c93466f
commit ad9798d0f5
4 changed files with 29 additions and 3 deletions

View file

@ -913,3 +913,25 @@ main := fn(): int {
return back_buffer[1024 * 2] 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<()> { pub fn disasm(&mut self, output: &mut impl std::io::Write) -> std::io::Result<()> {
let mut bin = Vec::new(); let mut bin = Vec::new();
self.tys.assemble(&mut bin); self.assemble(&mut bin);
self.tys.disasm(&bin, &self.files, output, |_| {}) self.tys.disasm(&bin, &self.files, output, |_| {})
} }
@ -2701,5 +2701,6 @@ mod tests {
writing_into_string => README; writing_into_string => README;
request_page => README; request_page => README;
tests_ptr_to_ptr_copy => README; tests_ptr_to_ptr_copy => README;
something_somehow => README;
} }
} }

View file

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