make --gc:arc --exceptions:quirky work again [backport:1.4] (#16583)

* make --gc:arc --exceptions:quirky work again [backport:1.4]

* fixes #16404 [backport:1.4]
This commit is contained in:
Andreas Rumpf 2021-01-04 19:44:50 +01:00 • committed by GitHub
commit 6317e4004d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 17 deletions

View file

@ -572,6 +572,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
if pass in {passCmd2, passPP}: if pass in {passCmd2, passPP}:
defineSymbol(conf.symbols, "nimSeqsV2") defineSymbol(conf.symbols, "nimSeqsV2")
defineSymbol(conf.symbols, "nimV2") defineSymbol(conf.symbols, "nimV2")
if conf.exc == excNone and conf.backend != backendCpp:
conf.exc = excGoto
of "orc": of "orc":
conf.selectedGC = gcOrc conf.selectedGC = gcOrc
defineSymbol(conf.symbols, "gcdestructors") defineSymbol(conf.symbols, "gcdestructors")
@ -581,6 +583,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
if pass in {passCmd2, passPP}: if pass in {passCmd2, passPP}:
defineSymbol(conf.symbols, "nimSeqsV2") defineSymbol(conf.symbols, "nimSeqsV2")
defineSymbol(conf.symbols, "nimV2") defineSymbol(conf.symbols, "nimV2")
if conf.exc == excNone and conf.backend != backendCpp:
conf.exc = excGoto
of "hooks": of "hooks":
conf.selectedGC = gcHooks conf.selectedGC = gcHooks
defineSymbol(conf.symbols, "gchooks") defineSymbol(conf.symbols, "gchooks")

View file

@ -192,8 +192,6 @@ proc mainCommand*(graph: ModuleGraph) =
# A better solution might be to fix system.nim # A better solution might be to fix system.nim
undefSymbol(conf.symbols, "useNimRtl") undefSymbol(conf.symbols, "useNimRtl")
of backendInvalid: doAssert false of backendInvalid: doAssert false
if conf.selectedGC in {gcArc, gcOrc} and conf.backend != backendCpp:
conf.exc = excGoto
proc compileToBackend() = proc compileToBackend() =
customizeForBackend(conf.backend) customizeForBackend(conf.backend)

View file

@ -44,3 +44,13 @@ proc setControlCHook(hook: proc () {.noconv.}) = discard
proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} = proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} =
sysFatal(ReraiseDefect, "exception handling is not available") sysFatal(ReraiseDefect, "exception handling is not available")
when gotoBasedExceptions:
var nimInErrorMode {.threadvar.}: bool
proc nimErrorFlag(): ptr bool {.compilerRtl, inl.} =
result = addr(nimInErrorMode)
proc nimTestErrorFlag() {.compilerRtl.} =
if nimInErrorMode:
sysFatal(ReraiseDefect, "exception handling is not available")

View file

@ -24,26 +24,26 @@ const digitsTable = "0001020304050607080910111213141516171819" &
# else: # else:
# res.add $i # res.add $i
# doAssert res == digitsTable # doAssert res == digitsTable
func digits10(num: uint64): int {.noinline.} = func digits10(num: uint64): int {.noinline.} =
if num < 10: if num < 10'u64:
result = 1 result = 1
elif num < 100: elif num < 100'u64:
result = 2 result = 2
elif num < 1_000: elif num < 1_000'u64:
result = 3 result = 3
elif num < 10_000: elif num < 10_000'u64:
result = 4 result = 4
elif num < 100_000: elif num < 100_000'u64:
result = 5 result = 5
elif num < 1_000_000: elif num < 1_000_000'u64:
result = 6 result = 6
elif num < 10_000_000: elif num < 10_000_000'u64:
result = 7 result = 7
elif num < 100_000_000: elif num < 100_000_000'u64:
result = 8 result = 8
elif num < 1_000_000_000: elif num < 1_000_000_000'u64:
result = 9 result = 9
elif num < 10_000_000_000'u64: elif num < 10_000_000_000'u64:
result = 10 result = 10

View file

@ -11,9 +11,4 @@ proc panic(s: string) {.noreturn.} =
rawoutput(s) rawoutput(s)
exit(1) exit(1)
# Alternatively we also could implement these 2 here:
#
# proc sysFatal(exceptn: typeDesc, message: string) {.noReturn.}
# proc sysFatal(exceptn: typeDesc, message, arg: string) {.noReturn.}
{.pop.} {.pop.}

View file

@ -0,0 +1,14 @@
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 rawoutput(s: string) =
printf("%s\n", s)
proc panic(s: string) {.noreturn.} =
rawoutput(s)
exit(1)
{.pop.}

View file

@ -0,0 +1,7 @@
# bug #16404
proc printf(frmt: cstring) {.varargs, header: "<stdio.h>", cdecl.}
var x = 0
inc x
printf("hi %ld\n", x+4777)

View file

@ -0,0 +1,4 @@
--gc:arc
--cpu:avr
--os:standalone
--compileOnly