VM exception fixes (#11868)
This commit is contained in:
parent
a906b3952b
commit
50e921bb94
3 changed files with 28 additions and 2 deletions
|
|
@ -102,7 +102,8 @@ template stackTrace(c: PCtx, tos: PStackFrame, pc: int, msg: string) =
|
||||||
|
|
||||||
proc bailOut(c: PCtx; tos: PStackFrame) =
|
proc bailOut(c: PCtx; tos: PStackFrame) =
|
||||||
stackTrace(c, tos, c.exceptionInstr, "unhandled exception: " &
|
stackTrace(c, tos, c.exceptionInstr, "unhandled exception: " &
|
||||||
c.currentExceptionA.sons[3].skipColon.strVal)
|
c.currentExceptionA.sons[3].skipColon.strVal &
|
||||||
|
" [" & c.currentExceptionA.sons[2].skipColon.strVal & "]")
|
||||||
|
|
||||||
when not defined(nimComputedGoto):
|
when not defined(nimComputedGoto):
|
||||||
{.pragma: computedGoto.}
|
{.pragma: computedGoto.}
|
||||||
|
|
@ -1199,8 +1200,15 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
tos = savedFrame
|
tos = savedFrame
|
||||||
move(regs, tos.slots)
|
move(regs, tos.slots)
|
||||||
of opcRaise:
|
of opcRaise:
|
||||||
let raised = regs[ra].node
|
let raised =
|
||||||
|
# Empty `raise` statement - reraise current exception
|
||||||
|
if regs[ra].kind == rkNone:
|
||||||
|
c.currentExceptionA
|
||||||
|
else:
|
||||||
|
regs[ra].node
|
||||||
c.currentExceptionA = raised
|
c.currentExceptionA = raised
|
||||||
|
# Set the `name` field of the exception
|
||||||
|
c.currentExceptionA.sons[2].skipColon.strVal = c.currentExceptionA.typ.sym.name.s
|
||||||
c.exceptionInstr = pc
|
c.exceptionInstr = pc
|
||||||
|
|
||||||
var frame = tos
|
var frame = tos
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,9 @@ proc getCurrentExceptionMsgWrapper(a: VmArgs) {.nimcall.} =
|
||||||
setResult(a, if a.currentException.isNil: ""
|
setResult(a, if a.currentException.isNil: ""
|
||||||
else: a.currentException.sons[3].skipColon.strVal)
|
else: a.currentException.sons[3].skipColon.strVal)
|
||||||
|
|
||||||
|
proc getCurrentExceptionWrapper(a: VmArgs) {.nimcall.} =
|
||||||
|
setResult(a, a.currentException)
|
||||||
|
|
||||||
proc staticWalkDirImpl(path: string, relative: bool): PNode =
|
proc staticWalkDirImpl(path: string, relative: bool): PNode =
|
||||||
result = newNode(nkBracket)
|
result = newNode(nkBracket)
|
||||||
for k, f in walkDir(path, relative):
|
for k, f in walkDir(path, relative):
|
||||||
|
|
@ -132,6 +135,7 @@ proc registerAdditionalOps*(c: PCtx) =
|
||||||
wrap1s(readFile, ioop)
|
wrap1s(readFile, ioop)
|
||||||
wrap2si(readLines, ioop)
|
wrap2si(readLines, ioop)
|
||||||
systemop getCurrentExceptionMsg
|
systemop getCurrentExceptionMsg
|
||||||
|
systemop getCurrentException
|
||||||
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =
|
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =
|
||||||
setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1)))
|
setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1)))
|
||||||
systemop gorgeEx
|
systemop gorgeEx
|
||||||
|
|
|
||||||
14
tests/vm/texception.nim
Normal file
14
tests/vm/texception.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
proc someFunc() =
|
||||||
|
try:
|
||||||
|
raise newException(ValueError, "message")
|
||||||
|
except ValueError as err:
|
||||||
|
doAssert err.name == "ValueError"
|
||||||
|
doAssert err.msg == "message"
|
||||||
|
raise
|
||||||
|
|
||||||
|
static:
|
||||||
|
try:
|
||||||
|
someFunc()
|
||||||
|
except:
|
||||||
|
discard
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue