Compare commits

..

2 commits

Author SHA1 Message Date
Jakub Doka f013e90936
better somehow 2024-10-22 22:57:40 +02:00
Jakub Doka 6977cb218c
seems to be compiling 2024-10-22 16:54:32 +02:00
3 changed files with 368 additions and 379 deletions

View file

@ -89,7 +89,6 @@ pub enum DisasmError<'a> {
InstructionOutOfBounds(&'a str), InstructionOutOfBounds(&'a str),
FmtFailed(core::fmt::Error), FmtFailed(core::fmt::Error),
HasOutOfBoundsJumps, HasOutOfBoundsJumps,
HasDirectInstructionCycles,
} }
#[cfg(feature = "disasm")] #[cfg(feature = "disasm")]
@ -113,9 +112,6 @@ impl core::fmt::Display for DisasmError<'_> {
"the code contained jumps that dont got neither to a \ "the code contained jumps that dont got neither to a \
valid symbol or local insturction" valid symbol or local insturction"
), ),
DisasmError::HasDirectInstructionCycles => {
writeln!(f, "found instruction that jumps to itself")
}
} }
} }
} }
@ -145,7 +141,6 @@ pub fn disasm<'a>(
let mut labels = BTreeMap::<u32, u32>::default(); let mut labels = BTreeMap::<u32, u32>::default();
let mut buf = Vec::<instrs::Oper>::new(); let mut buf = Vec::<instrs::Oper>::new();
let mut has_cycle = false;
let mut has_oob = false; let mut has_oob = false;
'_offset_pass: for (&off, &(name, len, kind)) in functions.iter() { '_offset_pass: for (&off, &(name, len, kind)) in functions.iter() {
@ -174,8 +169,6 @@ pub fn disasm<'a>(
_ => continue, _ => continue,
}; };
has_cycle |= rel == 0;
let global_offset: u32 = (offset + rel).try_into().unwrap(); let global_offset: u32 = (offset + rel).try_into().unwrap();
if functions.get(&global_offset).is_some() { if functions.get(&global_offset).is_some() {
continue; continue;
@ -287,9 +280,5 @@ pub fn disasm<'a>(
return Err(DisasmError::HasOutOfBoundsJumps); return Err(DisasmError::HasOutOfBoundsJumps);
} }
if has_cycle {
return Err(DisasmError::HasDirectInstructionCycles);
}
Ok(()) Ok(())
} }

View file

@ -528,99 +528,6 @@ main := fn(): int {
### Purely Testing Examples ### Purely Testing Examples
#### smh_happened
```hb
render := @use("render.hb")
main := fn(): void {
render.init(true)
return
}
// in module: stn.hb
string := @use("string.hb")
dt := @use("dt.hb")
memory := @use("memory.hb")
// in module: memory.hb
PAGE_SIZE := 4096
MAX_ALLOC := 0xFF
alloc := fn($Expr: type, num: int): ^Expr {
pages := 1 + @bitcast(@sizeof(Expr)) * num / PAGE_SIZE
if pages <= MAX_ALLOC {
return @bitcast(@inline(request_page, pages))
}
ptr := @inline(request_page, 0xFF)
remaining := pages - MAX_ALLOC
loop if remaining <= 0 break else {
if remaining < MAX_ALLOC {
request_page(remaining)
} else {
request_page(MAX_ALLOC)
}
remaining -= MAX_ALLOC
}
return @bitcast(ptr)
}
request_page := fn(page_count: u8): ^u8 {
msg := "\{00}\{01}xxxxxxxx\0"
msg_page_count := msg + 1;
*msg_page_count = page_count
return @eca(3, 2, msg, 12)
}
// in module: string.hb
length := fn(ptr: ^u8): uint {
len := @as(uint, 0)
loop if *(ptr + len) == 0 break else len += 1
return len
}
// in module: dt.hb
.{string} := @use("stn.hb")
get := fn($Expr: type, query: ^u8): Expr {
return @eca(3, 5, query, @inline(string.length, query))
}
// in module: render.hb
.{dt, memory} := @use("stn.hb")
Color := packed struct {b: u8, g: u8, r: u8, a: u8}
Surface := struct {
buf: ^Color,
width: int,
height: int,
}
new_surface := fn(width: int, height: int): Surface {
return .(
@inline(memory.alloc, Color, width * height),
width,
height,
)
}
init := fn(doublebuffer: bool): Surface {
framebuffer := dt.get(^Color, "framebuffer/fb0/ptr\0")
width := dt.get(int, "framebuffer/fb0/width\0")
height := dt.get(int, "framebuffer/fb0/height\0")
if doublebuffer {
return new_surface(width, height)
} else {
return .(framebuffer, width, height)
}
}
```
#### wide_ret #### wide_ret
```hb ```hb
OemIdent := struct { OemIdent := struct {
@ -1019,6 +926,14 @@ main := fn(arg: int): int {
#### exhaustive_loop_testing #### exhaustive_loop_testing
```hb ```hb
main := fn(): int { main := fn(): int {
loop break
x := 0
loop {
x += 1
break
}
if multiple_breaks(0) != 3 { if multiple_breaks(0) != 3 {
return 1 return 1
} }
@ -1043,7 +958,8 @@ main := fn(): int {
return 6 return 6
} }
return 0 loop {
}
} }
multiple_breaks := fn(arg: int): int { multiple_breaks := fn(arg: int): int {

File diff suppressed because it is too large Load diff