Add some documentation to the abi
[scheme.git] / abi.md
1 # heap
2
3 a heap is allocated at the start, and the address to the next free
4 space on it is stored in `heap_start`. it needs to be
5 updated/decremented whenever you put anything on the heap
6
7 # closures
8
9 * lambda: actual function containing the code
10 * closure: reference to the lambda containing captives
11
12 closures are stored on the heap. They contain the address to the
13 lambda along with any "captives", i.e. captured variables. They have
14 the following layout:
15
16 ```
17 0            8          16        24        32
18 lambda code  1st        2nd       3rd
19 address      captive    captive   captive   ...
20 ```
21
22 # lambdas
23
24 lambdas use the system v amd64 calling convention.
25
26 * param 0: the start address of the **1st** captive
27 * param 1...n: the remaining, regular args.
28
29 e.g.
30 ```
31 (let [(x 42)] (lambda (y) (+ x y)))
32 ```
33
34 * param 0: pointer to the value of `x`
35 * param 1: the value of`y`