Merge branch 'master' of git@github.com:Araq/Nimrod
This commit is contained in:
commit
086f0d34db
3 changed files with 41 additions and 41 deletions
|
|
@ -7,7 +7,7 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
import
|
import
|
||||||
strutils, os, times, parseopt, llstream, ast, renderer, options, msgs,
|
strutils, os, times, parseopt, llstream, ast, renderer, options, msgs,
|
||||||
clex, cparse
|
clex, cparse
|
||||||
|
|
||||||
|
|
@ -17,16 +17,16 @@ const
|
||||||
c2nim - C to Nimrod source converter
|
c2nim - C to Nimrod source converter
|
||||||
(c) 2011 Andreas Rumpf
|
(c) 2011 Andreas Rumpf
|
||||||
Usage: c2nim [options] inputfile [options]
|
Usage: c2nim [options] inputfile [options]
|
||||||
Options:
|
Options:
|
||||||
-o, --out:FILE set output filename
|
-o, --out:FILE set output filename
|
||||||
--dynlib:SYMBOL import from dynlib: SYMBOL will be used for the import
|
--dynlib:SYMBOL import from dynlib: SYMBOL will be used for the import
|
||||||
--header:HEADER_FILE import from a HEADER_FILE (discouraged!)
|
--header:HEADER_FILE import from a HEADER_FILE (discouraged!)
|
||||||
--cdecl annotate procs with ``{.cdecl.}``
|
--cdecl annotate procs with ``{.cdecl.}``
|
||||||
--stdcall annotate procs with ``{.stdcall.}``
|
--stdcall annotate procs with ``{.stdcall.}``
|
||||||
--ref convert typ* to ref typ (default: ptr typ)
|
--ref convert typ* to ref typ (default: ptr typ)
|
||||||
--prefix:PREFIX strip prefix for the generated Nimrod identifiers
|
--prefix:PREFIX strip prefix for the generated Nimrod identifiers
|
||||||
(multiple --prefix options are supported)
|
(multiple --prefix options are supported)
|
||||||
--suffix:SUFFIX strip suffix for the generated Nimrod identifiers
|
--suffix:SUFFIX strip suffix for the generated Nimrod identifiers
|
||||||
(multiple --suffix options are supported)
|
(multiple --suffix options are supported)
|
||||||
--skipinclude do not convert ``#include`` to ``import``
|
--skipinclude do not convert ``#include`` to ``import``
|
||||||
--typeprefixes generate ``T`` and ``P`` type prefixes
|
--typeprefixes generate ``T`` and ``P`` type prefixes
|
||||||
|
|
@ -35,7 +35,7 @@ Options:
|
||||||
-h, --help show this help
|
-h, --help show this help
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc main(infile, outfile: string, options: PParserOptions) =
|
proc main(infile, outfile: string, options: PParserOptions) =
|
||||||
var start = getTime()
|
var start = getTime()
|
||||||
var stream = LLStreamOpen(infile, fmRead)
|
var stream = LLStreamOpen(infile, fmRead)
|
||||||
if stream == nil: rawMessage(errCannotOpenFile, infile)
|
if stream == nil: rawMessage(errCannotOpenFile, infile)
|
||||||
|
|
@ -61,10 +61,10 @@ for kind, key, val in getopt():
|
||||||
of "version", "v":
|
of "version", "v":
|
||||||
stdout.write(Version & "\n")
|
stdout.write(Version & "\n")
|
||||||
quit(0)
|
quit(0)
|
||||||
of "o", "out": outfile = key
|
of "o", "out": outfile = val
|
||||||
else:
|
else:
|
||||||
if not parserOptions.setOption(key, val):
|
if not parserOptions.setOption(key, val):
|
||||||
stdout.write("[Error] unknown option: " & key)
|
stdout.writeln("[Error] unknown option: " & key)
|
||||||
of cmdEnd: assert(false)
|
of cmdEnd: assert(false)
|
||||||
if infile.len == 0:
|
if infile.len == 0:
|
||||||
# no filename has been given, so we show the help:
|
# no filename has been given, so we show the help:
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
import
|
import
|
||||||
strutils, os, parseopt, llstream, ast, renderer, options, msgs,
|
strutils, os, parseopt, llstream, ast, renderer, options, msgs,
|
||||||
paslex, pasparse
|
paslex, pasparse
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ const
|
||||||
pas2nim - Pascal to Nimrod source converter
|
pas2nim - Pascal to Nimrod source converter
|
||||||
(c) 2010 Andreas Rumpf
|
(c) 2010 Andreas Rumpf
|
||||||
Usage: pas2nim [options] inputfile [options]
|
Usage: pas2nim [options] inputfile [options]
|
||||||
Options:
|
Options:
|
||||||
-o, --out:FILE set output filename
|
-o, --out:FILE set output filename
|
||||||
--ref convert ^typ to ref typ (default: ptr typ)
|
--ref convert ^typ to ref typ (default: ptr typ)
|
||||||
--boot use special translation rules for the Nimrod compiler
|
--boot use special translation rules for the Nimrod compiler
|
||||||
|
|
@ -25,7 +25,7 @@ Options:
|
||||||
-h, --help show this help
|
-h, --help show this help
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc main(infile, outfile: string, flags: set[TParserFlag]) =
|
proc main(infile, outfile: string, flags: set[TParserFlag]) =
|
||||||
var stream = LLStreamOpen(infile, fmRead)
|
var stream = LLStreamOpen(infile, fmRead)
|
||||||
if stream == nil: rawMessage(errCannotOpenFile, infile)
|
if stream == nil: rawMessage(errCannotOpenFile, infile)
|
||||||
var p: TParser
|
var p: TParser
|
||||||
|
|
@ -49,10 +49,10 @@ for kind, key, val in getopt():
|
||||||
of "version", "v":
|
of "version", "v":
|
||||||
stdout.write(Version & "\n")
|
stdout.write(Version & "\n")
|
||||||
quit(0)
|
quit(0)
|
||||||
of "o", "out": outfile = key
|
of "o", "out": outfile = val
|
||||||
of "ref": incl(flags, pfRefs)
|
of "ref": incl(flags, pfRefs)
|
||||||
of "boot": flags = flags + {pfRefs, pfMoreReplacements, pfImportBlackList}
|
of "boot": flags = flags + {pfRefs, pfMoreReplacements, pfImportBlackList}
|
||||||
else: stdout.write("[Error] unknown option: " & key)
|
else: stdout.writeln("[Error] unknown option: " & key)
|
||||||
of cmdEnd: assert(false)
|
of cmdEnd: assert(false)
|
||||||
if infile.len == 0:
|
if infile.len == 0:
|
||||||
# no filename has been given, so we show the help:
|
# no filename has been given, so we show the help:
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
parseutils, strutils, pegs, os, osproc, streams, parsecfg, browsers, json,
|
parseutils, strutils, pegs, os, osproc, streams, parsecfg, browsers, json,
|
||||||
marshal
|
marshal, cgi
|
||||||
|
|
||||||
const
|
const
|
||||||
cmdTemplate = r"nimrod cc --hints:on $# $#"
|
cmdTemplate = r"nimrod cc --hints:on $# $#"
|
||||||
|
|
@ -34,33 +34,33 @@ type
|
||||||
TResults {.pure.} = object
|
TResults {.pure.} = object
|
||||||
total, passed, skipped: int
|
total, passed, skipped: int
|
||||||
data: string
|
data: string
|
||||||
|
|
||||||
TResultEnum = enum
|
TResultEnum = enum
|
||||||
reFailure, reIgnored, reSuccess
|
reFailure, reIgnored, reSuccess
|
||||||
|
|
||||||
# ----------------------- Spec parser ----------------------------------------
|
# ----------------------- Spec parser ----------------------------------------
|
||||||
|
|
||||||
when not defined(parseCfgBool):
|
when not defined(parseCfgBool):
|
||||||
# candidate for the stdlib:
|
# candidate for the stdlib:
|
||||||
proc parseCfgBool(s: string): bool =
|
proc parseCfgBool(s: string): bool =
|
||||||
case normalize(s)
|
case normalize(s)
|
||||||
of "y", "yes", "true", "1", "on": result = true
|
of "y", "yes", "true", "1", "on": result = true
|
||||||
of "n", "no", "false", "0", "off": result = false
|
of "n", "no", "false", "0", "off": result = false
|
||||||
else: raise newException(EInvalidValue, "cannot interpret as a bool: " & s)
|
else: raise newException(EInvalidValue, "cannot interpret as a bool: " & s)
|
||||||
|
|
||||||
proc extractSpec(filename: string): string =
|
proc extractSpec(filename: string): string =
|
||||||
const tripleQuote = "\"\"\""
|
const tripleQuote = "\"\"\""
|
||||||
var x = readFile(filename)
|
var x = readFile(filename)
|
||||||
if isNil(x): quit "cannot open file: " & filename
|
if isNil(x): quit "cannot open file: " & filename
|
||||||
var a = x.find(tripleQuote)
|
var a = x.find(tripleQuote)
|
||||||
var b = x.find(tripleQuote, a+3)
|
var b = x.find(tripleQuote, a+3)
|
||||||
if a >= 0 and b > a:
|
if a >= 0 and b > a:
|
||||||
result = x.substr(a+3, b-1).replace("'''", tripleQuote)
|
result = x.substr(a+3, b-1).replace("'''", tripleQuote)
|
||||||
else:
|
else:
|
||||||
#echo "warning: file does not contain spec: " & filename
|
#echo "warning: file does not contain spec: " & filename
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
template parseSpecAux(fillResult: stmt) =
|
template parseSpecAux(fillResult: stmt) =
|
||||||
var ss = newStringStream(extractSpec(filename))
|
var ss = newStringStream(extractSpec(filename))
|
||||||
var p: TCfgParser
|
var p: TCfgParser
|
||||||
open(p, ss, filename, 1)
|
open(p, ss, filename, 1)
|
||||||
|
|
@ -73,8 +73,8 @@ template parseSpecAux(fillResult: stmt) =
|
||||||
of cfgKeyValuePair:
|
of cfgKeyValuePair:
|
||||||
fillResult
|
fillResult
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
proc parseSpec(filename: string): TSpec =
|
proc parseSpec(filename: string): TSpec =
|
||||||
result.file = filename
|
result.file = filename
|
||||||
result.err = true
|
result.err = true
|
||||||
result.msg = ""
|
result.msg = ""
|
||||||
|
|
@ -82,7 +82,7 @@ proc parseSpec(filename: string): TSpec =
|
||||||
result.cmd = cmdTemplate
|
result.cmd = cmdTemplate
|
||||||
parseSpecAux:
|
parseSpecAux:
|
||||||
case normalize(e.key)
|
case normalize(e.key)
|
||||||
of "action":
|
of "action":
|
||||||
case e.value.normalize
|
case e.value.normalize
|
||||||
of "compile": result.action = actionCompile
|
of "compile": result.action = actionCompile
|
||||||
of "run": result.action = actionRun
|
of "run": result.action = actionRun
|
||||||
|
|
@ -126,7 +126,7 @@ proc callCompiler(cmdTemplate, filename, options: string): TSpec =
|
||||||
result.msg = ""
|
result.msg = ""
|
||||||
result.file = ""
|
result.file = ""
|
||||||
result.outp = ""
|
result.outp = ""
|
||||||
result.err = true
|
result.err = true
|
||||||
result.line = -1
|
result.line = -1
|
||||||
if s =~ pegLineError:
|
if s =~ pegLineError:
|
||||||
result.file = extractFilename(matches[0])
|
result.file = extractFilename(matches[0])
|
||||||
|
|
@ -137,7 +137,7 @@ proc callCompiler(cmdTemplate, filename, options: string): TSpec =
|
||||||
elif s =~ pegSuccess:
|
elif s =~ pegSuccess:
|
||||||
result.err = false
|
result.err = false
|
||||||
|
|
||||||
proc initResults: TResults =
|
proc initResults: TResults =
|
||||||
result.total = 0
|
result.total = 0
|
||||||
result.passed = 0
|
result.passed = 0
|
||||||
result.skipped = 0
|
result.skipped = 0
|
||||||
|
|
@ -149,7 +149,7 @@ proc readResults(filename: string): TResults =
|
||||||
proc writeResults(filename: string, r: TResults) =
|
proc writeResults(filename: string, r: TResults) =
|
||||||
writeFile(filename, $$r)
|
writeFile(filename, $$r)
|
||||||
|
|
||||||
proc `$`(x: TResults): string =
|
proc `$`(x: TResults): string =
|
||||||
result = ("Tests passed: $1 / $3 <br />\n" &
|
result = ("Tests passed: $1 / $3 <br />\n" &
|
||||||
"Tests skipped: $2 / $3 <br />\n") %
|
"Tests skipped: $2 / $3 <br />\n") %
|
||||||
[$x.passed, $x.skipped, $x.total]
|
[$x.passed, $x.skipped, $x.total]
|
||||||
|
|
@ -158,7 +158,7 @@ proc colorResult(r: TResultEnum): string =
|
||||||
case r
|
case r
|
||||||
of reFailure: result = "<span style=\"color:red\">no</span>"
|
of reFailure: result = "<span style=\"color:red\">no</span>"
|
||||||
of reIgnored: result = "<span style=\"color:fuchsia\">ignored</span>"
|
of reIgnored: result = "<span style=\"color:fuchsia\">ignored</span>"
|
||||||
of reSuccess: result = "<span style=\"color:green\">yes</span>"
|
of reSuccess: result = "<span style=\"color:green\">yes</span>"
|
||||||
|
|
||||||
const
|
const
|
||||||
TableHeader4 = "<table border=\"1\"><tr><td>Test</td><td>Expected</td>" &
|
TableHeader4 = "<table border=\"1\"><tr><td>Test</td><td>Expected</td>" &
|
||||||
|
|
@ -170,12 +170,12 @@ const
|
||||||
proc addResult(r: var TResults, test, expected, given: string,
|
proc addResult(r: var TResults, test, expected, given: string,
|
||||||
success: TResultEnum) =
|
success: TResultEnum) =
|
||||||
r.data.addf("<tr><td>$#</td><td>$#</td><td>$#</td><td>$#</td></tr>\n", [
|
r.data.addf("<tr><td>$#</td><td>$#</td><td>$#</td><td>$#</td></tr>\n", [
|
||||||
test, expected, given, success.colorResult])
|
XMLEncode(test), XMLEncode(expected), XMLEncode(given), success.colorResult])
|
||||||
|
|
||||||
proc addResult(r: var TResults, test, given: string,
|
proc addResult(r: var TResults, test, given: string,
|
||||||
success: TResultEnum) =
|
success: TResultEnum) =
|
||||||
r.data.addf("<tr><td>$#</td><td>$#</td><td>$#</td></tr>\n", [
|
r.data.addf("<tr><td>$#</td><td>$#</td><td>$#</td></tr>\n", [
|
||||||
test, given, success.colorResult])
|
XMLEncode(test), XMLEncode(given), success.colorResult])
|
||||||
|
|
||||||
proc listResults(reject, compile, run: TResults) =
|
proc listResults(reject, compile, run: TResults) =
|
||||||
var s = "<html>"
|
var s = "<html>"
|
||||||
|
|
@ -191,7 +191,7 @@ proc listResults(reject, compile, run: TResults) =
|
||||||
s.add("</html>")
|
s.add("</html>")
|
||||||
writeFile(resultsFile, s)
|
writeFile(resultsFile, s)
|
||||||
|
|
||||||
proc cmpMsgs(r: var TResults, expected, given: TSpec, test: string) =
|
proc cmpMsgs(r: var TResults, expected, given: TSpec, test: string) =
|
||||||
if strip(expected.msg) notin strip(given.msg):
|
if strip(expected.msg) notin strip(given.msg):
|
||||||
r.addResult(test, expected.msg, given.msg, reFailure)
|
r.addResult(test, expected.msg, given.msg, reFailure)
|
||||||
elif extractFilename(expected.file) != extractFilename(given.file) and
|
elif extractFilename(expected.file) != extractFilename(given.file) and
|
||||||
|
|
@ -203,20 +203,20 @@ proc cmpMsgs(r: var TResults, expected, given: TSpec, test: string) =
|
||||||
r.addResult(test, expected.msg, given.msg, reSuccess)
|
r.addResult(test, expected.msg, given.msg, reSuccess)
|
||||||
inc(r.passed)
|
inc(r.passed)
|
||||||
|
|
||||||
proc reject(r: var TResults, dir, options: string) =
|
proc reject(r: var TResults, dir, options: string) =
|
||||||
## handle all the tests that the compiler should reject
|
## handle all the tests that the compiler should reject
|
||||||
for test in os.walkFiles(dir / "t*.nim"):
|
for test in os.walkFiles(dir / "t*.nim"):
|
||||||
var t = extractFilename(test)
|
var t = extractFilename(test)
|
||||||
inc(r.total)
|
inc(r.total)
|
||||||
echo t
|
echo t
|
||||||
var expected = parseSpec(test)
|
var expected = parseSpec(test)
|
||||||
if expected.disabled:
|
if expected.disabled:
|
||||||
r.addResult(t, "", "", reIgnored)
|
r.addResult(t, "", "", reIgnored)
|
||||||
inc(r.skipped)
|
inc(r.skipped)
|
||||||
else:
|
else:
|
||||||
var given = callCompiler(expected.cmd, test, options)
|
var given = callCompiler(expected.cmd, test, options)
|
||||||
cmpMsgs(r, expected, given, t)
|
cmpMsgs(r, expected, given, t)
|
||||||
|
|
||||||
proc compile(r: var TResults, pattern, options: string) =
|
proc compile(r: var TResults, pattern, options: string) =
|
||||||
for test in os.walkFiles(pattern):
|
for test in os.walkFiles(pattern):
|
||||||
var t = extractFilename(test)
|
var t = extractFilename(test)
|
||||||
|
|
@ -258,15 +258,15 @@ proc runSingleTest(r: var TResults, test, options: string) =
|
||||||
var success = strip(buf) == strip(expected.outp)
|
var success = strip(buf) == strip(expected.outp)
|
||||||
if expected.substr: success = expected.outp in buf
|
if expected.substr: success = expected.outp in buf
|
||||||
if success: inc(r.passed)
|
if success: inc(r.passed)
|
||||||
r.addResult(t, expected.outp,
|
r.addResult(t, expected.outp,
|
||||||
buf, if success: reSuccess else: reFailure)
|
buf, if success: reSuccess else: reFailure)
|
||||||
else:
|
else:
|
||||||
r.addResult(t, expected.outp, "executable not found", reFailure)
|
r.addResult(t, expected.outp, "executable not found", reFailure)
|
||||||
|
|
||||||
proc run(r: var TResults, dir, options: string) =
|
proc run(r: var TResults, dir, options: string) =
|
||||||
for test in os.walkFiles(dir / "t*.nim"): runSingleTest(r, test, options)
|
for test in os.walkFiles(dir / "t*.nim"): runSingleTest(r, test, options)
|
||||||
|
|
||||||
proc compileExample(r: var TResults, pattern, options: string) =
|
proc compileExample(r: var TResults, pattern, options: string) =
|
||||||
for test in os.walkFiles(pattern): compileSingleTest(r, test, options)
|
for test in os.walkFiles(pattern): compileSingleTest(r, test, options)
|
||||||
|
|
||||||
proc toJson(res: TResults): PJsonNode =
|
proc toJson(res: TResults): PJsonNode =
|
||||||
|
|
@ -282,9 +282,9 @@ proc outputJSON(reject, compile, run: TResults) =
|
||||||
doc["run"] = toJson(run)
|
doc["run"] = toJson(run)
|
||||||
var s = pretty(doc)
|
var s = pretty(doc)
|
||||||
writeFile(jsonFile, s)
|
writeFile(jsonFile, s)
|
||||||
|
|
||||||
proc main(action: string) =
|
proc main(action: string) =
|
||||||
const
|
const
|
||||||
compileJson = "compile.json"
|
compileJson = "compile.json"
|
||||||
runJson = "run.json"
|
runJson = "run.json"
|
||||||
rejectJson = "reject.json"
|
rejectJson = "reject.json"
|
||||||
|
|
@ -292,7 +292,7 @@ proc main(action: string) =
|
||||||
for i in 2.. paramCount():
|
for i in 2.. paramCount():
|
||||||
add(options, " ")
|
add(options, " ")
|
||||||
add(options, paramStr(i))
|
add(options, paramStr(i))
|
||||||
|
|
||||||
case action
|
case action
|
||||||
of "reject":
|
of "reject":
|
||||||
var rejectRes = initResults()
|
var rejectRes = initResults()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue