--exception:goto switch for deterministic exception handling (#12977)
This implements "deterministic" exception handling for Nim based on goto instead of setjmp. This means raising an exception is much cheaper than in C++'s table based implementations. Supports hard realtime systems. Default for --gc:arc and the C target because it's generally a good idea and arc is all about deterministic behavior. Note: This implies that fatal runtime traps are not catchable anymore! This needs to be documented.
This commit is contained in:
parent
8a63caca07
commit
c3344862b0
23 changed files with 640 additions and 183 deletions
|
|
@ -1,4 +1,19 @@
|
|||
#
|
||||
#
|
||||
# Nim's Runtime Library
|
||||
# (c) Copyright 2019 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
{.push profiler: off.}
|
||||
|
||||
when defined(nimHasExceptionsQuery):
|
||||
const gotoBasedExceptions = compileOption("exceptions", "goto")
|
||||
else:
|
||||
const gotoBasedExceptions = false
|
||||
|
||||
when hostOS == "standalone":
|
||||
include "$projectpath/panicoverride"
|
||||
|
||||
|
|
@ -9,19 +24,20 @@ when hostOS == "standalone":
|
|||
rawoutput(message)
|
||||
panic(arg)
|
||||
|
||||
elif defined(nimQuirky) and not defined(nimscript):
|
||||
elif (defined(nimQuirky) or gotoBasedExceptions) and not defined(nimscript):
|
||||
import ansi_c
|
||||
|
||||
proc name(t: typedesc): string {.magic: "TypeTrait".}
|
||||
|
||||
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
|
||||
writeStackTrace()
|
||||
var buf = newStringOfCap(200)
|
||||
add(buf, "Error: unhandled exception: ")
|
||||
add(buf, message)
|
||||
add(buf, arg)
|
||||
add(buf, " [")
|
||||
add(buf, name exceptn)
|
||||
add(buf, "]")
|
||||
add(buf, "]\n")
|
||||
cstderr.rawWrite buf
|
||||
quit 1
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue