summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorOscar NihlgÄrd <oscarnihlgard@gmail.com>2019-08-02 23:59:04 +0200
committercooldome <cdome@bk.ru>2019-08-02 22:59:04 +0100
commit50e921bb941d0f1ef728dfb4623f626015556e10 (patch)
tree8225032bc91d1ce2fb9b8890bcb3e893705d4a6c /compiler
parenta906b3952b2d0c6c33c128fac5f5fad0a2d5a598 (diff)
downloadNim-50e921bb941d0f1ef728dfb4623f626015556e10.tar.gz
VM exception fixes (#11868)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/vm.nim12
-rw-r--r--compiler/vmops.nim4
2 files changed, 14 insertions, 2 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 27b067da2..30ba6f32f 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -102,7 +102,8 @@ template stackTrace(c: PCtx, tos: PStackFrame, pc: int, msg: string) =
 
 proc bailOut(c: PCtx; tos: PStackFrame) =
   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):
   {.pragma: computedGoto.}
@@ -1199,8 +1200,15 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
           tos = savedFrame
           move(regs, tos.slots)
     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
+      # Set the `name` field of the exception
+      c.currentExceptionA.sons[2].skipColon.strVal = c.currentExceptionA.typ.sym.name.s
       c.exceptionInstr = pc
 
       var frame = tos
diff --git a/compiler/vmops.nim b/compiler/vmops.nim
index 3bd931b39..5087dabfa 100644
--- a/compiler/vmops.nim
+++ b/compiler/vmops.nim
@@ -79,6 +79,9 @@ proc getCurrentExceptionMsgWrapper(a: VmArgs) {.nimcall.} =
   setResult(a, if a.currentException.isNil: ""
                else: a.currentException.sons[3].skipColon.strVal)
 
+proc getCurrentExceptionWrapper(a: VmArgs) {.nimcall.} =
+  setResult(a, a.currentException)
+
 proc staticWalkDirImpl(path: string, relative: bool): PNode =
   result = newNode(nkBracket)
   for k, f in walkDir(path, relative):
@@ -132,6 +135,7 @@ proc registerAdditionalOps*(c: PCtx) =
     wrap1s(readFile, ioop)
     wrap2si(readLines, ioop)
     systemop getCurrentExceptionMsg
+    systemop getCurrentException
     registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =
       setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1)))
     systemop gorgeEx