From 843bb14807b9d5402ec5ca22f5f782fbd59ee349 Mon Sep 17 00:00:00 2001 From: araq Date: Tue, 18 Nov 2025 20:34:41 +0100 Subject: [PATCH 1/2] progress --- lib/system/excpt.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index ea0eb13c81..c5d82a2788 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -597,6 +597,8 @@ proc callDepthLimitReached() {.noinline.} = showErrorMessage2(msg) rawQuit(1) +{.push overflowChecks: off.} + proc nimFrame(s: PFrame) {.compilerRtl, inl, raises: [].} = if framePtr == nil: s.calldepth = 0 @@ -608,6 +610,8 @@ proc nimFrame(s: PFrame) {.compilerRtl, inl, raises: [].} = framePtr = s if s.calldepth == nimCallDepthLimit: callDepthLimitReached() +{.pop.} + when defined(cpp) and appType != "lib" and not gotoBasedExceptions and not defined(js) and not defined(nimscript) and hostOS != "standalone" and hostOS != "any" and not defined(noCppExceptions) and @@ -634,7 +638,7 @@ when defined(cpp) and appType != "lib" and not gotoBasedExceptions and msg = currException.getStackTrace() & "Error: unhandled exception: " & currException.msg & " [" & cstrToStrBuiltin(currException.name) & "]" except StdException as e: - msg = "Error: unhandled cpp exception: " & $e.what() + msg = "Error: unhandled cpp exception: " & cstrToStrBuiltin(e.what()) except: msg = "Error: unhandled unknown cpp exception" From 51028a828d01e6a40a882e02e3b5792f0cae827a Mon Sep 17 00:00:00 2001 From: araq Date: Tue, 18 Nov 2025 21:25:35 +0100 Subject: [PATCH 2/2] yay --- lib/system.nim | 43 ++++++++++++++++++++++--------------------- lib/system/excpt.nim | 4 +++- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index b1774b965f..5813651869 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1740,6 +1740,28 @@ when not defined(nimscript): when not declared(sysFatal): include "system/fatal" +proc echo*(x: varargs[typed, `$`]) {.magic: "Echo", benign, sideEffect.} + ## Writes and flushes the parameters to the standard output. + ## + ## Special built-in that takes a variable number of arguments. Each argument + ## is converted to a string via `$`, so it works for user-defined + ## types that have an overloaded `$` operator. + ## It is roughly equivalent to `writeLine(stdout, x); flushFile(stdout)`, but + ## available for the JavaScript target too. + ## + ## Unlike other IO operations this is guaranteed to be thread-safe as + ## `echo` is very often used for debugging convenience. If you want to use + ## `echo` inside a `proc without side effects + ## `_ you can use `debugEcho + ## <#debugEcho,varargs[typed,]>`_ instead. + +proc debugEcho*(x: varargs[typed, `$`]) {.magic: "Echo", noSideEffect, + tags: [], raises: [].} + ## Same as `echo <#echo,varargs[typed,]>`_, but as a special semantic rule, + ## `debugEcho` pretends to be free of side effects, so that it can be used + ## for debugging routines marked as `noSideEffect + ## `_. + type PFrame* = ptr TFrame ## Represents a runtime frame of the call stack; ## part of the debugger API. @@ -2002,27 +2024,6 @@ elif hasAlloc: inc(i) {.pop.} -proc echo*(x: varargs[typed, `$`]) {.magic: "Echo", benign, sideEffect.} - ## Writes and flushes the parameters to the standard output. - ## - ## Special built-in that takes a variable number of arguments. Each argument - ## is converted to a string via `$`, so it works for user-defined - ## types that have an overloaded `$` operator. - ## It is roughly equivalent to `writeLine(stdout, x); flushFile(stdout)`, but - ## available for the JavaScript target too. - ## - ## Unlike other IO operations this is guaranteed to be thread-safe as - ## `echo` is very often used for debugging convenience. If you want to use - ## `echo` inside a `proc without side effects - ## `_ you can use `debugEcho - ## <#debugEcho,varargs[typed,]>`_ instead. - -proc debugEcho*(x: varargs[typed, `$`]) {.magic: "Echo", noSideEffect, - tags: [], raises: [].} - ## Same as `echo <#echo,varargs[typed,]>`_, but as a special semantic rule, - ## `debugEcho` pretends to be free of side effects, so that it can be used - ## for debugging routines marked as `noSideEffect - ## `_. when hostOS == "standalone" and defined(nogc): proc nimToCStringConv(s: NimString): cstring {.compilerproc, inline.} = diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index c5d82a2788..2fb958999f 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -43,6 +43,8 @@ proc writeToStdErr(msg: string) {.inline.} = writeToStdErr(msg.cstring, msg.len) proc cstrToStrBuiltin(x: cstring): string {.magic: "CStrToStr", noSideEffect.} +when defined(genode): + template `$`(s: string): string = s proc showErrorMessage(data: cstring, length: int) {.gcsafe, raises: [].} = var toWrite = true @@ -55,7 +57,7 @@ proc showErrorMessage(data: cstring, length: int) {.gcsafe, raises: [].} = if toWrite: when defined(genode): # stderr not available by default, use the LOG session - echo data + echo cstrToStrBuiltin(data) else: writeToStdErr(data, length)