X-Git-Url: http://git.lukelau.me/?p=scheme.git;a=blobdiff_plain;f=abi.md;h=0dbbcc4942b21515229a11ad8f1945f1c22163a6;hp=0185ec03acc4803a0bcc45f710d19d2ab23e77e1;hb=HEAD;hpb=2a4254606dce5b839c4379ba1a7c35d2761ebaca diff --git a/abi.md b/abi.md index 0185ec0..0dbbcc4 100644 --- a/abi.md +++ b/abi.md @@ -11,6 +11,15 @@ when allocating, use first free block, move up free pointer when freeing, do ??? +# ownership + +``` +(let ([s "hello"]) <- s should be a linear string + (mkpair + (lambda () (print s)) <- two references to s? + (lambda () (print (reverse s))))) +``` + # closures * lambda: actual function containing the code @@ -26,6 +35,19 @@ lambda code 1st 2nd 3rd address captive captive captive ... ``` +## note on recursive closures + +The following example shows a recursive lambda, that results in a +closure that captures itself. +``` +(let ([f (closure lambda0 (f))]) + (f 42)) +``` +When this happens, `codegen-let` will insert `(f . 'self-captive)` +into the environment when codegen'ing the closure. `codegen-closure` +will then pick this up, and use it to insert its own heap address into +its inner environment. + # lambdas lambdas use the system v amd64 calling convention. @@ -40,3 +62,8 @@ e.g. * param 0: pointer to the value of `x` * param 1: the value of`y` + +# inter-function and stack values + +ints, bools and closures are passed around within functions in `%rax`. +adts are passed on the stack, at whatever stack index the code generation was called with. \ No newline at end of file