fixes #99
This commit is contained in:
parent
547e8aa418
commit
a13a14327a
2 changed files with 37 additions and 6 deletions
|
|
@ -158,9 +158,9 @@ proc blockLeaveActions(p: BProc, howMany: int) =
|
||||||
|
|
||||||
proc genReturnStmt(p: BProc, t: PNode) =
|
proc genReturnStmt(p: BProc, t: PNode) =
|
||||||
p.beforeRetNeeded = true
|
p.beforeRetNeeded = true
|
||||||
blockLeaveActions(p, min(1, p.nestedTryStmts.len))
|
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
if (t.sons[0].kind != nkEmpty): genStmts(p, t.sons[0])
|
if (t.sons[0].kind != nkEmpty): genStmts(p, t.sons[0])
|
||||||
|
blockLeaveActions(p, min(1, p.nestedTryStmts.len))
|
||||||
appff(p.s[cpsStmts], "goto BeforeRet;$n", "br label %BeforeRet$n", [])
|
appff(p.s[cpsStmts], "goto BeforeRet;$n", "br label %BeforeRet$n", [])
|
||||||
|
|
||||||
proc genWhileStmt(p: BProc, t: PNode) =
|
proc genWhileStmt(p: BProc, t: PNode) =
|
||||||
|
|
@ -529,7 +529,7 @@ proc genTryStmt(p: BProc, t: PNode) =
|
||||||
discard cgsym(p.module, "E_Base")
|
discard cgsym(p.module, "E_Base")
|
||||||
appcg(p, cpsLocals, "#TSafePoint $1;$n", [safePoint])
|
appcg(p, cpsLocals, "#TSafePoint $1;$n", [safePoint])
|
||||||
appcg(p, cpsStmts, "#pushSafePoint(&$1);$n" &
|
appcg(p, cpsStmts, "#pushSafePoint(&$1);$n" &
|
||||||
"$1.status = setjmp($1.context);$n", [safePoint])
|
"$1.status = setjmp($1.context);$n", [safePoint])
|
||||||
if optStackTrace in p.Options:
|
if optStackTrace in p.Options:
|
||||||
appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
|
appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
|
||||||
appf(p.s[cpsStmts], "if ($1.status == 0) {$n", [safePoint])
|
appf(p.s[cpsStmts], "if ($1.status == 0) {$n", [safePoint])
|
||||||
|
|
@ -544,10 +544,11 @@ proc genTryStmt(p: BProc, t: PNode) =
|
||||||
if blen == 1:
|
if blen == 1:
|
||||||
# general except section:
|
# general except section:
|
||||||
if i > 1: appf(p.s[cpsStmts], "else {$n")
|
if i > 1: appf(p.s[cpsStmts], "else {$n")
|
||||||
|
appcg(p, cpsStmts, "$1.status = 0;$n", [safePoint])
|
||||||
inc p.popCurrExc
|
inc p.popCurrExc
|
||||||
genStmts(p, t.sons[i].sons[0])
|
genStmts(p, t.sons[i].sons[0])
|
||||||
dec p.popCurrExc
|
dec p.popCurrExc
|
||||||
appcg(p, cpsStmts, "$1.status = 0;#popCurrentException();$n", [safePoint])
|
appcg(p, cpsStmts, "#popCurrentException();$n", [])
|
||||||
if i > 1: appf(p.s[cpsStmts], "}$n")
|
if i > 1: appf(p.s[cpsStmts], "}$n")
|
||||||
else:
|
else:
|
||||||
inc p.popCurrExc
|
inc p.popCurrExc
|
||||||
|
|
@ -560,11 +561,11 @@ proc genTryStmt(p: BProc, t: PNode) =
|
||||||
[genTypeInfo(p.module, t.sons[i].sons[j].typ)])
|
[genTypeInfo(p.module, t.sons[i].sons[j].typ)])
|
||||||
if i > 1: app(p.s[cpsStmts], "else ")
|
if i > 1: app(p.s[cpsStmts], "else ")
|
||||||
appf(p.s[cpsStmts], "if ($1) {$n", [orExpr])
|
appf(p.s[cpsStmts], "if ($1) {$n", [orExpr])
|
||||||
|
appcg(p, cpsStmts, "$1.status = 0;$n", [safePoint])
|
||||||
genStmts(p, t.sons[i].sons[blen-1])
|
genStmts(p, t.sons[i].sons[blen-1])
|
||||||
dec p.popCurrExc
|
dec p.popCurrExc
|
||||||
# code to clear the exception:
|
# code to clear the exception:
|
||||||
appcg(p, cpsStmts, "$1.status = 0;#popCurrentException();}$n",
|
appcg(p, cpsStmts, "#popCurrentException();}$n", [])
|
||||||
[safePoint])
|
|
||||||
inc(i)
|
inc(i)
|
||||||
appf(p.s[cpsStmts], "}$n") # end of if statement
|
appf(p.s[cpsStmts], "}$n") # end of if statement
|
||||||
if i < length and t.sons[i].kind == nkFinally:
|
if i < length and t.sons[i].kind == nkFinally:
|
||||||
|
|
|
||||||
30
tests/run/texcpt1.nim
Normal file
30
tests/run/texcpt1.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
discard """
|
||||||
|
outputsub: "-6"
|
||||||
|
"""
|
||||||
|
type
|
||||||
|
ESomething = object of E_Base
|
||||||
|
ESomeOtherErr = object of E_Base
|
||||||
|
|
||||||
|
proc genErrors(s: string) =
|
||||||
|
if s == "error!":
|
||||||
|
raise newException(ESomething, "Test")
|
||||||
|
else:
|
||||||
|
raise newException(EsomeotherErr, "bla")
|
||||||
|
|
||||||
|
proc raiseBla(): int =
|
||||||
|
try:
|
||||||
|
genErrors("errssor!")
|
||||||
|
except ESomething:
|
||||||
|
echo("Error happened")
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
|
||||||
|
proc blah(): int =
|
||||||
|
try:
|
||||||
|
result = raiseBla()
|
||||||
|
except ESomeOtherErr:
|
||||||
|
result = -6
|
||||||
|
|
||||||
|
echo blah()
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue