# Rumpk Panic Override
# Required for Nim --os:any / --os:standalone
# This file must be named panicoverride.nim

{.push stackTrace: off.}

proc console_write(p: pointer, len: csize_t) {.importc, cdecl.}
proc rumpk_halt() {.importc, cdecl, noreturn.}

proc rawoutput(s: string) =
  if s.len > 0:
    console_write(unsafeAddr s[0], csize_t(s.len))

proc panic(s: cstring) {.exportc, noreturn.} =
  rawoutput("[PANIC] ")
  if s != nil:
    var i = 0
    while s[i] != '\0':
      var buf: array[1, char]
      buf[0] = s[i]
      console_write(addr buf[0], 1)
      inc i
  rawoutput("\n")
  rumpk_halt()

{.pop.}
