github.com/aykevl/tinygo@v0.5.0/src/runtime/panic.go (about)

     1  package runtime
     2  
     3  // trap is a compiler hint that this function cannot be executed. It is
     4  // translated into either a trap instruction or a call to abort().
     5  //go:export llvm.trap
     6  func trap()
     7  
     8  // Builtin function panic(msg), used as a compiler intrinsic.
     9  func _panic(message interface{}) {
    10  	printstring("panic: ")
    11  	printitf(message)
    12  	printnl()
    13  	abort()
    14  }
    15  
    16  // Cause a runtime panic, which is (currently) always a string.
    17  func runtimePanic(msg string) {
    18  	printstring("panic: runtime error: ")
    19  	println(msg)
    20  	abort()
    21  }
    22  
    23  // Try to recover a panicking goroutine.
    24  func _recover() interface{} {
    25  	// Deferred functions are currently not executed during panic, so there is
    26  	// no way this can return anything besides nil.
    27  	return nil
    28  }
    29  
    30  // See emitNilCheck in compiler/asserts.go.
    31  // This function is a dummy function that has its first and only parameter
    32  // marked 'nocapture' to work around a limitation in LLVM: a regular pointer
    33  // comparison captures the pointer.
    34  func isnil(ptr *uint8) bool {
    35  	return ptr == nil
    36  }
    37  
    38  // Panic when trying to dereference a nil pointer.
    39  func nilpanic() {
    40  	runtimePanic("nil pointer dereference")
    41  }
    42  
    43  // Panic when trying to acces an array or slice out of bounds.
    44  func lookuppanic() {
    45  	runtimePanic("index out of range")
    46  }
    47  
    48  // Panic when trying to slice a slice out of bounds.
    49  func slicepanic() {
    50  	runtimePanic("slice out of range")
    51  }