英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论