JS codegen: produce better code for constant sets
This commit is contained in:
parent
3d34a9f6d3
commit
56a5c249c9
2 changed files with 9 additions and 3 deletions
|
|
@ -1864,8 +1864,8 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
proc genSetConstr(p: PProc, n: PNode, r: var TCompRes) =
|
proc genSetConstr(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
var
|
var
|
||||||
a, b: TCompRes
|
a, b: TCompRes
|
||||||
useMagic(p, "SetConstr")
|
useMagic(p, "setConstr")
|
||||||
r.res = rope("SetConstr(")
|
r.res = rope("setConstr(")
|
||||||
r.kind = resExpr
|
r.kind = resExpr
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
if i > 0: add(r.res, ", ")
|
if i > 0: add(r.res, ", ")
|
||||||
|
|
@ -1878,6 +1878,12 @@ proc genSetConstr(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
gen(p, it, a)
|
gen(p, it, a)
|
||||||
add(r.res, a.res)
|
add(r.res, a.res)
|
||||||
add(r.res, ")")
|
add(r.res, ")")
|
||||||
|
# emit better code for constant sets:
|
||||||
|
if p.target == targetJS and isDeepConstExpr(n):
|
||||||
|
inc(p.g.unique)
|
||||||
|
let tmp = rope("ConstSet") & rope(p.g.unique)
|
||||||
|
addf(p.g.constants, "var $1 = $2;$n", [tmp, r.res])
|
||||||
|
r.res = tmp
|
||||||
|
|
||||||
proc genArrayConstr(p: PProc, n: PNode, r: var TCompRes) =
|
proc genArrayConstr(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
var a: TCompRes
|
var a: TCompRes
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ proc raiseIndexError() {.compilerproc, noreturn.} =
|
||||||
proc raiseFieldError(f: string) {.compilerproc, noreturn.} =
|
proc raiseFieldError(f: string) {.compilerproc, noreturn.} =
|
||||||
raise newException(FieldError, f & " is not accessible")
|
raise newException(FieldError, f & " is not accessible")
|
||||||
|
|
||||||
proc SetConstr() {.varargs, asmNoStackFrame, compilerproc.} =
|
proc setConstr() {.varargs, asmNoStackFrame, compilerproc.} =
|
||||||
when defined(nimphp):
|
when defined(nimphp):
|
||||||
asm """
|
asm """
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue