diff options
author | Hans Raaf <hara@oderwat.de> | 2016-03-04 19:25:41 +0100 |
---|---|---|
committer | Hans Raaf <hara@oderwat.de> | 2016-03-04 23:14:11 +0100 |
commit | 3cc5614d975b8213f336610d9e89a6c42b38b9b9 (patch) | |
tree | 35204333e2c3d21969899e89e9802b5406bbf795 /compiler | |
parent | 3ae45691d294504d33be3d6a602a3b7217ff21de (diff) | |
download | Nim-3cc5614d975b8213f336610d9e89a6c42b38b9b9.tar.gz |
Partial fix for defer in PHP Codegen.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/jsgen.nim | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index d6b546d8b..e80147bd0 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -82,7 +82,7 @@ type TProc = object procDef: PNode prc: PSym - locals, body: Rope + globals, locals, body: Rope options: TOptions module: BModule g: PGlobals @@ -567,6 +567,8 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) = var safePoint = "Tmp$1" % [rope(p.unique)] if optStackTrace in p.options: add(p.body, "framePtr = F;" & tnl) addf(p.body, "try {$n", []) + if p.target == targetPHP and p.globals == nil: + p.globals = "global $lastJSError; global $prevJSError;".rope var a: TCompRes gen(p, n.sons[0], a) moveInto(p, a, r) @@ -609,14 +611,16 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) = addf(p.body, "$1lastJSError = $1prevJSError;$n", [dollar]) if p.target == targetJS: add(p.body, "} finally {" & tnl) + if p.target == targetPHP: + # XXX ugly hack for PHP codegen + add(p.body, "}" & tnl) if i < length and n.sons[i].kind == nkFinally: genStmt(p, n.sons[i].sons[0]) + if p.target == targetPHP: + # XXX ugly hack for PHP codegen + add(p.body, "if($lastJSError) throw($lastJSError);" & tnl) if p.target == targetJS: add(p.body, "}" & tnl) - if p.target == targetPHP: - # we need to repeat the finally block for PHP ... - if i < length and n.sons[i].kind == nkFinally: - genStmt(p, n.sons[i].sons[0]) proc genRaiseStmt(p: PProc, n: PNode) = genLineDir(p, n) @@ -1841,8 +1845,9 @@ proc genProc(oldProc: PProc, prc: PSym): Rope = else: returnStmt = "return $#;$n" % [a.res] genStmt(p, prc.getBody) - result = "function $#($#) {$n$#$#$#$#}$n" % - [name, header, p.locals, resultAsgn, + + result = "function $#($#) {$n$#$n$#$#$#$#}$n" % + [name, header, p.globals, p.locals, resultAsgn, genProcBody(p, prc), returnStmt] #if gVerbosity >= 3: # echo "END generated code for: " & prc.name.s |