openarray/varargs split; breaks bootstrapping

This commit is contained in:
Araq 2012-08-16 08:34:33 +02:00
commit 0171566c98
29 changed files with 228 additions and 175 deletions

View file

@ -161,17 +161,6 @@ proc assign*(dest: var TIntSet, src: TIntSet) =
it = it.next
template dollarImpl(): stmt =
result = "{"
for key in items(s):
if result.len > 1: result.add(", ")
result.add($key)
result.add("}")
proc `$`*(s: TIntSet): string =
## The `$` operator for int sets.
dollarImpl()
iterator items*(s: TIntSet): int {.inline.} =
## iterates over any included element of `s`.
var r = s.head
@ -190,6 +179,17 @@ iterator items*(s: TIntSet): int {.inline.} =
inc(i)
r = r.next
template dollarImpl(): stmt =
result = "{"
for key in items(s):
if result.len > 1: result.add(", ")
result.add($key)
result.add("}")
proc `$`*(s: TIntSet): string =
## The `$` operator for int sets.
dollarImpl()
when isMainModule:
var x = initIntSet()
x.incl(1)

View file

@ -108,7 +108,7 @@ proc assertReply(received: TaintedString, expected: string) =
"Expected reply '$1' got: $2" % [
expected, received.string])
proc assertReply(received: TaintedString, expected: openarray[string]) =
proc assertReply(received: TaintedString, expected: varargs[string]) =
for i in items(expected):
if received.string.startsWith(i): return
raise newException(EInvalidReply,

View file

@ -149,7 +149,7 @@ template multipleOp(k: TPegKind, localOpt: expr) =
if result.len == 1:
result = result.sons[0]
proc `/`*(a: openArray[TPeg]): TPeg {.
proc `/`*(a: varargs[TPeg]): TPeg {.
nosideEffect, rtl, extern: "npegsOrderedChoice".} =
## constructs an ordered choice with the PEGs in `a`
multipleOp(pkOrderedChoice, addChoice)
@ -166,7 +166,7 @@ proc addSequence(dest: var TPeg, elem: TPeg) =
else: add(dest, elem)
else: add(dest, elem)
proc sequence*(a: openArray[TPeg]): TPeg {.
proc sequence*(a: varargs[TPeg]): TPeg {.
nosideEffect, rtl, extern: "npegs$1".} =
## constructs a sequence with all the PEGs from `a`
multipleOp(pkSequence, addSequence)
@ -939,7 +939,7 @@ proc replace*(s: string, sub: TPeg, by = ""): string {.
inc(i, x)
add(result, substr(s, i))
proc parallelReplace*(s: string, subs: openArray[
proc parallelReplace*(s: string, subs: varargs[
tuple[pattern: TPeg, repl: string]]): string {.
nosideEffect, rtl, extern: "npegs$1".} =
## Returns a modified copy of `s` with the substitutions in `subs`
@ -964,7 +964,7 @@ proc parallelReplace*(s: string, subs: openArray[
add(result, substr(s, i))
proc transformFile*(infile, outfile: string,
subs: openArray[tuple[pattern: TPeg, repl: string]]) {.
subs: varargs[tuple[pattern: TPeg, repl: string]]) {.
rtl, extern: "npegs$1".} =
## reads in the file `infile`, performs a parallel replacement (calls
## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an

View file

@ -151,7 +151,7 @@ proc newStringTable*(mode: TStringTableMode): PStringTable {.
result.counter = 0
newSeq(result.data, startSize)
proc newStringTable*(keyValuePairs: openarray[string],
proc newStringTable*(keyValuePairs: varargs[string],
mode: TStringTableMode): PStringTable {.
rtl, extern: "nst$1WithPairs".} =
## creates a new string table with given key value pairs.
@ -164,7 +164,7 @@ proc newStringTable*(keyValuePairs: openarray[string],
result[keyValuePairs[i]] = keyValuePairs[i + 1]
inc(i, 2)
proc newStringTable*(keyValuePairs: openarray[tuple[key, val: string]],
proc newStringTable*(keyValuePairs: varargs[tuple[key, val: string]],
mode: TStringTableMode = modeCaseSensitive): PStringTable {.
rtl, extern: "nst$1WithTableConstr".} =
## creates a new string table with given key value pairs.

View file

@ -1112,6 +1112,13 @@ proc `%` *(formatstr, a: string): string {.noSideEffect,
## This is the same as ``formatstr % [a]``.
result = newStringOfCap(formatstr.len + a.len)
addf(result, formatstr, [a])
proc format*(formatstr: string, a: varargs[string, `$`]): string {.noSideEffect,
rtl, extern: "nsuFormatVarargs".} =
## This is the same as ``formatstr % a`` except that it supports
## auto stringification.
result = newStringOfCap(formatstr.len + a.len)
addf(result, formatstr, a)
{.pop.}