Caterpillar

Daily Thought - 2024-07-24

< back to list

I just finished implementing if in Caterpillar. So far, I had very low-level placeholders (return_if_zero and return_if_non_zero), which were easy to implement, but obviously not what a high-level language needs.

Remember that Caterpillar still has no syntax. It is embedded into Rust, meaning you can use a Rust API to build its syntax tree. The following is just pseudocode to demonstrate how if in Caterpillar currently works, and what it could look like once syntax is implemented:

condition
{ do_if_true }
{ do_if_false }
    if

if is just a function call that takes three arguments: A condition (the language is still untyped, so that's just a number; 0 is considered to be "false"), a block of code for the "then" case, and another block of code for the "else" case. I have my doubts about this, but for now I've decided to keep the syntax simple and model as much as I can as function calls.

<< previous thoughtnext thought >>