compiler, runtime: move defer notes to the runtime file

This seems like the more appropriate place to describe the
implementation of defer.
This commit is contained in:
Ayke van Laethem
2018-11-01 11:42:04 +01:00
parent c7cf6f0e82
commit d7844ce124
2 changed files with 12 additions and 13 deletions
+12
View File
@@ -1,5 +1,17 @@
package runtime
// Defer statements are implemented by transforming the function in the
// following way:
// * Creating an alloca in the entry block that contains a pointer (initially
// null) to the linked list of defer frames.
// * Every time a defer statement is executed, a new defer frame is created
// using alloca with a pointer to the previous defer frame, and the head
// pointer in the entry block is replaced with a pointer to this defer
// frame.
// * On return, runtime.rundefers is called which calls all deferred functions
// from the head of the linked list until it has gone through all defer
// frames.
import "unsafe"
type deferContext unsafe.Pointer