wrong index for extend

This commit is contained in:
Jakub Doka 2024-11-09 10:28:53 +01:00
parent 65e9f272a8
commit b8032aa840
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
4 changed files with 37 additions and 3 deletions

View file

@ -612,6 +612,39 @@ main := fn(): uint {
### Purely Testing Examples ### Purely Testing Examples
#### null_check_returning_small_global
```hb
MAGIC := 127
get := fn(file: ^u8): ?uint {
if *file == MAGIC {
return MAGIC
} else {
return null
}
}
some_file := [u8].(127, 255, 255, 255, 255, 255)
foo := fn(): ?uint {
gotten := get(&some_file[0])
if gotten == null {
return null
} else if gotten == 4 {
return 2
} else if gotten == MAGIC {
return 0
}
return null
}
main := fn(): uint {
f := foo()
if f == null return 100
return f
}
```
#### null_check_in_the_loop #### null_check_in_the_loop
```hb ```hb
A := struct { A := struct {

View file

@ -4579,7 +4579,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);
@ -4640,6 +4640,7 @@ mod tests {
fb_driver; fb_driver;
// Purely Testing Examples; // Purely Testing Examples;
null_check_returning_small_global;
null_check_in_the_loop; null_check_in_the_loop;
stack_provenance; stack_provenance;
advanced_floating_point_arithmetic; advanced_floating_point_arithmetic;

View file

@ -264,8 +264,8 @@ impl HbvmBackend {
} else if let Some(against) = op.cmp_against() { } else if let Some(against) = op.cmp_against() {
let op_ty = fuc.nodes[rh].ty; let op_ty = fuc.nodes[rh].ty;
self.emit(extend(fuc.nodes[lh].ty, fuc.nodes[lh].ty.extend(), 0, 0)); self.emit(extend(fuc.nodes[lh].ty, fuc.nodes[lh].ty.extend(), 1, 1));
self.emit(extend(fuc.nodes[rh].ty, fuc.nodes[rh].ty.extend(), 1, 1)); self.emit(extend(fuc.nodes[rh].ty, fuc.nodes[rh].ty.extend(), 2, 2));
let &[dst, lhs, rhs] = allocs else { unreachable!() }; let &[dst, lhs, rhs] = allocs else { unreachable!() };
if op_ty.is_float() && matches!(op, TokenKind::Le | TokenKind::Ge) { if op_ty.is_float() && matches!(op, TokenKind::Le | TokenKind::Ge) {