[][src]Module inc::lambda

Scheme functions

Scheme lambdas are heavily overloaded and this is one of the most sophisticated parts of this compiler.

A scheme lambda creates a callable function and a heap allocated closure object that captures the free variables. This module also implements a calling convention - which is a set of rules agreed by the caller of a function and its definition regarding how the arguments are passed in and how a result is returned.

Closure conversion aims to break down scheme lambdas into something simpler for code generation and is a well known technique in several functional compilers. All lambdas are lifted to top level with a unique name and an explicit closure object is passed as the first argument which captures the environment in which the function was defined.

See Closure conversion: How to compile lambda for a detailed explanation.

The paper uses a calling convention that passes all arguments in stack. This is harder to implement than the default calling calling convention used by GCC on x86-64 - System V AMD64 ABI, in which arguments are passed in the registers RDI, RSI, RDX, RCX, R8, R9 and the return value is passed back in RAX.

⚠ This module implements the stack version for now, but must be migrated to SysV at some point.

Functions

call

Emit code for a function application. See code for details.

code

Function body for the simplest C style functions

lift

Scan through the source and lift lambdas into top level.