defer语句在哪里实现的?

huangapple go评论80阅读模式
英文:

Where is the defer statement implemented?

问题

我想知道defer语句是如何工作的,以及它在编译器源代码中的实现位置。

我找到了关于解析defer语句并在语法树中构建它的包。

但我对defer在运行时的实际执行很感兴趣。
我猜它可能在"src/runtime"的某个地方实现。

英文:

I would like to know how and why the defer-Statement works and where it is implemented(in Compiler Source Code).

I found the package about parsing the defer-Statement and building it in the syntax-tree

But I'm interestetd in the actual exection of defer at runtime.
My guess is, that it's somewhere inside the "src/runtime"

答案1

得分: 5

开始阅读这里 https://github.com/golang/go/blob/d089a6c7187f1ff85277515405ec6c641588a7ff/src/runtime/panic.go#L70

你也可以在代码库中搜索术语"deferreturn"以获取更多结果。

延迟跳转的汇编代码在这里 https://github.com/golang/go/blob/master/src/runtime/asm_amd64.s#L550

英文:

Begin reading here https://github.com/golang/go/blob/d089a6c7187f1ff85277515405ec6c641588a7ff/src/runtime/panic.go#L70

You can also search the repository for the term "deferreturn" to find more results.

Assembly for defer jumps here https://github.com/golang/go/blob/master/src/runtime/asm_amd64.s#L550

huangapple
  • 本文由 发表于 2017年5月17日 03:53:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/44010453.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定