mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
compiler: implement recover() built-in function
This commit is contained in:
committed by
Ron Evans
parent
79ba6a50c3
commit
8d6b210c09
@@ -20,6 +20,22 @@ type Task struct {
|
||||
|
||||
// state is the underlying running state of the task.
|
||||
state state
|
||||
|
||||
// DeferFrame stores a pointer to the (stack allocated) defer frame of the
|
||||
// goroutine that is used for the recover builtin.
|
||||
DeferFrame *DeferFrame
|
||||
}
|
||||
|
||||
// DeferFrame is a stack allocated object that stores information for the
|
||||
// current "defer frame", which is used in functions that use the `defer`
|
||||
// keyword.
|
||||
// The compiler knows the JumpPC struct offset.
|
||||
type DeferFrame struct {
|
||||
JumpSP unsafe.Pointer // stack pointer to return to
|
||||
JumpPC unsafe.Pointer // pc to return to
|
||||
Previous *DeferFrame // previous recover buffer pointer
|
||||
Panicking bool // true iff this defer frame is panicking
|
||||
PanicValue interface{} // panic value, might be nil for panic(nil) for example
|
||||
}
|
||||
|
||||
// getGoroutineStackSize is a compiler intrinsic that returns the stack size for
|
||||
|
||||
@@ -4,6 +4,9 @@ package task
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// There is only one goroutine so the task struct can be a global.
|
||||
var mainTask Task
|
||||
|
||||
//go:linkname runtimePanic runtime.runtimePanic
|
||||
func runtimePanic(str string)
|
||||
|
||||
@@ -12,8 +15,8 @@ func Pause() {
|
||||
}
|
||||
|
||||
func Current() *Task {
|
||||
runtimePanic("scheduler is disabled")
|
||||
return nil
|
||||
// Return a task struct, which is used for the recover builtin for example.
|
||||
return &mainTask
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
|
||||
Reference in New Issue
Block a user