From 3cc5614d975b8213f336610d9e89a6c42b38b9b9 Mon Sep 17 00:00:00 2001 From: Hans Raaf Date: Fri, 4 Mar 2016 19:25:41 +0100 Subject: Partial fix for defer in PHP Codegen. --- compiler/jsgen.nim | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'compiler') 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 -- cgit 1.4.1-2-gfad0