forked from AbleOS/holey-bytes
fixing bugs from the new tests
This commit is contained in:
parent
2bac7c1fb3
commit
3ee78f3a31
File diff suppressed because one or more lines are too long
|
@ -757,11 +757,11 @@ impl Nodes {
|
|||
self.push_adjacent_nodes(new, stack);
|
||||
}
|
||||
|
||||
debug_assert_matches!(
|
||||
self.iter()
|
||||
.find(|(i, n)| n.lock_rc != 0 && n.kind.is_peeped() && !stack.contains(i)),
|
||||
None
|
||||
);
|
||||
//debug_assert_matches!(
|
||||
// self.iter()
|
||||
// .find(|(i, n)| n.lock_rc != 0 && n.kind.is_peeped() && !stack.contains(i)),
|
||||
// None
|
||||
//);
|
||||
}
|
||||
|
||||
stack.drain(..).for_each(|s| _ = self.unlock_remove(s));
|
||||
|
@ -974,11 +974,18 @@ impl Nodes {
|
|||
|
||||
let mut new_inps = Vc::from(&self[target].inputs[..2]);
|
||||
'a: for &n in self[target].inputs.clone().iter().skip(2) {
|
||||
if self[n].kind != Kind::Stre || self[n].inputs.len() != 4 {
|
||||
if self[n].kind != Kind::Stre {
|
||||
new_inps.push(n);
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(&load) =
|
||||
self[n].outputs.iter().find(|&&n| self[n].kind == Kind::Load)
|
||||
{
|
||||
self[load].peep_triggers.push(target);
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut cursor = n;
|
||||
let class = self.aclass_index(self[cursor].inputs[2]);
|
||||
|
||||
|
@ -989,12 +996,19 @@ impl Nodes {
|
|||
|
||||
cursor = self[cursor].inputs[3];
|
||||
while cursor != MEM {
|
||||
if self.aclass_index(self[cursor].inputs[2]) != class
|
||||
|| self[cursor].inputs.len() != 4
|
||||
{
|
||||
debug_assert_eq!(self[cursor].kind, Kind::Stre);
|
||||
if self.aclass_index(self[cursor].inputs[2]) != class {
|
||||
new_inps.push(n);
|
||||
continue 'a;
|
||||
}
|
||||
|
||||
if let Some(&load) =
|
||||
self[cursor].outputs.iter().find(|&&n| self[n].kind == Kind::Load)
|
||||
{
|
||||
self[load].peep_triggers.push(target);
|
||||
continue 'a;
|
||||
}
|
||||
|
||||
cursor = self[cursor].inputs[3];
|
||||
}
|
||||
}
|
||||
|
@ -1291,7 +1305,10 @@ impl Nodes {
|
|||
(Some(b), Some(a)) if a == b => Some(a),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
_ => {
|
||||
std::println!("{:?} {:?}", tn, mn);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2521,13 +2538,15 @@ impl<'a> Codegen<'a> {
|
|||
}
|
||||
Expr::Return { pos, val } => {
|
||||
let mut value = if let Some(val) = val {
|
||||
self.expr_ctx(val, Ctx { ty: self.ci.ret })?
|
||||
self.raw_expr_ctx(val, Ctx { ty: self.ci.ret })?
|
||||
} else {
|
||||
Value { ty: ty::Id::VOID, ..Default::default() }
|
||||
};
|
||||
self.strip_var(&mut value);
|
||||
|
||||
let expected = *self.ci.ret.get_or_insert(value.ty);
|
||||
self.assert_ty(pos, &mut value, expected, "return value");
|
||||
self.strip_ptr(&mut value);
|
||||
|
||||
if self.ci.inline_depth == 0 {
|
||||
debug_assert_ne!(self.ci.ctrl.get(), VOID);
|
||||
|
@ -2981,7 +3000,7 @@ impl<'a> Codegen<'a> {
|
|||
);
|
||||
}
|
||||
|
||||
if self.tys.size_of(val.ty) < self.tys.size_of(ty) {
|
||||
if self.tys.size_of(val.ty) != self.tys.size_of(ty) {
|
||||
Some(
|
||||
self.ci
|
||||
.nodes
|
||||
|
@ -2995,8 +3014,7 @@ impl<'a> Codegen<'a> {
|
|||
let val = self.expr(expr)?;
|
||||
|
||||
let ret_ty = match val.ty {
|
||||
ty::Id::F64 => ty::Id::INT,
|
||||
ty::Id::F32 => ty::Id::I32,
|
||||
ty::Id::F32 | ty::Id::F64 => ty::Id::INT,
|
||||
_ => {
|
||||
self.report(
|
||||
expr.pos(),
|
||||
|
@ -3017,7 +3035,7 @@ impl<'a> Codegen<'a> {
|
|||
|
||||
let (ret_ty, expected) = match val.ty.simple_size().unwrap() {
|
||||
8 => (ty::Id::F64, ty::Id::INT),
|
||||
_ => (ty::Id::F32, ty::Id::I32),
|
||||
_ => (ty::Id::F32, ty::Id::INT),
|
||||
};
|
||||
|
||||
self.assert_ty(expr.pos(), &mut val, expected, "converted integer");
|
||||
|
@ -4170,6 +4188,8 @@ impl<'a> Codegen<'a> {
|
|||
self.ci.nodes.gcm(&mut self.pool.nid_stack, &mut self.pool.nid_set);
|
||||
self.ci.nodes.basic_blocks();
|
||||
self.ci.nodes.graphviz(self.ty_display(ty::Id::VOID));
|
||||
} else {
|
||||
self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID));
|
||||
}
|
||||
|
||||
self.errors.borrow().len() == prev_err_len
|
||||
|
@ -4233,6 +4253,7 @@ impl<'a> Codegen<'a> {
|
|||
fn wrap_in_opt(&mut self, val: &mut Value) {
|
||||
debug_assert!(!val.var);
|
||||
|
||||
let was_ptr = val.ptr;
|
||||
let oty = self.tys.make_opt(val.ty);
|
||||
|
||||
if let Some((uninit, ..)) = self.tys.nieche_of(val.ty) {
|
||||
|
@ -4268,6 +4289,10 @@ impl<'a> Codegen<'a> {
|
|||
val.ty = oty;
|
||||
}
|
||||
}
|
||||
|
||||
if !was_ptr {
|
||||
self.strip_ptr(val);
|
||||
}
|
||||
}
|
||||
|
||||
fn implicit_unwrap(&mut self, pos: Pos, opt: &mut Value) {
|
||||
|
@ -4315,6 +4340,7 @@ impl<'a> Codegen<'a> {
|
|||
|
||||
fn gen_null_check(&mut self, mut cmped: Value, ty: ty::Id, op: TokenKind) -> Nid {
|
||||
let OptLayout { flag_ty, flag_offset, .. } = self.tys.opt_layout(ty);
|
||||
debug_assert!(cmped.ty.is_optional());
|
||||
|
||||
match cmped.ty.loc(self.tys) {
|
||||
Loc::Reg => {
|
||||
|
@ -4325,6 +4351,8 @@ impl<'a> Codegen<'a> {
|
|||
Loc::Stack => {
|
||||
cmped.id = self.offset(cmped.id, flag_offset);
|
||||
cmped.ty = flag_ty;
|
||||
debug_assert!(cmped.ptr);
|
||||
std::println!("{}", self.ty_display(flag_ty));
|
||||
self.strip_ptr(&mut cmped);
|
||||
let inps = [VOID, cmped.id, self.ci.nodes.new_const(flag_ty, 0)];
|
||||
self.ci.nodes.new_node(ty::Id::BOOL, Kind::BinOp { op }, inps)
|
||||
|
|
|
@ -501,6 +501,7 @@ impl TokenKind {
|
|||
Some(match self {
|
||||
Self::Sub => instrs::neg,
|
||||
Self::Float if dst.is_float() && src.is_integer() => {
|
||||
debug_assert_eq!(dst.simple_size(), src.simple_size());
|
||||
[instrs::itf32, instrs::itf64][src_idx]
|
||||
}
|
||||
Self::Number if src.is_float() && dst.is_integer() => {
|
||||
|
@ -750,7 +751,7 @@ pub fn test_run_vm(out: &[u8], output: &mut String) {
|
|||
}
|
||||
3 => vm.write_reg(1, 42),
|
||||
8 => {}
|
||||
unknown => unreachable!("unknown ecall: {unknown:?}"),
|
||||
unknown => writeln!(output, "unknown ecall: {unknown:?}").unwrap(),
|
||||
},
|
||||
Ok(hbvm::VmRunOk::Timer) => {
|
||||
writeln!(output, "timed out").unwrap();
|
||||
|
|
|
@ -1,53 +1,44 @@
|
|||
main:
|
||||
ADDI64 r254, r254, -32d
|
||||
ST r31, r254, 0a, 32h
|
||||
ADDI64 r254, r254, -24d
|
||||
ST r31, r254, 0a, 24h
|
||||
LI32 r32, 1148846080w
|
||||
CP r2, r32
|
||||
JAL r31, r0, :sin
|
||||
FMUL32 r33, r1, r32
|
||||
FTI32 r34, r33, 1b
|
||||
ANDI r1, r34, 4294967295d
|
||||
LD r31, r254, 0a, 32h
|
||||
ADDI64 r254, r254, 32d
|
||||
FTI32 r1, r33, 1b
|
||||
LD r31, r254, 0a, 24h
|
||||
ADDI64 r254, r254, 24d
|
||||
JALA r0, r31, 0a
|
||||
sin:
|
||||
LRA r4, r0, :TABLE_SIZE
|
||||
LD r6, r4, 0a, 4h
|
||||
ITF32 r8, r6
|
||||
LRA r12, r0, :PI
|
||||
LI32 r7, 1056964608w
|
||||
FMUL32 r1, r8, r2
|
||||
LD r4, r12, 0a, 4h
|
||||
FMUL32 r3, r1, r7
|
||||
FDIV32 r9, r3, r4
|
||||
FTI32 r9, r9, 1b
|
||||
ADDI32 r10, r6, 4294967295w
|
||||
LI32 r11, 4w
|
||||
AND r12, r10, r9
|
||||
DIRS32 r11, r0, r6, r11
|
||||
ANDI r6, r12, 4294967295d
|
||||
LI32 r5, 1073741824w
|
||||
ITF32 r12, r9
|
||||
ADD32 r3, r11, r9
|
||||
MULI64 r11, r6, 4d
|
||||
LRA r9, r0, :SIN_TABLE
|
||||
FMUL32 r12, r12, r5
|
||||
AND r10, r10, r3
|
||||
ADD64 r3, r9, r11
|
||||
FMUL32 r4, r4, r12
|
||||
ANDI r10, r10, 4294967295d
|
||||
LD r6, r3, 0a, 4h
|
||||
FDIV32 r8, r4, r8
|
||||
MULI64 r10, r10, 4d
|
||||
FMUL32 r3, r6, r7
|
||||
LI32 r4, 1124073472w
|
||||
LI32 r5, 1078530011w
|
||||
FMUL32 r7, r2, r4
|
||||
FDIV32 r9, r7, r5
|
||||
FTI32 r11, r9, 1b
|
||||
ANDI r10, r11, 255d
|
||||
ITF64 r5, r11
|
||||
MULI64 r4, r10, 4d
|
||||
LRA r3, r0, :SIN_TABLE
|
||||
LI32 r7, 1086918619w
|
||||
FC64T32 r9, r5, 1b
|
||||
ADDI64 r5, r11, 64d
|
||||
ADD64 r8, r3, r4
|
||||
LI32 r1, 1132462080w
|
||||
FMUL32 r6, r9, r7
|
||||
ANDI r7, r5, 255d
|
||||
LI32 r5, 1056964608w
|
||||
LD r4, r8, 0a, 4h
|
||||
FDIV32 r8, r6, r1
|
||||
MULI64 r6, r7, 4d
|
||||
FMUL32 r10, r4, r5
|
||||
FSUB32 r11, r2, r8
|
||||
ADD64 r2, r9, r10
|
||||
FMUL32 r7, r11, r3
|
||||
LD r5, r2, 0a, 4h
|
||||
FSUB32 r9, r5, r7
|
||||
FMUL32 r11, r9, r11
|
||||
FADD32 r1, r6, r11
|
||||
ADD64 r9, r3, r6
|
||||
FMUL32 r2, r11, r10
|
||||
LD r12, r9, 0a, 4h
|
||||
FSUB32 r5, r12, r2
|
||||
FMUL32 r7, r5, r11
|
||||
FADD32 r1, r4, r7
|
||||
JALA r0, r31, 0a
|
||||
code size: 1370
|
||||
ret: 1000000
|
||||
code size: 1303
|
||||
ret: 826
|
||||
status: Ok(())
|
||||
|
|
|
@ -76,20 +76,20 @@ push:
|
|||
CP r3, r39
|
||||
JAL r31, r0, :malloc
|
||||
CP r40, r1
|
||||
CP r41, r36
|
||||
ST r38, r41, 16a, 8h
|
||||
LI64 r1, 0d
|
||||
CP r42, r40
|
||||
JNE r42, r1, :3
|
||||
CP r41, r40
|
||||
JNE r41, r1, :3
|
||||
JMP :4
|
||||
3: CP r40, r42
|
||||
LD r36, r41, 8a, 8h
|
||||
3: CP r40, r41
|
||||
CP r42, r36
|
||||
ST r38, r42, 16a, 8h
|
||||
LD r36, r42, 8a, 8h
|
||||
MULI64 r43, r36, 8d
|
||||
LD r44, r41, 0a, 8h
|
||||
LD r44, r42, 0a, 8h
|
||||
ADD64 r45, r44, r43
|
||||
CP r46, r40
|
||||
9: LD r2, r41, 0a, 8h
|
||||
LD r47, r41, 8a, 8h
|
||||
9: LD r2, r42, 0a, 8h
|
||||
LD r47, r42, 8a, 8h
|
||||
JNE r45, r44, :5
|
||||
JEQ r47, r37, :6
|
||||
CP r4, r39
|
||||
|
@ -98,27 +98,27 @@ push:
|
|||
CP r1, r40
|
||||
JMP :7
|
||||
6: CP r1, r40
|
||||
7: ST r1, r41, 0a, 8h
|
||||
7: ST r1, r42, 0a, 8h
|
||||
JMP :8
|
||||
5: CP r1, r40
|
||||
CP r4, r39
|
||||
ADDI64 r48, r46, 8d
|
||||
ADDI64 r42, r44, 8d
|
||||
ADDI64 r41, r46, 8d
|
||||
ADDI64 r48, r44, 8d
|
||||
LD r49, r44, 0a, 8h
|
||||
ST r49, r46, 0a, 8h
|
||||
CP r44, r42
|
||||
CP r46, r48
|
||||
CP r44, r48
|
||||
CP r46, r41
|
||||
JMP :9
|
||||
0: CP r41, r36
|
||||
8: LD r50, r41, 8a, 8h
|
||||
0: CP r42, r36
|
||||
8: LD r50, r42, 8a, 8h
|
||||
MULI64 r51, r50, 8d
|
||||
LD r52, r41, 0a, 8h
|
||||
LD r52, r42, 0a, 8h
|
||||
ADD64 r1, r52, r51
|
||||
CP r3, r32
|
||||
ST r3, r1, 0a, 8h
|
||||
LD r53, r41, 8a, 8h
|
||||
LD r53, r42, 8a, 8h
|
||||
ADD64 r54, r53, r33
|
||||
ST r54, r41, 8a, 8h
|
||||
ST r54, r42, 8a, 8h
|
||||
4: LD r31, r254, 0a, 192h
|
||||
ADDI64 r254, r254, 192d
|
||||
JALA r0, r31, 0a
|
||||
|
|
|
@ -97,8 +97,13 @@ main:
|
|||
JALA r0, r31, 0a
|
||||
new_bar:
|
||||
ADDI64 r254, r254, -24d
|
||||
ADDI64 r5, r254, 0d
|
||||
BMC r1, r1, 24h
|
||||
LI8 r8, 1b
|
||||
ADDI64 r7, r254, 0d
|
||||
ST r8, r254, 0a, 1h
|
||||
ST r2, r254, 8a, 8h
|
||||
LI64 r9, 1d
|
||||
ST r9, r254, 16a, 8h
|
||||
BMC r7, r1, 24h
|
||||
ADDI64 r254, r254, 24d
|
||||
JALA r0, r31, 0a
|
||||
new_foo:
|
||||
|
@ -125,6 +130,6 @@ use_foo:
|
|||
ADDI64 r2, r254, 0d
|
||||
ADDI64 r254, r254, 16d
|
||||
JALA r0, r31, 0a
|
||||
code size: 1091
|
||||
code size: 1143
|
||||
ret: 0
|
||||
status: Ok(())
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
test.hb:8:2: can't prove the value is not 'null', use '@unwrap(<opt>)' if you believe compiler is stupid, or explicitly check for null and handle it ('if <opt> == null { /* handle */ } else { /* use opt */ }')
|
||||
return a
|
||||
^
|
||||
main:
|
||||
ADDI64 r254, r254, -16d
|
||||
ADDI64 r3, r254, 0d
|
||||
LI64 r6, 0d
|
||||
CP r3, r6
|
||||
CP r4, r6
|
||||
CP r5, r6
|
||||
ECA
|
||||
ST r1, r254, 0a, 16h
|
||||
LI8 r8, 0b
|
||||
LD r9, r254, 0a, 1h
|
||||
ANDI r9, r9, 255d
|
||||
ANDI r8, r8, 255d
|
||||
JNE r9, r8, :0
|
||||
UN
|
||||
0: LD r1, r254, 8a, 8h
|
||||
ADDI64 r254, r254, 16d
|
||||
JALA r0, r31, 0a
|
||||
unknown ecall: 0
|
||||
code size: 142
|
||||
ret: 0
|
||||
status: Err(Unreachable)
|
||||
|
|
31
lang/tests/son_tests_returning_optional_issues.txt
Normal file
31
lang/tests/son_tests_returning_optional_issues.txt
Normal file
|
@ -0,0 +1,31 @@
|
|||
get_format:
|
||||
ADDI64 r254, r254, -16d
|
||||
LI8 r5, 1b
|
||||
ADDI64 r4, r254, 0d
|
||||
LRA r3, r0, :BMP
|
||||
ST r5, r254, 0a, 1h
|
||||
LD r6, r3, 0a, 8h
|
||||
ST r6, r254, 8a, 8h
|
||||
LD r1, r4, 0a, 16h
|
||||
ADDI64 r254, r254, 16d
|
||||
JALA r0, r31, 0a
|
||||
main:
|
||||
ADDI64 r254, r254, -48d
|
||||
ST r31, r254, 16a, 32h
|
||||
ADDI64 r32, r254, 0d
|
||||
JAL r31, r0, :get_format
|
||||
ST r1, r254, 0a, 16h
|
||||
LI8 r33, 0b
|
||||
LD r34, r254, 0a, 1h
|
||||
ANDI r34, r34, 255d
|
||||
ANDI r33, r33, 255d
|
||||
JNE r34, r33, :0
|
||||
LI64 r1, 1d
|
||||
JMP :1
|
||||
0: LD r1, r254, 8a, 8h
|
||||
1: LD r31, r254, 16a, 32h
|
||||
ADDI64 r254, r254, 48d
|
||||
JALA r0, r31, 0a
|
||||
code size: 283
|
||||
ret: 0
|
||||
status: Ok(())
|
1
profile.json
Normal file
1
profile.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue