openarray/varargs split; breaks bootstrapping
This commit is contained in:
parent
1215193010
commit
0171566c98
29 changed files with 228 additions and 175 deletions
|
|
@ -48,7 +48,7 @@ proc loadInto(p: BProc, le, ri: PNode, a: var TLoc) {.inline.} =
|
|||
expr(p, ri, a)
|
||||
|
||||
proc startBlock(p: BProc, start: TFormatStr = "{$n",
|
||||
args: openarray[PRope]): int {.discardable.} =
|
||||
args: varargs[PRope]): int {.discardable.} =
|
||||
lineCg(p, cpsStmts, start, args)
|
||||
inc(p.labels)
|
||||
result = len(p.blocks)
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ proc getTypeName(typ: PType): PRope =
|
|||
else:
|
||||
if typ.loc.r == nil:
|
||||
typ.loc.r = if gCmd != cmdCompileToLLVM: con(typ.typeName, typ.id.toRope)
|
||||
else: con("%".toRope, typ.typeName, typ.id.toRope)
|
||||
else: con(["%".toRope, typ.typeName, typ.id.toRope])
|
||||
result = typ.loc.r
|
||||
if result == nil: InternalError("getTypeName: " & $typ.kind)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@ proc cgenPass*(): TPass
|
|||
var
|
||||
generatedHeader: BModule
|
||||
|
||||
proc ropeff(cformat, llvmformat: string, args: openarray[PRope]): PRope =
|
||||
proc ropeff(cformat, llvmformat: string, args: varargs[PRope]): PRope =
|
||||
if gCmd == cmdCompileToLLVM: result = ropef(llvmformat, args)
|
||||
else: result = ropef(cformat, args)
|
||||
|
||||
proc appff(dest: var PRope, cformat, llvmformat: string,
|
||||
args: openarray[PRope]) =
|
||||
args: varargs[PRope]) =
|
||||
if gCmd == cmdCompileToLLVM: appf(dest, llvmformat, args)
|
||||
else: appf(dest, cformat, args)
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ proc useHeader(m: BModule, sym: PSym) =
|
|||
|
||||
proc cgsym(m: BModule, name: string): PRope
|
||||
|
||||
proc ropecg(m: BModule, frmt: TFormatStr, args: openarray[PRope]): PRope =
|
||||
proc ropecg(m: BModule, frmt: TFormatStr, args: varargs[PRope]): PRope =
|
||||
var i = 0
|
||||
var length = len(frmt)
|
||||
result = nil
|
||||
|
|
@ -145,15 +145,15 @@ proc ropecg(m: BModule, frmt: TFormatStr, args: openarray[PRope]): PRope =
|
|||
app(result, substr(frmt, start, i - 1))
|
||||
|
||||
proc appcg(m: BModule, c: var PRope, frmt: TFormatStr,
|
||||
args: openarray[PRope]) =
|
||||
args: varargs[PRope]) =
|
||||
app(c, ropecg(m, frmt, args))
|
||||
|
||||
proc appcg(m: BModule, s: TCFileSection, frmt: TFormatStr,
|
||||
args: openarray[PRope]) =
|
||||
args: varargs[PRope]) =
|
||||
app(m.s[s], ropecg(m, frmt, args))
|
||||
|
||||
proc appcg(p: BProc, s: TCProcSection, frmt: TFormatStr,
|
||||
args: openarray[PRope]) =
|
||||
args: varargs[PRope]) =
|
||||
app(p.s(s), ropecg(p.module, frmt, args))
|
||||
|
||||
var indent = "\t".toRope
|
||||
|
|
@ -168,19 +168,19 @@ proc line(p: BProc, s: TCProcSection, r: string) =
|
|||
app(p.s(s), indentLine(p, r.toRope))
|
||||
|
||||
proc lineF(p: BProc, s: TCProcSection, frmt: TFormatStr,
|
||||
args: openarray[PRope]) =
|
||||
args: varargs[PRope]) =
|
||||
app(p.s(s), indentLine(p, ropef(frmt, args)))
|
||||
|
||||
proc lineCg(p: BProc, s: TCProcSection, frmt: TFormatStr,
|
||||
args: openarray[PRope]) =
|
||||
args: varargs[PRope]) =
|
||||
app(p.s(s), indentLine(p, ropecg(p.module, frmt, args)))
|
||||
|
||||
proc appLineCg(p: BProc, r: var PRope, frmt: TFormatStr,
|
||||
args: openarray[PRope]) =
|
||||
args: varargs[PRope]) =
|
||||
app(r, indentLine(p, ropecg(p.module, frmt, args)))
|
||||
|
||||
proc lineFF(p: BProc, s: TCProcSection, cformat, llvmformat: string,
|
||||
args: openarray[PRope]) =
|
||||
args: varargs[PRope]) =
|
||||
if gCmd == cmdCompileToLLVM: lineF(p, s, llvmformat, args)
|
||||
else: lineF(p, s, cformat, args)
|
||||
|
||||
|
|
|
|||
|
|
@ -479,7 +479,7 @@ proc getLinkOptions: string =
|
|||
for linkedLib in items(cLinkedLibs):
|
||||
result.add(cc[ccompiler].linkLibCmd % linkedLib.quoteIfContainsWhite)
|
||||
for libDir in items(cLibs):
|
||||
result.add cc[ccompiler].linkDirCmd, libDir.quoteIfContainsWhite
|
||||
result.add([cc[ccompiler].linkDirCmd, libDir.quoteIfContainsWhite])
|
||||
|
||||
proc needsExeExt(): bool {.inline.} =
|
||||
result = (optGenScript in gGlobalOptions and targetOS == osWindows) or
|
||||
|
|
@ -502,7 +502,7 @@ proc getCompileCFileCmd*(cfilename: string, isExternal = false): string =
|
|||
includeCmd = cc[c].includeCmd & quoteIfContainsWhite(libpath)
|
||||
|
||||
for includeDir in items(cIncludes):
|
||||
includeCmd.add cc[c].includeCmd, includeDir.quoteIfContainsWhite
|
||||
includeCmd.add([cc[c].includeCmd, includeDir.quoteIfContainsWhite])
|
||||
|
||||
compilePattern = JoinPath(ccompilerpath, exe)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ type
|
|||
proc con*(a, b: PRope): PRope
|
||||
proc con*(a: PRope, b: string): PRope
|
||||
proc con*(a: string, b: PRope): PRope
|
||||
proc con*(a: openarray[PRope]): PRope
|
||||
proc con*(a: varargs[PRope]): PRope
|
||||
proc app*(a: var PRope, b: PRope)
|
||||
proc app*(a: var PRope, b: string)
|
||||
proc prepend*(a: var PRope, b: PRope)
|
||||
|
|
@ -84,8 +84,8 @@ proc toRope*(i: BiggestInt): PRope
|
|||
proc ropeLen*(a: PRope): int
|
||||
proc writeRopeIfNotEqual*(r: PRope, filename: string): bool
|
||||
proc ropeToStr*(p: PRope): string
|
||||
proc ropef*(frmt: TFormatStr, args: openarray[PRope]): PRope
|
||||
proc appf*(c: var PRope, frmt: TFormatStr, args: openarray[PRope])
|
||||
proc ropef*(frmt: TFormatStr, args: varargs[PRope]): PRope
|
||||
proc appf*(c: var PRope, frmt: TFormatStr, args: varargs[PRope])
|
||||
proc RopeEqualsFile*(r: PRope, f: string): bool
|
||||
# returns true if the rope r is the same as the contents of file f
|
||||
proc RopeInvariant*(r: PRope): bool
|
||||
|
|
@ -183,7 +183,7 @@ proc con(a, b: PRope): PRope =
|
|||
proc con(a: PRope, b: string): PRope = result = con(a, toRope(b))
|
||||
proc con(a: string, b: PRope): PRope = result = con(toRope(a), b)
|
||||
|
||||
proc con(a: openarray[PRope]): PRope =
|
||||
proc con(a: varargs[PRope]): PRope =
|
||||
for i in countup(0, high(a)): result = con(result, a[i])
|
||||
|
||||
proc toRope(i: BiggestInt): PRope = result = toRope($i)
|
||||
|
|
@ -212,7 +212,7 @@ proc WriteRope*(head: PRope, filename: string, useWarning = false) =
|
|||
rawMessage(if useWarning: warnCannotOpenFile else: errCannotOpenFile,
|
||||
filename)
|
||||
|
||||
proc ropef(frmt: TFormatStr, args: openarray[PRope]): PRope =
|
||||
proc ropef(frmt: TFormatStr, args: varargs[PRope]): PRope =
|
||||
var i = 0
|
||||
var length = len(frmt)
|
||||
result = nil
|
||||
|
|
@ -254,7 +254,7 @@ proc ropef(frmt: TFormatStr, args: openarray[PRope]): PRope =
|
|||
app(result, substr(frmt, start, i - 1))
|
||||
assert(RopeInvariant(result))
|
||||
|
||||
proc appf(c: var PRope, frmt: TFormatStr, args: openarray[PRope]) =
|
||||
proc appf(c: var PRope, frmt: TFormatStr, args: varargs[PRope]) =
|
||||
app(c, ropef(frmt, args))
|
||||
|
||||
const
|
||||
|
|
|
|||
|
|
@ -388,9 +388,9 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
|||
elif f.sons[0].kind in GenericTypes:
|
||||
result = minRel(result, typeRel(c, f.sons[0], a.sons[0]))
|
||||
else: nil
|
||||
of tyOpenArray:
|
||||
of tyOpenArray, tyVarargs:
|
||||
case a.Kind
|
||||
of tyOpenArray:
|
||||
of tyOpenArray, tyVarargs:
|
||||
result = typeRel(c, base(f), base(a))
|
||||
if result < isGeneric: result = isNone
|
||||
of tyArrayConstr:
|
||||
|
|
@ -409,10 +409,6 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
|||
elif typeRel(c, base(f), a.sons[0]) >= isGeneric:
|
||||
result = isConvertible
|
||||
else: nil
|
||||
of tyVarargs:
|
||||
if a.Kind == tyVarargs:
|
||||
result = typeRel(c, base(f), base(a))
|
||||
if result < isGeneric: result = isNone
|
||||
of tySequence:
|
||||
case a.Kind
|
||||
of tyNil:
|
||||
|
|
@ -611,10 +607,13 @@ proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType,
|
|||
result = c.semOverloadedCall(c, call, call, RoutineKinds)
|
||||
if result != nil:
|
||||
# resulting type must be consistent with the other arguments:
|
||||
var r = typeRel(m, f, result.typ)
|
||||
var r = typeRel(m, f.sons[0], result.typ)
|
||||
if r < isGeneric: return nil
|
||||
if result.kind == nkCall: result.kind = nkHiddenCallConv
|
||||
inc(m.convMatches)
|
||||
if r == isGeneric:
|
||||
result.typ = getInstantiatedType(c, arg, m, base(f))
|
||||
m.baseTypeMatch = true
|
||||
|
||||
proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
|
||||
arg, argOrig: PNode): PNode =
|
||||
|
|
@ -686,17 +685,21 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
|
|||
m.proxyMatch = true
|
||||
return copyTree(arg)
|
||||
result = userConvMatch(c, m, f, a, arg)
|
||||
# check for a base type match, which supports openarray[T] without []
|
||||
# check for a base type match, which supports varargs[T] without []
|
||||
# constructor in a call:
|
||||
if result == nil and f.kind == tyOpenArray:
|
||||
r = typeRel(m, base(f), a)
|
||||
if r >= isGeneric:
|
||||
inc(m.convMatches)
|
||||
result = copyTree(arg)
|
||||
if r == isGeneric: result.typ = getInstantiatedType(c, arg, m, base(f))
|
||||
m.baseTypeMatch = true
|
||||
if result == nil and f.kind == tyVarargs:
|
||||
if f.n != nil:
|
||||
result = localConvMatch(c, m, f, a, arg)
|
||||
else:
|
||||
result = userConvMatch(c, m, base(f), a, arg)
|
||||
r = typeRel(m, base(f), a)
|
||||
if r >= isGeneric:
|
||||
inc(m.convMatches)
|
||||
result = copyTree(arg)
|
||||
if r == isGeneric:
|
||||
result.typ = getInstantiatedType(c, arg, m, base(f))
|
||||
m.baseTypeMatch = true
|
||||
else:
|
||||
result = userConvMatch(c, m, base(f), a, arg)
|
||||
|
||||
proc ParamTypesMatch(c: PContext, m: var TCandidate, f, a: PType,
|
||||
arg, argOrig: PNode): PNode =
|
||||
|
|
@ -777,7 +780,7 @@ proc matchesAux*(c: PContext, n, nOrig: PNode,
|
|||
var container: PNode = nil # constructed container
|
||||
var formal: PSym = nil
|
||||
while a < n.len:
|
||||
if n.sons[a].kind == nkExprEqExpr:
|
||||
if n.sons[a].kind == nkExprEqExpr:
|
||||
# named param
|
||||
# check if m.callee has such a param:
|
||||
if n.sons[a].sons[0].kind != nkIdent:
|
||||
|
|
@ -870,19 +873,19 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
|||
if m.state == csNoMatch: return
|
||||
# check that every formal parameter got a value:
|
||||
var f = 1
|
||||
while f < sonsLen(m.callee.n):
|
||||
while f < sonsLen(m.callee.n):
|
||||
var formal = m.callee.n.sons[f].sym
|
||||
if not ContainsOrIncl(marker, formal.position):
|
||||
if formal.ast == nil:
|
||||
if formal.typ.kind == tyOpenArray:
|
||||
if formal.ast == nil:
|
||||
if formal.typ.kind == tyVarargs:
|
||||
var container = newNodeI(nkBracket, n.info)
|
||||
addSon(m.call, implicitConv(nkHiddenStdConv, formal.typ,
|
||||
addSon(m.call, implicitConv(nkHiddenStdConv, formal.typ,
|
||||
container, m, c))
|
||||
else:
|
||||
# no default value
|
||||
m.state = csNoMatch
|
||||
break
|
||||
else:
|
||||
else:
|
||||
# use default value:
|
||||
setSon(m.call, formal.position + 1, copyTree(formal.ast))
|
||||
inc(f)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue