diff --git a/lang/README.md b/lang/README.md index 362689f2..f4732ffe 100644 --- a/lang/README.md +++ b/lang/README.md @@ -446,9 +446,12 @@ pass := fn(arr: ^[uint; 3]): uint { #### inline ```hb main := fn(): uint { + some_eca() return @inline(foo, 1, 2, 3) - bar(3) } +$some_eca := fn(): void return @eca(8) + // only for functions with no control flow (if, loop) $bar := fn(a: uint): uint return a * 2 diff --git a/lang/src/son.rs b/lang/src/son.rs index 7afc62a5..59ba3ab3 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -3849,7 +3849,13 @@ impl<'a> Codegen<'a> { } let (v, ctrl, scope) = mem::replace(&mut self.ci.inline_ret, prev_inline_ret)?; - if is_inline && ctrl.get() != prev_ctrl { + if is_inline + && (ctrl.get() != prev_ctrl + && (!matches!(self.ci.nodes[ctrl.get()].kind, Kind::Call { + func: ty::Func::ECA, + .. + }) || self.ci.nodes[ctrl.get()].inputs[0] != prev_ctrl)) + { self.report(body.pos(), "function is makred inline but it contains controlflow"); } diff --git a/lang/tests/son_tests_inline.txt b/lang/tests/son_tests_inline.txt index 753b36f4..f144cb0e 100644 --- a/lang/tests/son_tests_inline.txt +++ b/lang/tests/son_tests_inline.txt @@ -1,18 +1,20 @@ main: - LI64 r7, 6d - LRA r3, r0, :gb - LI64 r6, 0d - LD r8, r3, 0a, 8h - CMPU r9, r8, r6 - CMPUI r9, r9, 0d - ORI r11, r9, 0d - ANDI r11, r11, 255d - JNE r11, r0, :0 - CP r4, r7 + LI64 r2, 8d + ECA + LI64 r10, 6d + LRA r6, r0, :gb + LI64 r9, 0d + LD r11, r6, 0a, 8h + CMPU r12, r11, r9 + CMPUI r12, r12, 0d + ORI r2, r12, 0d + ANDI r2, r2, 255d + JNE r2, r0, :0 + CP r7, r10 JMP :1 - 0: LI64 r4, 1d - 1: SUB64 r1, r4, r7 + 0: LI64 r7, 1d + 1: SUB64 r1, r7, r10 JALA r0, r31, 0a -code size: 131 +code size: 142 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_memory_swap.txt b/lang/tests/son_tests_memory_swap.txt index e69de29b..9fae971f 100644 --- a/lang/tests/son_tests_memory_swap.txt +++ b/lang/tests/son_tests_memory_swap.txt @@ -0,0 +1,32 @@ +decide: + ADDI64 r254, r254, -24d + ADDI64 r5, r254, 0d + ST r2, r254, 0a, 8h + LI64 r8, 0d + ST r8, r254, 8a, 8h + ST r8, r254, 16a, 8h + BMC r5, r1, 24h + ADDI64 r254, r254, 24d + JALA r0, r31, 0a +main: + ADDI64 r254, r254, -112d + ST r31, r254, 72a, 40h + ADDI64 r32, r254, 48d + LI64 r2, 0d + CP r1, r32 + JAL r31, r0, :decide + ADDI64 r1, r254, 24d + BMC r32, r1, 24h + LI64 r2, 1d + JAL r31, r0, :decide + ADDI64 r33, r254, 0d + BMC r32, r33, 24h + LD r34, r254, 24a, 8h + LD r35, r254, 0a, 8h + ADD64 r1, r35, r34 + LD r31, r254, 72a, 40h + ADDI64 r254, r254, 112d + JALA r0, r31, 0a +code size: 275 +ret: 1 +status: Ok(())