atomic is now a keyword
This commit is contained in:
parent
b50133b50f
commit
0ea4b71eec
8 changed files with 77 additions and 39 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
addr and as asm
|
addr and as asm atomic
|
||||||
bind block break
|
bind block break
|
||||||
case cast const continue converter
|
case cast const continue converter
|
||||||
discard distinct div
|
discard distinct div
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Nimrod's Runtime Library
|
# Nimrod's Runtime Library
|
||||||
# (c) Copyright 2009 Andreas Rumpf
|
# (c) Copyright 2010 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
## Constructive mathematics is naturally typed. -- Simon Thompson
|
||||||
|
##
|
||||||
## Basic math routines for Nimrod.
|
## Basic math routines for Nimrod.
|
||||||
## This module is available for the ECMAScript target.
|
## This module is available for the ECMAScript target.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -328,7 +328,9 @@ proc ParseFloat*(s: string): float {.noSideEffect, procvar.}
|
||||||
|
|
||||||
proc ParseHexInt*(s: string): int {.noSideEffect, procvar.}
|
proc ParseHexInt*(s: string): int {.noSideEffect, procvar.}
|
||||||
## Parses a hexadecimal integer value contained in `s`. If `s` is not
|
## 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:
|
# the stringify and format operators:
|
||||||
proc toString*[Ty](x: Ty): string {.deprecated.}
|
proc toString*[Ty](x: Ty): string {.deprecated.}
|
||||||
|
|
@ -735,10 +737,22 @@ proc ParseBiggestInt(s: string): biggestInt =
|
||||||
if index == -1:
|
if index == -1:
|
||||||
raise newException(EInvalidValue, "invalid integer: " & s)
|
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 =
|
proc ParseHexInt(s: string): int =
|
||||||
var i = 0
|
var i = 0
|
||||||
if s[i] == '0' and (s[i+1] == 'x' or s[i+1] == 'X'): inc(i, 2)
|
if s[i] == '0' and (s[i+1] == 'x' or s[i+1] == 'X'): inc(i, 2)
|
||||||
|
elif s[i] == '#': inc(i)
|
||||||
while true:
|
while true:
|
||||||
case s[i]
|
case s[i]
|
||||||
of '_': inc(i)
|
of '_': inc(i)
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,12 @@ proc initIndexFile(d: PDoc) =
|
||||||
addSon(d.indexFile, h)
|
addSon(d.indexFile, h)
|
||||||
|
|
||||||
proc newDocumentor(filename: string): PDoc =
|
proc newDocumentor(filename: string): PDoc =
|
||||||
var s: string
|
|
||||||
new(result)
|
new(result)
|
||||||
result.tocPart = @ []
|
result.tocPart = @ []
|
||||||
result.filename = filename
|
result.filename = filename
|
||||||
result.id = 100
|
result.id = 100
|
||||||
result.splitAfter = 20
|
result.splitAfter = 20
|
||||||
s = getConfigVar("split.item.toc")
|
var s = getConfigVar("split.item.toc")
|
||||||
if s != "": result.splitAfter = parseInt(s)
|
if s != "": result.splitAfter = parseInt(s)
|
||||||
|
|
||||||
proc getVarIdx(varnames: openarray[string], id: string): int =
|
proc getVarIdx(varnames: openarray[string], id: string): int =
|
||||||
|
|
@ -277,12 +276,9 @@ proc genComment(d: PDoc, n: PNode): PRope =
|
||||||
result = renderRstToOut(d, rstParse(n.comment, true, toFilename(n.info),
|
result = renderRstToOut(d, rstParse(n.comment, true, toFilename(n.info),
|
||||||
toLineNumber(n.info), toColumn(n.info),
|
toLineNumber(n.info), toColumn(n.info),
|
||||||
dummyHasToc))
|
dummyHasToc))
|
||||||
else:
|
|
||||||
result = nil
|
|
||||||
|
|
||||||
proc genRecComment(d: PDoc, n: PNode): PRope =
|
proc genRecComment(d: PDoc, n: PNode): PRope =
|
||||||
if n == nil:
|
if n == nil: return nil
|
||||||
return nil
|
|
||||||
result = genComment(d, n)
|
result = genComment(d, n)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
if not (n.kind in {nkEmpty..nkNilLit}):
|
if not (n.kind in {nkEmpty..nkNilLit}):
|
||||||
|
|
@ -293,11 +289,10 @@ proc genRecComment(d: PDoc, n: PNode): PRope =
|
||||||
n.comment = nil
|
n.comment = nil
|
||||||
|
|
||||||
proc isVisible(n: PNode): bool =
|
proc isVisible(n: PNode): bool =
|
||||||
var v: PIdent
|
|
||||||
result = false
|
result = false
|
||||||
if n.kind == nkPostfix:
|
if n.kind == nkPostfix:
|
||||||
if (sonsLen(n) == 2) and (n.sons[0].kind == nkIdent):
|
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))
|
result = (v.id == ord(wStar)) or (v.id == ord(wMinus))
|
||||||
elif n.kind == nkSym:
|
elif n.kind == nkSym:
|
||||||
result = sfInInterface in n.sym.flags
|
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)
|
setIndexForSourceTerm(d, getRstName(nameNode), d.id)
|
||||||
|
|
||||||
proc renderHeadline(d: PDoc, n: PRstNode): PRope =
|
proc renderHeadline(d: PDoc, n: PRstNode): PRope =
|
||||||
var
|
|
||||||
length: int
|
|
||||||
refname: PRope
|
|
||||||
result = nil
|
result = nil
|
||||||
for i in countup(0, rsonsLen(n) - 1): app(result, renderRstToOut(d, n.sons[i]))
|
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:
|
if d.hasToc:
|
||||||
length = len(d.tocPart)
|
var length = len(d.tocPart)
|
||||||
setlen(d.tocPart, length + 1)
|
setlen(d.tocPart, length + 1)
|
||||||
d.tocPart[length].refname = refname
|
d.tocPart[length].refname = refname
|
||||||
d.tocPart[length].n = n
|
d.tocPart[length].n = n
|
||||||
|
|
@ -424,8 +416,8 @@ proc renderOverline(d: PDoc, n: PRstNode): PRope =
|
||||||
|
|
||||||
proc renderRstToRst(d: PDoc, n: PRstNode): PRope
|
proc renderRstToRst(d: PDoc, n: PRstNode): PRope
|
||||||
proc renderRstSons(d: PDoc, n: PRstNode): PRope =
|
proc renderRstSons(d: PDoc, n: PRstNode): PRope =
|
||||||
result = nil
|
for i in countup(0, rsonsLen(n) - 1):
|
||||||
for i in countup(0, rsonsLen(n) - 1): app(result, renderRstToRst(d, n.sons[i]))
|
app(result, renderRstToRst(d, n.sons[i]))
|
||||||
|
|
||||||
proc renderRstToRst(d: PDoc, n: PRstNode): PRope =
|
proc renderRstToRst(d: PDoc, n: PRstNode): PRope =
|
||||||
# this is needed for the index generation; it may also be useful for
|
# 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])
|
[result])
|
||||||
|
|
||||||
proc renderContainer(d: PDoc, n: PRstNode): PRope =
|
proc renderContainer(d: PDoc, n: PRstNode): PRope =
|
||||||
var arg: PRope
|
|
||||||
result = renderRstToOut(d, n.sons[2])
|
result = renderRstToOut(d, n.sons[2])
|
||||||
arg = toRope(strip(getArgument(n)))
|
var arg = toRope(strip(getArgument(n)))
|
||||||
if arg == nil: result = dispF("<div>$1</div>", "$1", [result])
|
if arg == nil: result = dispF("<div>$1</div>", "$1", [result])
|
||||||
else: result = dispF("<div class=\"$1\">$2</div>", "$2", [arg, result])
|
else: result = dispF("<div class=\"$1\">$2</div>", "$2", [arg, result])
|
||||||
|
|
||||||
|
|
@ -874,12 +865,9 @@ proc generateIndex(d: PDoc) =
|
||||||
writeRope(renderRstToRst(d, d.indexFile), gIndexFile)
|
writeRope(renderRstToRst(d, d.indexFile), gIndexFile)
|
||||||
|
|
||||||
proc CommandDoc(filename: string) =
|
proc CommandDoc(filename: string) =
|
||||||
var
|
var ast = parseFile(addFileExt(filename, nimExt))
|
||||||
ast: PNode
|
|
||||||
d: PDoc
|
|
||||||
ast = parseFile(addFileExt(filename, nimExt))
|
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
d = newDocumentor(filename)
|
var d = newDocumentor(filename)
|
||||||
initIndexFile(d)
|
initIndexFile(d)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
generateDoc(d, ast)
|
generateDoc(d, ast)
|
||||||
|
|
@ -887,17 +875,12 @@ proc CommandDoc(filename: string) =
|
||||||
generateIndex(d)
|
generateIndex(d)
|
||||||
|
|
||||||
proc CommandRstAux(filename, outExt: string) =
|
proc CommandRstAux(filename, outExt: string) =
|
||||||
var
|
var filen = addFileExt(filename, "txt")
|
||||||
filen: string
|
var d = newDocumentor(filen)
|
||||||
d: PDoc
|
|
||||||
rst: PRstNode
|
|
||||||
code: PRope
|
|
||||||
filen = addFileExt(filename, "txt")
|
|
||||||
d = newDocumentor(filen)
|
|
||||||
initIndexFile(d)
|
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)
|
d.modDesc = renderRstToOut(d, rst)
|
||||||
code = genOutFile(d)
|
var code = genOutFile(d)
|
||||||
writeRope(code, getOutFile(filename, outExt))
|
writeRope(code, getOutFile(filename, outExt))
|
||||||
generateIndex(d)
|
generateIndex(d)
|
||||||
|
|
||||||
|
|
|
||||||
4
rod/pas2nim/pas2nim.cfg
Executable file
4
rod/pas2nim/pas2nim.cfg
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Use the modules of the compiler
|
||||||
|
|
||||||
|
path: "$nimrod/rod"
|
||||||
|
|
||||||
|
|
@ -46,7 +46,8 @@ type
|
||||||
# i = i + 1
|
# i = i + 1
|
||||||
#cog.out(idents)
|
#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,
|
tkConst, tkContinue, tkConverter, tkDiscard, tkDistinct, tkDiv, tkElif,
|
||||||
tkElse, tkEnd, tkEnum, tkExcept, tkFinally, tkFor, tkFrom, tkGeneric, tkIf,
|
tkElse, tkEnd, tkEnum, tkExcept, tkFinally, tkFor, tkFrom, tkGeneric, tkIf,
|
||||||
tkImplies, tkImport, tkIn, tkInclude, tkIs, tkIsnot, tkIterator, tkLambda,
|
tkImplies, tkImport, tkIn, tkInclude, tkIs, tkIsnot, tkIterator, tkLambda,
|
||||||
|
|
@ -77,7 +78,8 @@ const
|
||||||
"tkSymbol", #[[[cog
|
"tkSymbol", #[[[cog
|
||||||
#cog.out(strings)
|
#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",
|
"const", "continue", "converter", "discard", "distinct", "div", "elif",
|
||||||
"else", "end", "enum", "except", "finally", "for", "from", "generic", "if",
|
"else", "end", "enum", "except", "finally", "for", "from", "generic", "if",
|
||||||
"implies", "import", "in", "include", "is", "isnot", "iterator", "lambda",
|
"implies", "import", "in", "include", "is", "isnot", "iterator", "lambda",
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@ type
|
||||||
TSpecialWord* = enum
|
TSpecialWord* = enum
|
||||||
wInvalid,
|
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,
|
wContinue, wConverter, wDiscard, wDistinct, wDiv, wElif, wElse, wEnd, wEnum,
|
||||||
wExcept, wFinally, wFor, wFrom, wGeneric, wIf, wImplies, wImport, wIn,
|
wExcept, wFinally, wFor, wFrom, wGeneric, wIf, wImplies, wImport, wIn,
|
||||||
wInclude, wIs, wIsnot, wIterator, wLambda, wMacro, wMethod, wMod, wNil,
|
wInclude, wIs, wIsnot, wIterator, wLambda, wMacro, wMethod, wMod, wNil,
|
||||||
|
|
@ -62,7 +63,8 @@ const
|
||||||
oprHigh* = ord(wHat)
|
oprHigh* = ord(wHat)
|
||||||
specialWords*: array[low(TSpecialWord)..high(TSpecialWord), string] = ["",
|
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",
|
"const", "continue", "converter", "discard", "distinct", "div", "elif",
|
||||||
"else", "end", "enum", "except", "finally", "for", "from", "generic", "if",
|
"else", "end", "enum", "except", "finally", "for", "from", "generic", "if",
|
||||||
"implies", "import", "in", "include", "is", "isnot", "iterator", "lambda",
|
"implies", "import", "in", "include", "is", "isnot", "iterator", "lambda",
|
||||||
|
|
|
||||||
31
tools/cmerge.nim
Executable file
31
tools/cmerge.nim
Executable file
|
|
@ -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"))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue