diff options
author | Araq <rumpf_a@web.de> | 2013-01-11 01:08:37 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-01-11 01:08:37 +0100 |
commit | 4670445a935e2555f4c5c41f810b606fe5abaa0d (patch) | |
tree | a71df57d721e3e9add158114e00bcc8dd5cd4a0d /compiler/ecmasgen.nim | |
parent | 86b19c44eba8a1572feaeb47f039e5da5478720a (diff) | |
download | Nim-4670445a935e2555f4c5c41f810b606fe5abaa0d.tar.gz |
'importcpp' for the JS target to generate an infix call
Diffstat (limited to 'compiler/ecmasgen.nim')
-rwxr-xr-x | compiler/ecmasgen.nim | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/compiler/ecmasgen.nim b/compiler/ecmasgen.nim index 25d147ebc..8899c904e 100755 --- a/compiler/ecmasgen.nim +++ b/compiler/ecmasgen.nim @@ -1,7 +1,7 @@ # # # The Nimrod Compiler -# (c) Copyright 2012 Andreas Rumpf +# (c) Copyright 2013 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -964,24 +964,45 @@ proc genDeref(p: var TProc, n: PNode, r: var TCompRes) = if a.kind != etyBaseIndex: InternalError(n.info, "genDeref") r.res = ropef("$1[$2]", [a.com, a.res]) +proc genArg(p: var TProc, n: PNode, r: var TCompRes) = + var a: TCompRes + gen(p, n, a) + if a.kind == etyBaseIndex: + app(r.res, a.com) + app(r.res, ", ") + app(r.res, a.res) + else: + app(r.res, mergeExpr(a)) + proc genArgs(p: var TProc, n: PNode, r: var TCompRes) = app(r.res, "(") for i in countup(1, sonsLen(n) - 1): if i > 1: app(r.res, ", ") - var a: TCompRes - gen(p, n.sons[i], a) - if a.kind == etyBaseIndex: - app(r.res, a.com) - app(r.res, ", ") - app(r.res, a.res) - else: - app(r.res, mergeExpr(a)) + genArg(p, n.sons[i], r) app(r.res, ")") proc genCall(p: var TProc, n: PNode, r: var TCompRes) = gen(p, n.sons[0], r) genArgs(p, n, r) +proc genInfixCall(p: var TProc, n: PNode, r: var TCompRes) = + gen(p, n.sons[1], r) + if r.kind == etyBaseIndex: + if r.com == nil: + GlobalError(n.info, "cannot invoke with infix syntax") + r.res = ropef("$1[0]", [r.res, r.com]) + r.com = nil + app(r.res, ".") + var op: TCompRes + gen(p, n.sons[0], op) + app(r.res, mergeExpr(op)) + + app(r.res, "(") + for i in countup(2, sonsLen(n) - 1): + if i > 2: app(r.res, ", ") + genArg(p, n.sons[i], r) + app(r.res, ")") + proc genEcho(p: var TProc, n: PNode, r: var TCompRes) = useMagic(p, "rawEcho") app(r.res, "rawEcho") @@ -1513,9 +1534,12 @@ proc gen(p: var TProc, n: PNode, r: var TCompRes) = else: r.res = toRope(f.ToStrMaxPrecision) of nkBlockExpr: genBlock(p, n, r) of nkIfExpr: genIfExpr(p, n, r) - of nkCallKinds: + of nkCallKinds: if (n.sons[0].kind == nkSym) and (n.sons[0].sym.magic != mNone): genMagic(p, n, r) + elif n.sons[0].kind == nkSym and sfInfixCall in n.sons[0].sym.flags and + n.len >= 2: + genInfixCall(p, n, r) else: genCall(p, n, r) of nkCurly: genSetConstr(p, n, r) |