mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-27 01:34:02 +00:00
Merge pull request #2657 from def-/noreturn
Pass noReturn pragma to C code.
This commit is contained in:
@@ -1110,7 +1110,7 @@ var programResult* {.exportc: "nim_program_result".}: int
|
||||
## prematurely using ``quit``, this value is ignored.
|
||||
|
||||
proc quit*(errorcode: int = QuitSuccess) {.
|
||||
magic: "Exit", importc: "exit", header: "<stdlib.h>", noReturn.}
|
||||
magic: "Exit", importc: "exit", header: "<stdlib.h>", noreturn.}
|
||||
## Stops the program immediately with an exit code.
|
||||
##
|
||||
## Before stopping the program the "quit procedures" are called in the
|
||||
@@ -2270,20 +2270,21 @@ when hostOS == "standalone":
|
||||
include panicoverride
|
||||
|
||||
when not declared(sysFatal):
|
||||
template sysFatal(exceptn: typedesc, message: string) =
|
||||
when hostOS == "standalone":
|
||||
when hostOS == "standalone":
|
||||
proc sysFatal(exceptn: typedesc, message: string) {.inline.} =
|
||||
panic(message)
|
||||
else:
|
||||
|
||||
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
|
||||
rawoutput(message)
|
||||
panic(arg)
|
||||
else:
|
||||
proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} =
|
||||
var e: ref exceptn
|
||||
new(e)
|
||||
e.msg = message
|
||||
raise e
|
||||
|
||||
template sysFatal(exceptn: typedesc, message, arg: string) =
|
||||
when hostOS == "standalone":
|
||||
rawoutput(message)
|
||||
panic(arg)
|
||||
else:
|
||||
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noReturn.} =
|
||||
var e: ref exceptn
|
||||
new(e)
|
||||
e.msg = message & arg
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
# simple integer arithmetic with overflow checking
|
||||
|
||||
proc raiseOverflow {.compilerproc, noinline, noreturn.} =
|
||||
proc raiseOverflow {.compilerproc, noinline.} =
|
||||
# a single proc to reduce code size to a minimum
|
||||
sysFatal(OverflowError, "over- or underflow")
|
||||
|
||||
proc raiseDivByZero {.compilerproc, noinline, noreturn.} =
|
||||
proc raiseDivByZero {.compilerproc, noinline.} =
|
||||
sysFatal(DivByZeroError, "division by zero")
|
||||
|
||||
proc addInt64(a, b: int64): int64 {.compilerProc, inline.} =
|
||||
@@ -327,13 +327,13 @@ when not declared(mulInt):
|
||||
# We avoid setting the FPU control word here for compatibility with libraries
|
||||
# written in other languages.
|
||||
|
||||
proc raiseFloatInvalidOp {.noinline, noreturn.} =
|
||||
proc raiseFloatInvalidOp {.noinline.} =
|
||||
sysFatal(FloatInvalidOpError, "FPU operation caused a NaN result")
|
||||
|
||||
proc nanCheck(x: float64) {.compilerProc, inline.} =
|
||||
if x != x: raiseFloatInvalidOp()
|
||||
|
||||
proc raiseFloatOverflow(x: float64) {.noinline, noreturn.} =
|
||||
proc raiseFloatOverflow(x: float64) {.noinline.} =
|
||||
if x > 0.0:
|
||||
sysFatal(FloatOverflowError, "FPU operation caused an overflow")
|
||||
else:
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
|
||||
# Implementation of some runtime checks.
|
||||
|
||||
proc raiseRangeError(val: BiggestInt) {.compilerproc, noreturn, noinline.} =
|
||||
proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} =
|
||||
when hostOS == "standalone":
|
||||
sysFatal(RangeError, "value out of range")
|
||||
else:
|
||||
sysFatal(RangeError, "value out of range: ", $val)
|
||||
|
||||
proc raiseIndexError() {.compilerproc, noreturn, noinline.} =
|
||||
proc raiseIndexError() {.compilerproc, noinline.} =
|
||||
sysFatal(IndexError, "index out of bounds")
|
||||
|
||||
proc raiseFieldError(f: string) {.compilerproc, noreturn, noinline.} =
|
||||
proc raiseFieldError(f: string) {.compilerproc, noinline.} =
|
||||
sysFatal(FieldError, f, " is not accessible")
|
||||
|
||||
proc chckIndx(i, a, b: int): int =
|
||||
|
||||
Reference in New Issue
Block a user