diff options
author | Araq <rumpf_a@web.de> | 2012-02-17 02:16:33 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-02-17 02:16:33 +0100 |
commit | 97366d44195a96075960749a0ea84ded582dce87 (patch) | |
tree | 091e6263166b46b344ab50ffee0b1ad20ffc3e07 | |
parent | 88f9eff38fc8b462df474e2e3a9404527d29f30a (diff) | |
download | Nim-97366d44195a96075960749a0ea84ded582dce87.tar.gz |
bugfix: optimization of complex constant string concatenations
-rwxr-xr-x | compiler/msgs.nim | 4 | ||||
-rwxr-xr-x | compiler/transf.nim | 10 | ||||
-rwxr-xr-x | koch.nim | 2 | ||||
-rwxr-xr-x | lib/wrappers/sqlite3.nim | 2 | ||||
-rw-r--r-- | tests/run/tconcat.nim | 11 | ||||
-rwxr-xr-x | tools/cmerge.nim | 27 | ||||
-rwxr-xr-x | web/news.txt | 3 |
7 files changed, 43 insertions, 16 deletions
diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 210886173..7b4d38efa 100755 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -512,6 +512,10 @@ proc toFileLine*(info: TLineInfo): string {.inline.} = proc toFileLineCol*(info: TLineInfo): string {.inline.} = result = info.toFilename & "(" & $info.line & "," & $info.col & ")" +proc `??`* (info: TLineInfo, filename: string): bool = + # only for debugging purposes + result = filename in info.toFilename + var checkPoints: seq[TLineInfo] = @[] proc addCheckpoint*(info: TLineInfo) = diff --git a/compiler/transf.nim b/compiler/transf.nim index 70d0771bd..986d5311d 100755 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -588,13 +588,15 @@ proc transformCall(c: PTransf, n: PNode): PTransNode = add(result, transform(c, n.sons[0])) var j = 1 while j < sonsLen(n): - var a = n.sons[j] + var a = transform(c, n.sons[j]).pnode inc(j) if isConstExpr(a): - while (j < sonsLen(n)) and isConstExpr(n.sons[j]): - a = evalOp(op.magic, n, a, n.sons[j], nil) + while (j < sonsLen(n)): + let b = transform(c, n.sons[j]).pnode + if not isConstExpr(b): break + a = evalOp(op.magic, n, a, b, nil) inc(j) - add(result, transform(c, a)) + add(result, a.ptransnode) if len(result) == 2: result = result[1] elif n.sons[0].kind == nkSym and n.sons[0].sym.kind == skMethod: # use the dispatcher for the call: diff --git a/koch.nim b/koch.nim index b3c219998..d0b9de7a2 100755 --- a/koch.nim +++ b/koch.nim @@ -49,8 +49,6 @@ Boot options: -d:nativeStacktrace use native stack traces (only for Mac OS X or Linux) """ -proc boot(args: string) # Forward declaration - proc exe(f: string): string = return addFileExt(f, ExeExt) proc exec(cmd: string) = diff --git a/lib/wrappers/sqlite3.nim b/lib/wrappers/sqlite3.nim index a5d2189a2..e0e5185a9 100755 --- a/lib/wrappers/sqlite3.nim +++ b/lib/wrappers/sqlite3.nim @@ -16,7 +16,7 @@ elif defined(macosx): Lib = "sqlite-3.6.13.dylib" else: const - Lib = "libsqlite3.so" + Lib = "libsqlite3.so(|.0)" const SQLITE_INTEGER* = 1 diff --git a/tests/run/tconcat.nim b/tests/run/tconcat.nim new file mode 100644 index 000000000..fdce3ea00 --- /dev/null +++ b/tests/run/tconcat.nim @@ -0,0 +1,11 @@ +discard """ + output: "DabcD" +""" + +const + x = "abc" + +var v = "D" & x & "D" + +echo v + diff --git a/tools/cmerge.nim b/tools/cmerge.nim index e461b00b0..ca221014f 100755 --- a/tools/cmerge.nim +++ b/tools/cmerge.nim @@ -1,26 +1,35 @@ # Simple tool to merge C projects into a single C file -import os, strtabs, pegs +import os, sets, pegs -proc process(dir, infile: string, outfile: TFile, processed: PStringTable) = - if processed.hasKey(infile): return - processed[infile] = "True" - echo "adding: ", infile - for line in lines(dir / infile): +type + TProcessResult = enum prSkipIncludeDir, prAddIncludeDir + +proc process(dir, infile: string, outfile: TFile, + processed: var TSet[string]): TProcessResult = + if processed.containsOrIncl(infile): return prSkipIncludeDir + let toProcess = dir / infile + if not existsFile(toProcess): + echo "Warning: could not process: ", toProcess + return prAddIncludeDir + echo "adding: ", toProcess + for line in lines(toProcess): if line =~ peg"""s <- ig '#include' ig '"' {[^"]+} '"' ig comment <- '/*' !'*/'* '*/' / '//' .* ig <- (comment / \s+)* """: # follow the include file: - process(dir, matches[0], outfile, processed) + if process(dir, matches[0], outfile, processed) == prAddIncludeDir: + writeln(outfile, line) else: writeln(outfile, line) proc main(dir, outfile: string) = var o: TFile if open(o, outfile, fmWrite): - var processed = newStringTable([outfile, "True"]) + var processed = initSet[string]() + processed.incl(outfile) for infile in walkfiles(dir / "*.c"): - process(dir, extractFilename(infile), o, processed) + discard process(dir, extractFilename(infile), o, processed) close(o) else: quit("Cannot open for writing: " & outfile) diff --git a/web/news.txt b/web/news.txt index 2e981673b..a171f1068 100755 --- a/web/news.txt +++ b/web/news.txt @@ -10,6 +10,9 @@ Version 0.8.XX has been released! Get it `here <download.html>`_. Bugfixes -------- +- Fixed a bug where the compiler would "optimize away" valid constant parts of + a string concatenation. + Library Additions ----------------- |