diff --git a/data/keywords.txt b/data/keywords.txt index 0ea2e16638..3cf9790efd 100755 --- a/data/keywords.txt +++ b/data/keywords.txt @@ -1,4 +1,4 @@ -addr and as asm +addr and as asm atomic bind block break case cast const continue converter discard distinct div diff --git a/lib/pure/math.nim b/lib/pure/math.nim index 50226f0f4a..cf4b6d95c0 100755 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -1,12 +1,14 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2009 Andreas Rumpf +# (c) Copyright 2010 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # +## Constructive mathematics is naturally typed. -- Simon Thompson +## ## Basic math routines for Nimrod. ## This module is available for the ECMAScript target. diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 5cf1cf6a34..292810538e 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -328,7 +328,9 @@ proc ParseFloat*(s: string): float {.noSideEffect, procvar.} proc ParseHexInt*(s: string): int {.noSideEffect, procvar.} ## Parses a hexadecimal integer value contained in `s`. If `s` is not - ## a valid integer, `EInvalidValue` is raised. + ## a valid integer, `EInvalidValue` is raised. `s` can have one of the + ## following optional prefixes: ``0x``, ``0X``, ``#``. + ## Underscores within `s` are ignored. # the stringify and format operators: proc toString*[Ty](x: Ty): string {.deprecated.} @@ -735,10 +737,22 @@ proc ParseBiggestInt(s: string): biggestInt = if index == -1: raise newException(EInvalidValue, "invalid integer: " & s) +proc ParseOctInt*(s: string): int = + var i = 0 + if s[i] == '0' and (s[i+1] == 'o' or s[i+1] == 'O'): inc(i, 2) + while true: + case s[i] + of '_': inc(i) + of '0'..'7': + result = result shl 3 or (ord(s[i]) - ord('0')) + inc(i) + of '\0': break + else: raise newException(EInvalidValue, "invalid integer: " & s) proc ParseHexInt(s: string): int = var i = 0 if s[i] == '0' and (s[i+1] == 'x' or s[i+1] == 'X'): inc(i, 2) + elif s[i] == '#': inc(i) while true: case s[i] of '_': inc(i) diff --git a/rod/docgen.nim b/rod/docgen.nim index 711848e5f1..3a7ef14d80 100755 --- a/rod/docgen.nim +++ b/rod/docgen.nim @@ -91,20 +91,19 @@ proc initIndexFile(d: PDoc) = addSon(d.indexFile, h) proc newDocumentor(filename: string): PDoc = - var s: string new(result) result.tocPart = @ [] result.filename = filename result.id = 100 result.splitAfter = 20 - s = getConfigVar("split.item.toc") + var s = getConfigVar("split.item.toc") if s != "": result.splitAfter = parseInt(s) proc getVarIdx(varnames: openarray[string], id: string): int = for i in countup(0, high(varnames)): if cmpIgnoreStyle(varnames[i], id) == 0: return i - result = - 1 + result = -1 proc ropeFormatNamedVars(frmt: TFormatStr, varnames: openarray[string], varvalues: openarray[PRope]): PRope = @@ -277,12 +276,9 @@ proc genComment(d: PDoc, n: PNode): PRope = result = renderRstToOut(d, rstParse(n.comment, true, toFilename(n.info), toLineNumber(n.info), toColumn(n.info), dummyHasToc)) - else: - result = nil proc genRecComment(d: PDoc, n: PNode): PRope = - if n == nil: - return nil + if n == nil: return nil result = genComment(d, n) if result == nil: if not (n.kind in {nkEmpty..nkNilLit}): @@ -293,11 +289,10 @@ proc genRecComment(d: PDoc, n: PNode): PRope = n.comment = nil proc isVisible(n: PNode): bool = - var v: PIdent result = false if n.kind == nkPostfix: if (sonsLen(n) == 2) and (n.sons[0].kind == nkIdent): - v = n.sons[0].ident + var v = n.sons[0].ident result = (v.id == ord(wStar)) or (v.id == ord(wMinus)) elif n.kind == nkSym: result = sfInInterface in n.sym.flags @@ -388,14 +383,11 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) = setIndexForSourceTerm(d, getRstName(nameNode), d.id) proc renderHeadline(d: PDoc, n: PRstNode): PRope = - var - length: int - refname: PRope result = nil for i in countup(0, rsonsLen(n) - 1): app(result, renderRstToOut(d, n.sons[i])) - refname = toRope(rstnodeToRefname(n)) + var refname = toRope(rstnodeToRefname(n)) if d.hasToc: - length = len(d.tocPart) + var length = len(d.tocPart) setlen(d.tocPart, length + 1) d.tocPart[length].refname = refname d.tocPart[length].n = n @@ -424,8 +416,8 @@ proc renderOverline(d: PDoc, n: PRstNode): PRope = proc renderRstToRst(d: PDoc, n: PRstNode): PRope proc renderRstSons(d: PDoc, n: PRstNode): PRope = - result = nil - for i in countup(0, rsonsLen(n) - 1): app(result, renderRstToRst(d, n.sons[i])) + for i in countup(0, rsonsLen(n) - 1): + app(result, renderRstToRst(d, n.sons[i])) proc renderRstToRst(d: PDoc, n: PRstNode): PRope = # this is needed for the index generation; it may also be useful for @@ -612,9 +604,8 @@ proc renderCodeBlock(d: PDoc, n: PRstNode): PRope = [result]) proc renderContainer(d: PDoc, n: PRstNode): PRope = - var arg: PRope result = renderRstToOut(d, n.sons[2]) - arg = toRope(strip(getArgument(n))) + var arg = toRope(strip(getArgument(n))) if arg == nil: result = dispF("
$1
", "$1", [result]) else: result = dispF("
$2
", "$2", [arg, result]) @@ -874,12 +865,9 @@ proc generateIndex(d: PDoc) = writeRope(renderRstToRst(d, d.indexFile), gIndexFile) proc CommandDoc(filename: string) = - var - ast: PNode - d: PDoc - ast = parseFile(addFileExt(filename, nimExt)) + var ast = parseFile(addFileExt(filename, nimExt)) if ast == nil: return - d = newDocumentor(filename) + var d = newDocumentor(filename) initIndexFile(d) d.hasToc = true generateDoc(d, ast) @@ -887,17 +875,12 @@ proc CommandDoc(filename: string) = generateIndex(d) proc CommandRstAux(filename, outExt: string) = - var - filen: string - d: PDoc - rst: PRstNode - code: PRope - filen = addFileExt(filename, "txt") - d = newDocumentor(filen) + var filen = addFileExt(filename, "txt") + var d = newDocumentor(filen) initIndexFile(d) - rst = rstParse(readFile(filen), false, filen, 0, 1, d.hasToc) + var rst = rstParse(readFile(filen), false, filen, 0, 1, d.hasToc) d.modDesc = renderRstToOut(d, rst) - code = genOutFile(d) + var code = genOutFile(d) writeRope(code, getOutFile(filename, outExt)) generateIndex(d) diff --git a/rod/pas2nim/pas2nim.cfg b/rod/pas2nim/pas2nim.cfg new file mode 100755 index 0000000000..789e6ec7f0 --- /dev/null +++ b/rod/pas2nim/pas2nim.cfg @@ -0,0 +1,4 @@ +# Use the modules of the compiler + +path: "$nimrod/rod" + diff --git a/rod/scanner.nim b/rod/scanner.nim index dd6bedac45..9367208da6 100755 --- a/rod/scanner.nim +++ b/rod/scanner.nim @@ -46,7 +46,8 @@ type # i = i + 1 #cog.out(idents) #]]] - tkAddr, tkAnd, tkAs, tkAsm, tkBind, tkBlock, tkBreak, tkCase, tkCast, + tkAddr, tkAnd, tkAs, tkAsm, tkAtomic, + tkBind, tkBlock, tkBreak, tkCase, tkCast, tkConst, tkContinue, tkConverter, tkDiscard, tkDistinct, tkDiv, tkElif, tkElse, tkEnd, tkEnum, tkExcept, tkFinally, tkFor, tkFrom, tkGeneric, tkIf, tkImplies, tkImport, tkIn, tkInclude, tkIs, tkIsnot, tkIterator, tkLambda, @@ -77,7 +78,8 @@ const "tkSymbol", #[[[cog #cog.out(strings) #]]] - "addr", "and", "as", "asm", "bind", "block", "break", "case", "cast", + "addr", "and", "as", "asm", "atomic", + "bind", "block", "break", "case", "cast", "const", "continue", "converter", "discard", "distinct", "div", "elif", "else", "end", "enum", "except", "finally", "for", "from", "generic", "if", "implies", "import", "in", "include", "is", "isnot", "iterator", "lambda", diff --git a/rod/wordrecg.nim b/rod/wordrecg.nim index b090d5a358..1d078dfccf 100755 --- a/rod/wordrecg.nim +++ b/rod/wordrecg.nim @@ -22,7 +22,8 @@ type TSpecialWord* = enum wInvalid, - wAddr, wAnd, wAs, wAsm, wBind, wBlock, wBreak, wCase, wCast, wConst, + wAddr, wAnd, wAs, wAsm, wAtomic, + wBind, wBlock, wBreak, wCase, wCast, wConst, wContinue, wConverter, wDiscard, wDistinct, wDiv, wElif, wElse, wEnd, wEnum, wExcept, wFinally, wFor, wFrom, wGeneric, wIf, wImplies, wImport, wIn, wInclude, wIs, wIsnot, wIterator, wLambda, wMacro, wMethod, wMod, wNil, @@ -62,7 +63,8 @@ const oprHigh* = ord(wHat) specialWords*: array[low(TSpecialWord)..high(TSpecialWord), string] = ["", - "addr", "and", "as", "asm", "bind", "block", "break", "case", "cast", + "addr", "and", "as", "asm", "atomic", + "bind", "block", "break", "case", "cast", "const", "continue", "converter", "discard", "distinct", "div", "elif", "else", "end", "enum", "except", "finally", "for", "from", "generic", "if", "implies", "import", "in", "include", "is", "isnot", "iterator", "lambda", diff --git a/tools/cmerge.nim b/tools/cmerge.nim new file mode 100755 index 0000000000..729a8f2187 --- /dev/null +++ b/tools/cmerge.nim @@ -0,0 +1,31 @@ +# Simple tool to merge C projects into a single C file + +import os, strtabs, 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): + if line =~ peg"""s <- ig '#include' ig '"' {[^"]+} '"' ig + comment <- '/*' !'*/'* '*/' / '//' .* + ig <- (comment / \s+)* """: + # follow the include file: + process(dir, matches[0], outfile, processed) + else: + writeln(outfile, line) + +proc main(dir, outfile: string) = + var o: TFile + if open(o, outfile, fmWrite): + var processed = newStringTable([outfile, "True"]) + for infile in walkfiles(dir / "*.c"): + process(dir, extractFilename(infile), o, processed) + close(o) + else: + quit("Cannot open for writing: " & outfile) + +if ParamCount() != 2: + echo "Usage: cmerge directory outfile" +else: + main(ParamStr(1), addFileExt(ParamStr(2), "c"))