From d7844ce1248c543a003953d1062458911502b10a Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 1 Nov 2018 11:42:04 +0100 Subject: [PATCH] compiler, runtime: move defer notes to the runtime file This seems like the more appropriate place to describe the implementation of defer. --- compiler/calls.go | 13 ------------- src/runtime/defer.go | 12 ++++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/compiler/calls.go b/compiler/calls.go index 18dd74ae..f5ded1f4 100644 --- a/compiler/calls.go +++ b/compiler/calls.go @@ -8,19 +8,6 @@ import ( // For a description of the calling convention in prose, see docs/internals.rst // or the online version of this document: // https://tinygo.readthedocs.io/en/latest/internals.html#calling-convention -// -// Some further notes: -// * 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. // The maximum number of arguments that can be expanded from a single struct. If // a struct contains more fields, it is passed as a struct without expanding. diff --git a/src/runtime/defer.go b/src/runtime/defer.go index bb82e466..3d8cafbf 100644 --- a/src/runtime/defer.go +++ b/src/runtime/defer.go @@ -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