mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 10:37:46 +00:00
31e0662856
This specifically fixes unix alloc(): previously when allocation fails it would (recursively) call alloc() again to create an interface due to lacking escape analysis. Also, all other cases shouldn't try to allocate just because something bad happens at runtime. TODO: implement escape analysis.
38 lines
887 B
Go
38 lines
887 B
Go
package runtime
|
|
|
|
// Builtin function panic(msg), used as a compiler intrinsic.
|
|
func _panic(message interface{}) {
|
|
printstring("panic: ")
|
|
printitf(message)
|
|
printnl()
|
|
abort()
|
|
}
|
|
|
|
// Cause a runtime panic, which is (currently) always a string.
|
|
func runtimePanic(msg string) {
|
|
printstring("panic: runtime error: ")
|
|
println(msg)
|
|
abort()
|
|
}
|
|
|
|
// Check for bounds in *ssa.Index, *ssa.IndexAddr and *ssa.Lookup.
|
|
func lookupBoundsCheck(length, index int) {
|
|
if index < 0 || index >= length {
|
|
runtimePanic("index out of range")
|
|
}
|
|
}
|
|
|
|
// Check for bounds in *ssa.Slice.
|
|
func sliceBoundsCheck(length, low, high uint) {
|
|
if !(0 <= low && low <= high && high <= length) {
|
|
runtimePanic("slice out of range")
|
|
}
|
|
}
|
|
|
|
// Check for bounds in *ssa.MakeSlice.
|
|
func sliceBoundsCheckMake(length, capacity uint) {
|
|
if !(0 <= length && length <= capacity) {
|
|
runtimePanic("slice size out of range")
|
|
}
|
|
}
|