This commit is contained in:
xushiwei
2024-06-13 13:51:36 +08:00
parent 64e96cc101
commit 4abcbb9b51
9 changed files with 75 additions and 21 deletions

View File

@@ -179,6 +179,7 @@ type aFunction struct {
blks []BasicBlock
defer_ *aDefer
recov BasicBlock
params []Type
freeVars Expr
@@ -329,4 +330,9 @@ func (p Function) Block(idx int) BasicBlock {
return p.blks[idx]
}
// SetRecover sets the recover block for the function.
func (p Function) SetRecover(blk BasicBlock) {
p.recov = blk
}
// -----------------------------------------------------------------------------

View File

@@ -22,6 +22,7 @@ import "C"
import (
"go/token"
"go/types"
"log"
"unsafe"
"github.com/goplus/llvm"
@@ -174,7 +175,7 @@ func (b Builder) getDefer(kind DoAction) *aDefer {
b.SetBlockEx(rethrowBlk, AtEnd, false) // rethrow
b.Call(b.Pkg.rtFunc("Rethrow"), link)
b.Unreachable() // TODO: func supports noreturn attribute
b.Jump(self.recov)
if kind == DeferAlways {
b.SetBlockEx(next, AtEnd, false)
@@ -266,16 +267,14 @@ func (b Builder) Unreachable() {
b.impl.CreateUnreachable()
}
/*
// Recover emits a recover instruction.
func (b Builder) Recover() (v Expr) {
func (b Builder) Recover() Expr {
if debugInstr {
log.Println("Recover")
}
prog := b.Prog
return prog.Zero(prog.Any())
// TODO(xsw): recover can't be a function call in Go
return b.Call(b.Pkg.rtFunc("Recover"))
}
*/
// Panic emits a panic instruction.
func (b Builder) Panic(v Expr) {

View File

@@ -898,8 +898,8 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
}
}
}
//case "recover":
// return b.Recover()
case "recover":
return b.Recover()
case "print", "println":
return b.PrintEx(fn == "println", args...)
}