From 239504d9f4e1510fc18195947d26d65e288cc3b0 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 20 Oct 2018 18:00:12 +0200 Subject: [PATCH] compiler: implement recover() Doesn't do anything useful yet as running deferred calls are not executed during panic. Only implemented to get code to compile. --- compiler/compiler.go | 2 ++ src/runtime/panic.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/compiler/compiler.go b/compiler/compiler.go index 964d7763..db931a25 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -1787,6 +1787,8 @@ func (c *Compiler) parseBuiltin(frame *Frame, args []ssa.Value, callName string) c.createRuntimeCall("printnl", nil, "") } return llvm.Value{}, nil // print() or println() returns void + case "recover": + return c.createRuntimeCall("_recover", nil, ""), nil case "ssa:wrapnilchk": // TODO: do an actual nil check? return c.parseExpr(frame, args[0]) diff --git a/src/runtime/panic.go b/src/runtime/panic.go index 6cbef364..4d07bfb7 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -15,6 +15,13 @@ func runtimePanic(msg string) { abort() } +// Try to recover a panicking goroutine. +func _recover() interface{} { + // Deferred functions are currently not executed during panic, so there is + // no way this can return anything besides nil. + return nil +} + // Check for bounds in *ssa.Index, *ssa.IndexAddr and *ssa.Lookup. func lookupBoundsCheck(length lenType, index int) { if index < 0 || index >= int(length) {