mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #4915
This commit is contained in:
@@ -76,12 +76,13 @@ proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int; recursionLimit=100) =
|
||||
msgWriteln(s)
|
||||
|
||||
proc stackTrace(c: PCtx, tos: PStackFrame, pc: int,
|
||||
msg: TMsgKind, arg = "") =
|
||||
msg: TMsgKind, arg = "", n: PNode = nil) =
|
||||
msgWriteln("stack trace: (most recent call last)")
|
||||
stackTraceAux(c, tos, pc)
|
||||
# XXX test if we want 'globalError' for every mode
|
||||
if c.mode == emRepl: globalError(c.debug[pc], msg, arg)
|
||||
else: localError(c.debug[pc], msg, arg)
|
||||
let lineInfo = if n == nil: c.debug[pc] else: n.info
|
||||
if c.mode == emRepl: globalError(lineInfo, msg, arg)
|
||||
else: localError(lineInfo, msg, arg)
|
||||
|
||||
proc bailOut(c: PCtx; tos: PStackFrame) =
|
||||
stackTrace(c, tos, c.exceptionInstr, errUnhandledExceptionX,
|
||||
@@ -1245,7 +1246,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
regs[rc].node.strVal, regs[rd].node.strVal,
|
||||
c.debug[pc])
|
||||
of opcNError:
|
||||
stackTrace(c, tos, pc, errUser, regs[ra].node.strVal)
|
||||
decodeB(rkNode)
|
||||
let a = regs[ra].node
|
||||
let b = regs[rb].node
|
||||
stackTrace(c, tos, pc, errUser, a.strVal, if b.kind == nkNilLit: nil else: b)
|
||||
of opcNWarning:
|
||||
message(c.debug[pc], warnUser, regs[ra].node.strVal)
|
||||
of opcNHint:
|
||||
|
||||
@@ -1068,7 +1068,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||
else:
|
||||
# setter
|
||||
unused(n, dest)
|
||||
genUnaryStmt(c, n, opcNError)
|
||||
genBinaryStmt(c, n, opcNError)
|
||||
of mNCallSite:
|
||||
if dest < 0: dest = c.getTemp(n.typ)
|
||||
c.gABC(n, opcCallSite, dest)
|
||||
|
||||
@@ -235,7 +235,7 @@ proc getImpl*(s: NimSym): NimNode {.magic: "GetImpl", noSideEffect.} =
|
||||
## const.
|
||||
discard
|
||||
|
||||
proc error*(msg: string) {.magic: "NError", benign.}
|
||||
proc error*(msg: string, n: NimNode = nil) {.magic: "NError", benign.}
|
||||
## writes an error message at compile time
|
||||
|
||||
proc warning*(msg: string) {.magic: "NWarning", benign.}
|
||||
@@ -377,19 +377,19 @@ proc expectKind*(n: NimNode, k: NimNodeKind) {.compileTime.} =
|
||||
## checks that `n` is of kind `k`. If this is not the case,
|
||||
## compilation aborts with an error message. This is useful for writing
|
||||
## macros that check the AST that is passed to them.
|
||||
if n.kind != k: error("Expected a node of kind " & $k & ", got " & $n.kind)
|
||||
if n.kind != k: error("Expected a node of kind " & $k & ", got " & $n.kind, n)
|
||||
|
||||
proc expectMinLen*(n: NimNode, min: int) {.compileTime.} =
|
||||
## checks that `n` has at least `min` children. If this is not the case,
|
||||
## compilation aborts with an error message. This is useful for writing
|
||||
## macros that check its number of arguments.
|
||||
if n.len < min: error("macro expects a node with " & $min & " children")
|
||||
if n.len < min: error("macro expects a node with " & $min & " children", n)
|
||||
|
||||
proc expectLen*(n: NimNode, len: int) {.compileTime.} =
|
||||
## checks that `n` has exactly `len` children. If this is not the case,
|
||||
## compilation aborts with an error message. This is useful for writing
|
||||
## macros that check its number of arguments.
|
||||
if n.len != len: error("macro expects a node with " & $len & " children")
|
||||
if n.len != len: error("macro expects a node with " & $len & " children", n)
|
||||
|
||||
proc newTree*(kind: NimNodeKind,
|
||||
children: varargs[NimNode]): NimNode {.compileTime.} =
|
||||
|
||||
@@ -31,6 +31,8 @@ Changes affecting backwards compatibility
|
||||
Library Additions
|
||||
-----------------
|
||||
|
||||
- Added new parameter to ``error`` proc of ``macro`` module to provide better
|
||||
error message
|
||||
|
||||
Tool Additions
|
||||
--------------
|
||||
|
||||
Reference in New Issue
Block a user