Add tail call recursion - works, but if a datastructure is too deep (say, because env keeps growing on the heap) Rc::drop will end up overflowing the stack when trying to deallocate

This commit is contained in:
2023-02-10 19:38:44 -05:00
parent ba67b8c67b
commit 3c2dfbf8a7
2 changed files with 81 additions and 40 deletions

View File

@@ -13,6 +13,10 @@ impl<A: Into<Form>, B: Into<Form>> From<(A, B)> for Form {
}
}
pub enum PossibleTailCall {
Result(Rc<Form>),
TailCall(Rc<Form>, Rc<Form>),
}
#[derive(Debug, Eq, PartialEq)]
pub enum Form {
Nil,
@@ -20,7 +24,7 @@ pub enum Form {
Bool(bool),
Symbol(String),
Pair(Rc<Form>,Rc<Form>),
PrimComb(String, fn(Rc<Form>, Rc<Form>) -> Rc<Form>),
PrimComb(String, fn(Rc<Form>, Rc<Form>) -> PossibleTailCall),
DeriComb { se: Rc<Form>, de: Option<String>, params: Rc<Form>, body: Rc<Form> },
}
impl Form {