diff options
-rwxr-xr-x | compiler/ast.nim | 1 | ||||
-rwxr-xr-x | compiler/ccgexprs.nim | 78 | ||||
-rwxr-xr-x | compiler/ecmasgen.nim | 1 | ||||
-rwxr-xr-x | compiler/evals.nim | 1 | ||||
-rwxr-xr-x | compiler/renderer.nim | 6 | ||||
-rwxr-xr-x | compiler/semexprs.nim | 3 | ||||
-rwxr-xr-x | compiler/semfold.nim | 1 | ||||
-rwxr-xr-x | compiler/semtempl.nim | 2 | ||||
-rwxr-xr-x | compiler/semthreads.nim | 2 | ||||
-rwxr-xr-x | compiler/sigmatch.nim | 4 | ||||
-rwxr-xr-x | compiler/transf.nim | 21 | ||||
-rwxr-xr-x | lib/core/macros.nim | 2 |
12 files changed, 50 insertions, 72 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index eb214e87f..e9bf532b1 100755 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -112,7 +112,6 @@ type nkChckRange, # range check for ints nkStringToCString, # string to cstring nkCStringToString, # cstring to string - nkPassAsOpenArray, # thing is passed as an open array # end of expressions nkAsgn, # a = b diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index ef0d6bc85..13b26f6ac 100755 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -819,6 +819,29 @@ proc fixupCall(p: BProc, t: PNode, d: var TLoc, pl: PRope) = app(p.s[cpsStmts], pl) app(p.s[cpsStmts], ';' & tnl) +proc openArrayLoc(a: TLoc): PRope = + case skipTypes(a.t, abstractVar).kind + of tyOpenArray: + result = ropef("$1, $1Len0", [rdLoc(a)]) + of tyString, tySequence: + result = ropef("$1->data, $1->$2", [rdLoc(a), lenField()]) + of tyArray, tyArrayConstr: + result = ropef("$1, $2", [rdLoc(a), toRope(lengthOrd(a.t))]) + else: InternalError("openArrayLoc: " & typeToString(a.t)) + +proc genArg(p: BProc, n: PNode, param: PSym): PRope = + var a: TLoc + if skipTypes(param.typ, abstractVar).kind == tyOpenArray: + var n = if n.kind != nkHiddenAddr: n else: n.sons[0] + initLocExpr(p, n, a) + result = openArrayLoc(a) + elif ccgIntroducedPtr(param): + initLocExpr(p, n, a) + result = addrLoc(a) + else: + initLocExpr(p, n, a) + result = rdLoc(a) + proc genCall(p: BProc, t: PNode, d: var TLoc) = var op, a: TLoc # this is a hotspot in the compiler @@ -828,14 +851,12 @@ proc genCall(p: BProc, t: PNode, d: var TLoc) = assert(typ.kind == tyProc) var length = sonsLen(t) for i in countup(1, length - 1): - initLocExpr(p, t.sons[i], a) # generate expression for param assert(sonsLen(typ) == sonsLen(typ.n)) if i < sonsLen(typ): assert(typ.n.sons[i].kind == nkSym) - var param = typ.n.sons[i].sym - if ccgIntroducedPtr(param): app(pl, addrLoc(a)) - else: app(pl, rdLoc(a)) + app(pl, genArg(p, t.sons[i], typ.n.sons[i].sym)) else: + initLocExpr(p, t.sons[i], a) # generate expression for param app(pl, rdLoc(a)) if i < length - 1: app(pl, ", ") fixupCall(p, t, d, pl) @@ -847,26 +868,22 @@ proc genInfixCall(p: BProc, t: PNode, d: var TLoc) = var typ = t.sons[0].typ # getUniqueType() is too expensive here! assert(typ.kind == tyProc) var length = sonsLen(t) - initLocExpr(p, t.sons[1], a) # generate expression for first param assert(sonsLen(typ) == sonsLen(typ.n)) var param = typ.n.sons[1].sym - if ccgIntroducedPtr(param): app(pl, addrLoc(a)) - else: app(pl, rdLoc(a)) + app(pl, genArg(p, t.sons[1], param)) if skipTypes(param.typ, {tyGenericInst}).kind == tyPtr: app(pl, "->") else: app(pl, ".") app(pl, op.r) app(pl, "(") for i in countup(2, length - 1): - initLocExpr(p, t.sons[i], a) # generate expression for param assert(sonsLen(typ) == sonsLen(typ.n)) if i < sonsLen(typ): assert(typ.n.sons[i].kind == nkSym) - var param = typ.n.sons[i].sym - if ccgIntroducedPtr(param): app(pl, addrLoc(a)) - else: app(pl, rdLoc(a)) + app(pl, genArg(p, t.sons[i], typ.n.sons[i].sym)) else: + initLocExpr(p, t.sons[i], a) # generate expression for param app(pl, rdLoc(a)) if i < length - 1: app(pl, ", ") fixupCall(p, t, d, pl) @@ -882,30 +899,22 @@ proc genNamedParamCall(p: BProc, t: PNode, d: var TLoc) = assert(sonsLen(typ) == sonsLen(typ.n)) if length > 1: - initLocExpr(p, t.sons[1], a) - var param = typ.n.sons[1].sym - if ccgIntroducedPtr(param): app(pl, addrLoc(a)) - else: app(pl, rdLoc(a)) + app(pl, genArg(p, t.sons[1], typ.n.sons[1].sym)) app(pl, " ") app(pl, op.r) if length > 2: - initLocExpr(p, t.sons[2], a) app(pl, ": ") - var param = typ.n.sons[2].sym - if ccgIntroducedPtr(param): app(pl, addrLoc(a)) - else: app(pl, rdLoc(a)) + app(pl, genArg(p, t.sons[2], typ.n.sons[2].sym)) for i in countup(3, length-1): - initLocExpr(p, t.sons[i], a) # generate expression for param assert(sonsLen(typ) == sonsLen(typ.n)) - if i >= sonsLen(typ): + if i >= sonsLen(typ): InternalError(t.info, "varargs for objective C method?") assert(typ.n.sons[i].kind == nkSym) var param = typ.n.sons[i].sym app(pl, " ") app(pl, param.name.s) app(pl, ": ") - if ccgIntroducedPtr(param): app(pl, addrLoc(a)) - else: app(pl, rdLoc(a)) + app(pl, genArg(p, t.sons[i], param)) if typ.sons[0] != nil: if isInvalidReturnType(typ.sons[0]): if sonsLen(t) > 1: app(pl, " ") @@ -1174,10 +1183,11 @@ proc genDollar(p: BProc, n: PNode, d: var TLoc, frmt: string) = genAssignment(p, d, a, {}) proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) = - var typ = skipTypes(e.sons[1].Typ, abstractPtrs) + var a = e.sons[1] + if a.kind == nkHiddenAddr: a = a.sons[0] + var typ = skipTypes(a.Typ, abstractVar) case typ.kind of tyOpenArray: - while e.sons[1].kind == nkPassAsOpenArray: e.sons[1] = e.sons[1].sons[0] if op == mHigh: unaryExpr(p, e, d, "($1Len0-1)") else: unaryExpr(p, e, d, "$1Len0") of tyCstring: @@ -1386,23 +1396,6 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) = proc genConv(p: BProc, e: PNode, d: var TLoc) = genCast(p, e, d) -proc passToOpenArray(p: BProc, n: PNode, d: var TLoc) = - var a: TLoc - while n.sons[0].kind == nkPassAsOpenArray: - n.sons[0] = n.sons[0].sons[0] # BUGFIX - var dest = skipTypes(n.typ, abstractVar) - case skipTypes(n.sons[0].typ, abstractVar).kind - of tyOpenArray: - initLocExpr(p, n.sons[0], a) - putIntoDest(p, d, dest, ropef("$1, $1Len0", [rdLoc(a)])) - of tyString, tySequence: - initLocExpr(p, n.sons[0], a) - putIntoDest(p, d, dest, ropef("$1->data, $1->$2", [rdLoc(a), lenField()])) - of tyArray, tyArrayConstr: - initLocExpr(p, n.sons[0], a) - putIntoDest(p, d, dest, ropef("$1, $2", [rdLoc(a), toRope(lengthOrd(a.t))])) - else: InternalError(n.sons[0].info, "passToOpenArray: " & typeToString(a.t)) - proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) = var a: TLoc initLocExpr(p, n.sons[0], a) @@ -1827,7 +1820,6 @@ proc expr(p: BProc, e: PNode, d: var TLoc) = of nkChckRange: genRangeChck(p, e, d, "chckRange") of nkStringToCString: convStrToCStr(p, e, d) of nkCStringToString: convCStrToStr(p, e, d) - of nkPassAsOpenArray: passToOpenArray(p, e, d) of nkLambda: var sym = e.sons[namePos].sym genProc(p.module, sym) diff --git a/compiler/ecmasgen.nim b/compiler/ecmasgen.nim index 66f315dc3..4347bd283 100755 --- a/compiler/ecmasgen.nim +++ b/compiler/ecmasgen.nim @@ -1390,7 +1390,6 @@ proc gen(p: var TProc, n: PNode, r: var TCompRes) = of nkChckRange: genRangeChck(p, n, r, "chckRange") of nkStringToCString: convStrToCStr(p, n, r) of nkCStringToString: convCStrToStr(p, n, r) - of nkPassAsOpenArray: gen(p, n.sons[0], r) of nkStmtListExpr: genStmtListExpr(p, n, r) of nkEmpty: nil else: InternalError(n.info, "gen: unknown node type: " & $n.kind) diff --git a/compiler/evals.nim b/compiler/evals.nim index 1ccf0d599..83dcf9df7 100755 --- a/compiler/evals.nim +++ b/compiler/evals.nim @@ -1083,7 +1083,6 @@ proc evalAux(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode = of nkChckRangeF, nkChckRange64, nkChckRange: result = evalRangeChck(c, n) of nkStringToCString: result = evalConvStrToCStr(c, n) of nkCStringToString: result = evalConvCStrToStr(c, n) - of nkPassAsOpenArray: result = evalAux(c, n.sons[0], flags) of nkStmtListExpr, nkStmtList, nkModule: for i in countup(0, sonsLen(n) - 1): result = evalAux(c, n.sons[i], flags) diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 3c2e76694..f630655f3 100755 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -355,8 +355,7 @@ proc lsub(n: PNode): int = of nkChckRangeF: result = len("chckRangeF") + 2 + lcomma(n) of nkChckRange64: result = len("chckRange64") + 2 + lcomma(n) of nkChckRange: result = len("chckRange") + 2 + lcomma(n) - of nkObjDownConv, nkObjUpConv, nkStringToCString, nkCStringToString, - nkPassAsOpenArray: + of nkObjDownConv, nkObjUpConv, nkStringToCString, nkCStringToString: result = 2 if sonsLen(n) >= 1: result = result + lsub(n.sons[0]) result = result + lcomma(n, 1) @@ -730,8 +729,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = put(g, tkParLe, "(") gcomma(g, n) put(g, tkParRi, ")") - of nkObjDownConv, nkObjUpConv, nkStringToCString, nkCStringToString, - nkPassAsOpenArray: + of nkObjDownConv, nkObjUpConv, nkStringToCString, nkCStringToString: if sonsLen(n) >= 1: gsub(g, n.sons[0]) put(g, tkParLe, "(") gcomma(g, n, 1) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index aa069c971..d116ede2e 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1224,8 +1224,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = of nkBlockExpr: result = semBlockExpr(c, n) of nkHiddenStdConv, nkHiddenSubConv, nkConv, nkHiddenCallConv: checkSonsLen(n, 2) - of nkStringToCString, nkCStringToString, nkPassAsOpenArray, nkObjDownConv, - nkObjUpConv: + of nkStringToCString, nkCStringToString, nkObjDownConv, nkObjUpConv: checkSonsLen(n, 1) of nkChckRangeF, nkChckRange64, nkChckRange: checkSonsLen(n, 3) diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 028143ae9..61e63a69f 100755 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -375,7 +375,6 @@ proc getConstExpr(m: PSym, n: PNode): PNode = n) of mLengthOpenArray: var a = n.sons[1] - if a.kind == nkPassAsOpenArray: a = a.sons[0] if a.kind == nkBracket: # we can optimize it away! This fixes the bug ``len(134)``. result = newIntNodeT(sonsLen(a), n) diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index e2b2a03d1..295aaac03 100755 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -12,7 +12,7 @@ proc isExpr(n: PNode): bool = case n.kind of nkIdent..nkNilLit: result = true - of nkCall..nkPassAsOpenArray: + of nkCall..pred(nkAsgn): for i in countup(0, sonsLen(n) - 1): if not isExpr(n.sons[i]): return false diff --git a/compiler/semthreads.nim b/compiler/semthreads.nim index 60c54b43e..66760a3c8 100755 --- a/compiler/semthreads.nim +++ b/compiler/semthreads.nim @@ -341,7 +341,7 @@ proc analyse(c: PProcCtx, n: PNode): TThreadOwner = of nkHiddenStdConv, nkHiddenSubConv, nkConv, nkCast: result = analyse(c, n.sons[1]) of nkStringToCString, nkCStringToString, nkChckRangeF, nkChckRange64, - nkChckRange, nkCheckedFieldExpr, nkPassAsOpenArray, nkObjDownConv, + nkChckRange, nkCheckedFieldExpr, nkObjDownConv, nkObjUpConv: result = analyse(c, n.sons[0]) of nkRaiseStmt: diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index ecf6a32c4..9acf83a46 100755 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -499,13 +499,13 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType, result = copyTree(arg) result.typ = getInstantiatedType(c, arg, m, f) # BUG: f may not be the right key! - if (skipTypes(result.typ, abstractVar).kind in {tyTuple, tyOpenArray}): + if (skipTypes(result.typ, abstractVar).kind in {tyTuple}): result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c) # BUGFIX: use ``result.typ`` and not `f` here of isEqual: inc(m.exactMatches) result = copyTree(arg) - if (skipTypes(f, abstractVar).kind in {tyTuple, tyOpenArray}): + if (skipTypes(f, abstractVar).kind in {tyTuple}): result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c) of isNone: result = userConvMatch(c, m, f, a, arg) diff --git a/compiler/transf.nim b/compiler/transf.nim index 395039208..159a3d07c 100755 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -268,10 +268,9 @@ proc transformLoopBody(c: PTransf, n: PNode): PTransNode = proc skipConv(n: PNode): PNode = case n.kind - of nkObjUpConv, nkObjDownConv, nkPassAsOpenArray, nkChckRange, nkChckRangeF, - nkChckRange64: + of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64: result = n.sons[0] - of nkHiddenStdConv, nkHiddenSubConv, nkConv: + of nkHiddenStdConv, nkHiddenSubConv, nkConv: result = n.sons[1] else: result = n @@ -337,11 +336,10 @@ proc addVar(father, v: PNode) = proc transformAddrDeref(c: PTransf, n: PNode, a, b: TNodeKind): PTransNode = case n.sons[0].kind - of nkObjUpConv, nkObjDownConv, nkPassAsOpenArray, nkChckRange, nkChckRangeF, - nkChckRange64: + of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64: var m = n.sons[0].sons[0] if (m.kind == a) or (m.kind == b): - # addr ( nkPassAsOpenArray ( deref ( x ) ) ) --> nkPassAsOpenArray(x) + # addr ( nkConv ( deref ( x ) ) ) --> nkConv(x) var x = copyTree(n) x.sons[0].sons[0] = m.sons[0] result = transform(c, x.sons[0]) @@ -362,7 +360,7 @@ proc transformAddrDeref(c: PTransf, n: PNode, a, b: TNodeKind): PTransNode = result = transform(c, n.sons[0].sons[0]) else: result = transformSons(c, n) - + proc transformConv(c: PTransf, n: PNode): PTransNode = # numeric types need range checks: var dest = skipTypes(n.typ, abstractVarRange) @@ -397,8 +395,7 @@ proc transformConv(c: PTransf, n: PNode): PTransNode = else: result = transformSons(c, n) of tyOpenArray: - result = newTransNode(nkPassAsOpenArray, n, 1) - result[0] = transform(c, n.sons[1]) + result = transform(c, n.sons[1]) of tyCString: if source.kind == tyString: result = newTransNode(nkStringToCString, n, 1) @@ -441,10 +438,6 @@ proc transformConv(c: PTransf, n: PNode): PTransNode = # happens sometimes for generated assignments, etc. else: result = transformSons(c, n) - -proc skipPassAsOpenArray(n: PNode): PNode = - result = n - while result.kind == nkPassAsOpenArray: result = result.sons[0] type TPutArgInto = enum @@ -491,7 +484,7 @@ proc transformFor(c: PTransf, n: PNode): PTransNode = # generate access statements for the parameters (unless they are constant) pushTransCon(c, newC) for i in countup(1, sonsLen(call) - 1): - var arg = skipPassAsOpenArray(transform(c, call.sons[i]).pnode) + var arg = transform(c, call.sons[i]).pnode var formal = skipTypes(newC.owner.typ, abstractInst).n.sons[i].sym case putArgInto(arg, formal.typ) of paDirectMapping: diff --git a/lib/core/macros.nim b/lib/core/macros.nim index e51141025..3b11e774c 100755 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -30,7 +30,7 @@ type nnkHiddenSubConv, nnkHiddenCallConv, nnkConv, nnkCast, nnkAddr, nnkHiddenAddr, nnkHiddenDeref, nnkObjDownConv, nnkObjUpConv, nnkChckRangeF, nnkChckRange64, nnkChckRange, - nnkStringToCString, nnkCStringToString, nnkPassAsOpenArray, nnkAsgn, + nnkStringToCString, nnkCStringToString, nnkAsgn, nnkFastAsgn, nnkGenericParams, nnkFormalParams, nnkOfInherit, nnkModule, nnkProcDef, nnkMethodDef, nnkConverterDef, nnkMacroDef, nnkTemplateDef, nnkIteratorDef, nnkOfBranch, |