allowing eca in inline functions

This commit is contained in:
Jakub Doka 2024-11-12 17:11:39 +01:00
parent c701eb7b6d
commit 9949086011
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
4 changed files with 57 additions and 14 deletions

View file

@ -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

View file

@ -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");
}

View file

@ -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(())

View file

@ -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(())