Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
- name: Check `nph` formatting
uses: arnetheduck/nph-action@v1
with:
version: 0.6.2
version: 0.7.0
options: "llvm nlvm"
fail: true
suggest: true
2 changes: 1 addition & 1 deletion Nim
Submodule Nim updated 189 files
20 changes: 16 additions & 4 deletions nlvm-lib/nlvm_system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ proc nlvmRaise(e: ref Exception) {.compilerproc, noreturn.} =
c_abort()

proc nlvmReraise() {.compilerproc, noreturn.} =
if not ehGlobals.closureException.isNil:
nlvmRaise(ehGlobals.closureException)

let unwindException = ehGlobals.caughtExceptions
if unwindException.isNil():
nlvmRaise((ref ReraiseDefect)(msg: "no exception to reraise"))
Expand Down Expand Up @@ -369,10 +372,12 @@ proc nlvmReraise() {.compilerproc, noreturn.} =
c_abort()

proc nlvmSetClosureException(e: ref Exception) {.compilerproc.} =
dprintf "set clo: %p\n", addr e[]
ehGlobals.closureException = e

proc nlvmGetCurrentException(): ref Exception {.compilerproc.} =
if not ehGlobals.closureException.isNil:
dprintf("closure: %p\n", addr ehGlobals.closureException[])
ehGlobals.closureException
else:
let unwindException = ehGlobals.caughtExceptions
Expand All @@ -386,6 +391,13 @@ proc nlvmGetCurrentExceptionMsg(): string {.compilerproc.} =
let e = nlvmGetCurrentException()
if e != nil: e.msg else: ""

proc nlvmPushCurrentException(e: sink(ref Exception)) {.compilerRtl, inl.} =
e.up = nlvmGetCurrentException()
nlvmSetClosureException(e)

proc nlvmPopCurrentException() {.compilerRtl, inl.} =
nlvmSetClosureException(nlvmGetCurrentException().up)

proc nlvmBeginCatch(unwindArg: pointer) {.compilerproc.} =
dprintf("begin catch %p\n", unwindArg)
ehGlobals.closureException = nil # Just in case, see workaround notes
Expand All @@ -397,9 +409,9 @@ proc nlvmBeginCatch(unwindArg: pointer) {.compilerproc.} =
dprintf("begin native %d\n", exceptionHeader.handlerCount)
exceptionHeader.handlerCount =
if exceptionHeader.handlerCount < 0:
-exceptionHeader.handlerCount + 1
-exceptionHeader.handlerCount +% 1
else:
exceptionHeader.handlerCount + 1
exceptionHeader.handlerCount +% 1

if ehGlobals.caughtExceptions != unwindException:
exceptionHeader.nextException = ehGlobals.caughtExceptions
Expand All @@ -426,13 +438,13 @@ proc nlvmEndCatch() {.compilerproc.} =
dprintf("end native %d\n", exceptionHeader.handlerCount)
if exceptionHeader.handlerCount < 0:
# Rethrowing
exceptionHeader.handlerCount += 1
exceptionHeader.handlerCount = exceptionHeader.handlerCount +% 1
if exceptionHeader.handlerCount == 0:
ehGlobals.caughtExceptions = exceptionHeader.nextException
else:
# TODO When passing exceptions between threads is supported, this needs
# to be atomic..
exceptionHeader.handlerCount -= 1
exceptionHeader.handlerCount = exceptionHeader.handlerCount -% 1
if exceptionHeader.handlerCount == 0:
ehGlobals.caughtExceptions = exceptionHeader.nextException

Expand Down
Loading
Loading