diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2020-01-25 20:00:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-25 20:00:13 +0100 |
commit | 6efac70181f54d24627b101ede6c79b8c3e74a96 (patch) | |
tree | 4ae2ee9081f66229ade8babe8c6cde16b59bb02f /lib | |
parent | 4f3dd33509070f0f50bbe5bbb6cbfc8a12b47b49 (diff) | |
download | Nim-6efac70181f54d24627b101ede6c79b8c3e74a96.tar.gz |
make goto based exceptions available for 'nim cpp' (#13244)
* make goto based exceptions available for 'nim cpp' * optimize seq.add to be comparable to C++'s emplace_back
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/excpt.nim | 8 | ||||
-rw-r--r-- | lib/system/memtracker.nim | 2 | ||||
-rw-r--r-- | lib/system/seqs_v2.nim | 6 |
3 files changed, 10 insertions, 6 deletions
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 91cf9aa3e..a9c7ba02a 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -61,7 +61,7 @@ var currException {.threadvar.}: ref Exception gcFramePtr {.threadvar.}: GcFrame -when defined(cpp) and not defined(noCppExceptions): +when defined(cpp) and not defined(noCppExceptions) and not gotoBasedExceptions: var raiseCounter {.threadvar.}: uint @@ -410,7 +410,7 @@ proc reportUnhandledError(e: ref Exception) {.nodestroy.} = discard() proc nimLeaveFinally() {.compilerRtl.} = - when defined(cpp) and not defined(noCppExceptions): + when defined(cpp) and not defined(noCppExceptions) and not gotoBasedExceptions: {.emit: "throw;".} else: if excHandler != nil: @@ -439,7 +439,7 @@ proc raiseExceptionAux(e: sink(ref Exception)) {.nodestroy.} = if not localRaiseHook(e): return if globalRaiseHook != nil: if not globalRaiseHook(e): return - when defined(cpp) and not defined(noCppExceptions): + when defined(cpp) and not defined(noCppExceptions) and not gotoBasedExceptions: if e == currException: {.emit: "throw;".} else: @@ -544,7 +544,7 @@ proc nimFrame(s: PFrame) {.compilerRtl, inl, raises: [].} = framePtr = s if s.calldepth == nimCallDepthLimit: callDepthLimitReached() -when defined(cpp) and appType != "lib" and +when defined(cpp) and appType != "lib" and not gotoBasedExceptions and not defined(js) and not defined(nimscript) and hostOS != "standalone" and not defined(noCppExceptions): diff --git a/lib/system/memtracker.nim b/lib/system/memtracker.nim index 69c8d5575..115d4a973 100644 --- a/lib/system/memtracker.nim +++ b/lib/system/memtracker.nim @@ -80,7 +80,7 @@ proc addEntry(entry: LogEntry) = #inc gLog.count #gLog.disabled = false -proc memTrackerWrite(address: pointer; size: int; file: cstring; line: int) {.compilerProc.} = +proc memTrackerWrite(address: pointer; size: int; file: cstring; line: int) {.compilerproc.} = addEntry LogEntry(op: "write", address: address, size: size, file: file, line: line, thread: myThreadId()) diff --git a/lib/system/seqs_v2.nim b/lib/system/seqs_v2.nim index f28bcadca..3bd5e291b 100644 --- a/lib/system/seqs_v2.nim +++ b/lib/system/seqs_v2.nim @@ -92,7 +92,7 @@ proc grow*[T](x: var seq[T]; newLen: Natural; value: T) = for i in oldLen .. newLen-1: xu.p.data[i] = value -proc add*[T](x: var seq[T]; value: sink T) {.magic: "AppendSeqElem", noSideEffect.} = +proc add*[T](x: var seq[T]; value: sink T) {.magic: "AppendSeqElem", noSideEffect, nodestroy.} = ## Generic proc for adding a data item `y` to a container `x`. ## ## For containers that have an order, `add` means *append*. New generic @@ -104,6 +104,10 @@ proc add*[T](x: var seq[T]; value: sink T) {.magic: "AppendSeqElem", noSideEffec if xu.p == nil or xu.p.cap < oldLen+1: xu.p = cast[typeof(xu.p)](prepareSeqAdd(oldLen, xu.p, 1, sizeof(T))) xu.len = oldLen+1 + # .nodestroy means `xu.p.data[oldLen] = value` is compiled into a + # copyMem(). This is fine as know by construction that + # in `xu.p.data[oldLen]` there is nothing to destroy. + # We also save the `wasMoved + destroy` pair for the sink parameter. xu.p.data[oldLen] = value proc setLen[T](s: var seq[T], newlen: Natural) = |