mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
JS codegen: produce better code for constant sets
This commit is contained in:
@@ -1864,8 +1864,8 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
||||
proc genSetConstr(p: PProc, n: PNode, r: var TCompRes) =
|
||||
var
|
||||
a, b: TCompRes
|
||||
useMagic(p, "SetConstr")
|
||||
r.res = rope("SetConstr(")
|
||||
useMagic(p, "setConstr")
|
||||
r.res = rope("setConstr(")
|
||||
r.kind = resExpr
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
if i > 0: add(r.res, ", ")
|
||||
@@ -1878,6 +1878,12 @@ proc genSetConstr(p: PProc, n: PNode, r: var TCompRes) =
|
||||
gen(p, it, a)
|
||||
add(r.res, a.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) =
|
||||
var a: TCompRes
|
||||
|
||||
@@ -172,7 +172,7 @@ proc raiseIndexError() {.compilerproc, noreturn.} =
|
||||
proc raiseFieldError(f: string) {.compilerproc, noreturn.} =
|
||||
raise newException(FieldError, f & " is not accessible")
|
||||
|
||||
proc SetConstr() {.varargs, asmNoStackFrame, compilerproc.} =
|
||||
proc setConstr() {.varargs, asmNoStackFrame, compilerproc.} =
|
||||
when defined(nimphp):
|
||||
asm """
|
||||
$args = func_get_args();
|
||||
|
||||
Reference in New Issue
Block a user