compiler: implement deferring of immediately-applied closures

This is a common operation:

    freevar := ...
    defer func() {
        println("I am deferred:", freevar)
    }()

The function is thus an immediately applied closure. Only this form is
currently supported, support for regular (fat) function pointers should
be trivial to add but is not currently implemented as it wasn't
necessary to get fmt to compile.
This commit is contained in:
Ayke van Laethem
2018-10-22 14:06:51 +02:00
parent 9b9b66a09d
commit 82be43f4e6
4 changed files with 228 additions and 34 deletions
+8
View File
@@ -0,0 +1,8 @@
hello from function pointer: 5
deferring...
...run as defer 3
...run closure deferred: 4
...run as defer 1
bound method: foo
thing inside closure: foo
inside fp closure: foo 3