SuperC documentation

⚠️ This is a PROPOSAL DRAFT. Lambdas are currently not implemented. Syntax may change
Development is not going to advance until LLVM backend is minimally stable.

Lambda Expressions & Closures

Lambdas and closures only differ at assembly level, it’s nice if you learn the difference, but you don’t have to.

In SuperC, you can write both as lambdas without worrying about capture. In other languages, you have to explicitly specify captures.

Assembly proposal

Lambdas

Just perform a fastcall

Closures

Since fastcall does not create a new stack frame, technically the closure has access to the local variables from the enclosing function. So the capture has already happened.

The key is to precalculate the address of the local variables relative to the stack pointer, in a reliable way.

As you can see in the assembly output, __closure0__ does essentially addl %esi, 28(%rdi), where %esi is the parameter y, and 28(%rdi) is the local variable x. Effectively performing x += y.


Previous

C backwards compatibility

Next

(DRAFT) Defer edge cases