Skip to content

Commit fb6dcac

Browse files
committed
feat: added support for recursive calls
1 parent c14e9b6 commit fb6dcac

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

examples/fib.qf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
func fib(si32 i) si32 {
2+
if(i <= 1_si32) {
3+
ret 1
4+
}
5+
6+
var si32 test = fib(i - 1_si32) + fib(i - 2_si32)
7+
ret test
8+
}

ir/src/conv/func.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn parse_ir_body(ctx: &IRContext, func: &mut IRFunction, nodes: Vec<Box<ASTT
9292
}
9393

9494
pub fn parse_ir_function_call(ctx: &IRContext, f: &IRFunction, node: Box<ASTTreeNode>, owner: Option<IRPointer>, grab_result: bool) -> PositionlessResult<Option<IRValueRef>> {
95-
if let ASTTreeNode::FunctionCall { func, args } = *node {
95+
if let ASTTreeNode::FunctionCall { func: ff, args } = *node {
9696
let mut arguments = vec![];
9797

9898
if owner.as_ref().is_some() {
@@ -103,9 +103,16 @@ pub fn parse_ir_function_call(ctx: &IRContext, f: &IRFunction, node: Box<ASTTree
103103
arguments.push(parse_ir_value(Some(&f), ctx, v, None, false)?);
104104
}
105105

106-
let func = ctx.get_function(func.hash)?;
107106

108-
let ret = func.call(ctx, arguments, grab_result)?;
107+
let ret;
108+
109+
if ff.hash == f.hash {
110+
ret = f.call(ctx, arguments, grab_result)?;
111+
} else {
112+
let func = ctx.get_function(ff.hash)?;
113+
114+
ret = func.call(ctx, arguments, grab_result)?;
115+
}
109116

110117
if !grab_result || ret.is_none() {
111118
return Ok(None);

0 commit comments

Comments
 (0)