forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs nim-lang#16521 import fatal; add tstandalone
- Loading branch information
1 parent
876fa3e
commit f7af90d
Showing
8 changed files
with
123 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# | ||
# 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.} | ||
|
||
# xxx move to excpt.nim where it's used | ||
when defined(nimHasExceptionsQuery): | ||
const gotoBasedExceptions* = compileOption("exceptions", "goto") | ||
else: | ||
const gotoBasedExceptions* = false | ||
|
||
when hostOS == "standalone": | ||
proc name(t: typedesc): string {.magic: "TypeTrait".} | ||
|
||
type PanicCallback* = proc(exceptionName: string, message: string, arg: string) | ||
# xxx: {.noconv.} ? | ||
|
||
var panicCallback: PanicCallback | ||
|
||
when not declared(setPanicCallback): | ||
# because fatal.nim is included twice; xxx: replace include with import | ||
proc setPanicCallback*(a: PanicCallback) = | ||
## this must be called at least once and is used by `sysFatal`; not thread safe. | ||
panicCallback = a | ||
|
||
proc sysFatal*(exceptn: typedesc, message: string) {.inline.} = | ||
# assumes `panicCallback != nil` | ||
panicCallback(name(exceptn), message, "") | ||
|
||
proc sysFatal*(exceptn: typedesc, message, arg: string) {.inline.} = | ||
# assumes `panicCallback != nil` | ||
panicCallback(name(exceptn), message, arg) | ||
|
||
elif (defined(nimQuirky) or defined(nimPanics)) 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, "]\n") | ||
cstderr.rawWrite buf | ||
quit 1 | ||
|
||
proc sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} = | ||
sysFatal(exceptn, message, "") | ||
|
||
else: | ||
proc sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} = | ||
raise (ref exceptn)(msg: message) | ||
|
||
proc sysFatal*(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = | ||
raise (ref exceptn)(msg: message & arg) | ||
|
||
{.pop.} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
discard """ | ||
ccodecheck: "\\i !@('systemInit')" | ||
ccodecheck: "\\i !@('systemDatInit')" | ||
output: "hello" | ||
matrix: "--os:standalone --gc:none" | ||
output: "hi 4778" | ||
""" | ||
# bug #2041: Macros need to be available for os:standalone! | ||
import macros | ||
|
||
proc printf(frmt: cstring) {.varargs, header: "<stdio.h>", cdecl.} | ||
proc printf(frmt: cstring) {.varargs, importc, header: "<stdio.h>", cdecl.} | ||
proc exit(code: int) {.importc, header: "<stdlib.h>", cdecl.} | ||
|
||
{.push stack_trace: off, profiler:off.} | ||
proc panicCallback(exceptionName: string, message: string, arg: string) {.noreturn.} = | ||
printf("panic: exception: %s, message: %s, arg: %s\n", exceptionName, message, arg) | ||
exit(1) | ||
{.pop.} | ||
|
||
setPanicCallback(panicCallback) | ||
|
||
var x = 0 | ||
inc x | ||
printf("hi %ld\n", x+4777) | ||
|
||
proc substr(a: string): string = a[0 .. 3] # This should compile. See #9762 | ||
const a = substr("foobar") | ||
# doAssert false |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
discard """ | ||
ccodecheck: "\\i !@('systemInit')" | ||
ccodecheck: "\\i !@('systemDatInit')" | ||
exitcode: 1 | ||
output: ''' | ||
hi 4778 | ||
panic: exception: AssertionDefect, message: tstandalone.nim(36, 10) `false` foo, arg: | ||
''' | ||
matrix: "--os:standalone --gc:none" | ||
""" | ||
|
||
# issue #2041: Macros need to be available for os:standalone! | ||
import macros | ||
|
||
from std/private/fatal import setPanicCallback | ||
|
||
proc printf(frmt: cstring) {.varargs, importc, header: "<stdio.h>", cdecl.} | ||
proc exit(code: int) {.importc, header: "<stdlib.h>", cdecl.} | ||
|
||
{.push stack_trace: off, profiler:off.} | ||
proc panicCallback(exceptionName: string, message: string, arg: string) {.noreturn.} = | ||
printf("panic: exception: %s, message: %s, arg: %s\n", exceptionName, message, arg) | ||
exit(1) | ||
{.pop.} | ||
|
||
setPanicCallback(panicCallback) | ||
|
||
var x = 0 | ||
inc x | ||
printf("hi %ld\n", x+4777) | ||
|
||
proc substr(a: string): string = a[0 .. 3] # This should compile. See #9762 | ||
const a = substr("foobar") | ||
|
||
## line 35 | ||
doAssert false, "foo" |