terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.73k stars 202 forks source link

How to build a recursive function from scratch? #341

Open capr opened 5 years ago

capr commented 5 years ago

Hello,

When building a terra function with lex:terrastats(), how do you handle recursivity (inside references to a symbol that is the function that is being built)?

Thanks!

capr commented 5 years ago

also, does Terra have tail calls?

capr commented 5 years ago

Found the answer: I make stubs and then I call func:resetdefinition() to add the actual body.

elliottslaughter commented 5 years ago

re tail calls, I don't think Terra has any specific support other than what would be provided by LLVM (e.g. https://stackoverflow.com/q/18603349/188046).

capr commented 5 years ago

@elliottslaughter just tested this today and it seems that the LLVM tail call optimization kicks in when it can.