Merge pull request #3934 from oderwat/php-fix-defer
Fix for defer in PHP Codegen.
This commit is contained in:
commit
749ce2f36a
1 changed files with 12 additions and 7 deletions
|
|
@ -82,7 +82,7 @@ type
|
||||||
TProc = object
|
TProc = object
|
||||||
procDef: PNode
|
procDef: PNode
|
||||||
prc: PSym
|
prc: PSym
|
||||||
locals, body: Rope
|
globals, locals, body: Rope
|
||||||
options: TOptions
|
options: TOptions
|
||||||
module: BModule
|
module: BModule
|
||||||
g: PGlobals
|
g: PGlobals
|
||||||
|
|
@ -567,6 +567,8 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
var safePoint = "Tmp$1" % [rope(p.unique)]
|
var safePoint = "Tmp$1" % [rope(p.unique)]
|
||||||
if optStackTrace in p.options: add(p.body, "framePtr = F;" & tnl)
|
if optStackTrace in p.options: add(p.body, "framePtr = F;" & tnl)
|
||||||
addf(p.body, "try {$n", [])
|
addf(p.body, "try {$n", [])
|
||||||
|
if p.target == targetPHP and p.globals == nil:
|
||||||
|
p.globals = "global $lastJSError; global $prevJSError;".rope
|
||||||
var a: TCompRes
|
var a: TCompRes
|
||||||
gen(p, n.sons[0], a)
|
gen(p, n.sons[0], a)
|
||||||
moveInto(p, a, r)
|
moveInto(p, a, r)
|
||||||
|
|
@ -609,14 +611,16 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
addf(p.body, "$1lastJSError = $1prevJSError;$n", [dollar])
|
addf(p.body, "$1lastJSError = $1prevJSError;$n", [dollar])
|
||||||
if p.target == targetJS:
|
if p.target == targetJS:
|
||||||
add(p.body, "} finally {" & tnl)
|
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:
|
if i < length and n.sons[i].kind == nkFinally:
|
||||||
genStmt(p, n.sons[i].sons[0])
|
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:
|
if p.target == targetJS:
|
||||||
add(p.body, "}" & tnl)
|
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) =
|
proc genRaiseStmt(p: PProc, n: PNode) =
|
||||||
genLineDir(p, n)
|
genLineDir(p, n)
|
||||||
|
|
@ -1850,8 +1854,9 @@ proc genProc(oldProc: PProc, prc: PSym): Rope =
|
||||||
else:
|
else:
|
||||||
returnStmt = "return $#;$n" % [a.res]
|
returnStmt = "return $#;$n" % [a.res]
|
||||||
genStmt(p, prc.getBody)
|
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]
|
genProcBody(p, prc), returnStmt]
|
||||||
#if gVerbosity >= 3:
|
#if gVerbosity >= 3:
|
||||||
# echo "END generated code for: " & prc.name.s
|
# echo "END generated code for: " & prc.name.s
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue