diff options
author | Zahary Karadjov <zahary@gmail.comy> | 2011-09-09 04:37:35 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.comy> | 2011-09-20 14:11:06 +0300 |
commit | 0f0dfd63796a0297c9da6fc40ec7947b07449d27 (patch) | |
tree | a4cd050dc8fa5688c1f33f923bbebc6828957228 /compiler | |
parent | daa2c8732d0f4feef20f68e75e9c491e95b95a0d (diff) | |
download | Nim-0f0dfd63796a0297c9da6fc40ec7947b07449d27.tar.gz |
Nimrod can now compile itself with --lineDir enabled
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/ccgexprs.nim | 6 | ||||
-rwxr-xr-x | compiler/ccgstmts.nim | 2 | ||||
-rwxr-xr-x | compiler/ccgutils.nim | 16 | ||||
-rwxr-xr-x | compiler/cgen.nim | 2 | ||||
-rwxr-xr-x | compiler/msgs.nim | 5 | ||||
-rwxr-xr-x | compiler/nimrod.nim | 3 |
6 files changed, 23 insertions, 11 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index fcc11d6e1..743357ba7 100755 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -128,7 +128,7 @@ proc genSetNode(p: BProc, n: PNode): PRope = if id == gid: # not found in cache: inc(gid) - appf(p.module.s[cfsData], "static NIM_CONST $1 $2 = $3;", + appf(p.module.s[cfsData], "static NIM_CONST $1 $2 = $3;$n", [getTypeDesc(p.module, n.typ), result, genRawSetData(cs, size)]) else: result = genRawSetData(cs, size) @@ -371,8 +371,8 @@ proc binaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) = else: storage = getTypeDesc(p.module, t) var tmp = getTempName() - appcg(p, cpsLocals, "$1 $2;", [storage, tmp]) - appcg(p, cpsStmts, "$1 = #$2($3, $4);", [tmp, toRope(prc[m]), + appcg(p, cpsLocals, "$1 $2;$n", [storage, tmp]) + appcg(p, cpsStmts, "$1 = #$2($3, $4);$n", [tmp, toRope(prc[m]), rdLoc(a), rdLoc(b)]) if size < platform.IntSize or t.kind in {tyRange, tyEnum, tySet}: appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n", diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index c12b93b4d..01813d158 100755 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -19,7 +19,7 @@ proc genLineDir(p: BProc, t: PNode) = line = 0 # negative numbers are not allowed in #line if optLineDir in p.Options and line > 0: appff(p.s[cpsStmts], "#line $2 $1$n", "; line $2 \"$1\"$n", - [makeCString(toFilename(t.info)), toRope(line)]) + [toRope(makeSingleLineCString(toFullPath(t.info))), toRope(line)]) if ({optStackTrace, optEndb} * p.Options == {optStackTrace, optEndb}) and (p.prc == nil or sfPure notin p.prc.flags): appcg(p, cpsStmts, "#endb($1);$n", [toRope(line)]) diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index 294c1057c..15b48fcb0 100755 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -103,6 +103,12 @@ proc toCChar*(c: Char): string = of '\0'..'\x1F', '\x80'..'\xFF': result = '\\' & toOctal(c) of '\'', '\"', '\\': result = '\\' & c else: result = $(c) + +proc makeSingleLineCString*(s: string): string = + result = "\"" + for c in items(s): + result.add(c.toCChar) + result.add('\"') proc makeCString*(s: string): PRope = # BUGFIX: We have to split long strings into many ropes. Otherwise @@ -113,10 +119,10 @@ proc makeCString*(s: string): PRope = var res: string result = nil res = "\"" - for i in countup(0, len(s) + 0 - 1): - if (i - 0 + 1) mod MaxLineLength == 0: + for i in countup(0, len(s) - 1): + if (i + 1) mod MaxLineLength == 0: add(res, '\"') - add(res, "\n") + add(res, tnl) app(result, toRope(res)) # reset: setlen(res, 1) res[0] = '\"' @@ -129,8 +135,8 @@ proc makeLLVMString*(s: string): PRope = var res: string result = nil res = "c\"" - for i in countup(0, len(s) + 0 - 1): - if (i - 0 + 1) mod MaxLineLength == 0: + for i in countup(0, len(s) - 1): + if (i + 1) mod MaxLineLength == 0: app(result, toRope(res)) setlen(res, 0) case s[i] diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 7b17e9958..2a29381b6 100755 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -13,7 +13,7 @@ import ast, astalgo, strutils, hashes, trees, platform, magicsys, extccomp, options, intsets, - nversion, nimsets, msgs, crc, bitsets, idents, lists, types, ccgutils, os, + nversion, nimsets, msgs, crc, bitsets, idents, lists, types, ccgutils, os, times, ropes, math, passes, rodread, wordrecg, treetab, cgmeth, rodutils, renderer diff --git a/compiler/msgs.nim b/compiler/msgs.nim index c3aa30891..5d0bde12e 100755 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -438,6 +438,11 @@ proc newLineInfo*(filename: string, line, col: int): TLineInfo = proc ToFilename*(info: TLineInfo): string = if info.fileIndex < 0: result = "???" else: result = filenames[info.fileIndex] + +proc toFullPath*(info: TLineInfo): string = + result = info.toFilename + if not isAbsolute(result): + result = JoinPath(options.projectPath, result) proc ToLinenumber*(info: TLineInfo): int {.inline.} = result = info.line diff --git a/compiler/nimrod.nim b/compiler/nimrod.nim index 3a910cfad..a28f8a965 100755 --- a/compiler/nimrod.nim +++ b/compiler/nimrod.nim @@ -66,7 +66,8 @@ proc HandleCmdLine() = var filename = "" ProcessCmdLine(passCmd1, command, filename) if filename != "": - var p = splitFile(filename) + var fullPath = expandFilename(filename) + var p = splitFile(fullPath) options.projectPath = p.dir options.projectName = p.name nimconf.LoadConfig(filename) # load the right config file |