improved expandimportc tool
This commit is contained in:
parent
f56816def0
commit
9dda24e475
6 changed files with 83 additions and 33 deletions
4
contributors.txt
Normal file
4
contributors.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
Mario Ray Mahardhika
|
||||||
|
Philippe Lhoste
|
||||||
|
Alexander R¿dseth
|
||||||
|
Jonathan Plona
|
||||||
|
|
@ -1774,13 +1774,11 @@ proc genConstSimpleList(p: BProc, n: PNode): PRope =
|
||||||
app(result, '}' & tnl)
|
app(result, '}' & tnl)
|
||||||
|
|
||||||
proc genConstExpr(p: BProc, n: PNode): PRope =
|
proc genConstExpr(p: BProc, n: PNode): PRope =
|
||||||
var
|
|
||||||
cs: TBitSet
|
|
||||||
d: TLoc
|
|
||||||
case n.Kind
|
case n.Kind
|
||||||
of nkHiddenStdConv, nkHiddenSubConv:
|
of nkHiddenStdConv, nkHiddenSubConv:
|
||||||
result = genConstExpr(p, n.sons[1])
|
result = genConstExpr(p, n.sons[1])
|
||||||
of nkCurly:
|
of nkCurly:
|
||||||
|
var cs: TBitSet
|
||||||
toBitSet(n, cs)
|
toBitSet(n, cs)
|
||||||
result = genRawSetData(cs, int(getSize(n.typ)))
|
result = genRawSetData(cs, int(getSize(n.typ)))
|
||||||
of nkBracket, nkPar:
|
of nkBracket, nkPar:
|
||||||
|
|
@ -1788,5 +1786,6 @@ proc genConstExpr(p: BProc, n: PNode): PRope =
|
||||||
result = genConstSimpleList(p, n)
|
result = genConstSimpleList(p, n)
|
||||||
else:
|
else:
|
||||||
# result := genLiteral(p, n)
|
# result := genLiteral(p, n)
|
||||||
|
var d: TLoc
|
||||||
initLocExpr(p, n, d)
|
initLocExpr(p, n, d)
|
||||||
result = rdLoc(d)
|
result = rdLoc(d)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
## the diverse wrappers.
|
## the diverse wrappers.
|
||||||
|
|
||||||
import
|
import
|
||||||
os, ropes, idents, ast, pnimsyn, rnimsyn, msgs, wordrecg, syntaxes
|
os, ropes, idents, ast, pnimsyn, rnimsyn, msgs, wordrecg, syntaxes, pegs
|
||||||
|
|
||||||
proc modifyPragmas(n: PNode, name: string) =
|
proc modifyPragmas(n: PNode, name: string) =
|
||||||
if n == nil: return
|
if n == nil: return
|
||||||
|
|
@ -36,17 +36,30 @@ proc processRoutine(n: PNode) =
|
||||||
var name = getName(n.sons[namePos])
|
var name = getName(n.sons[namePos])
|
||||||
modifyPragmas(n.sons[pragmasPos], name)
|
modifyPragmas(n.sons[pragmasPos], name)
|
||||||
|
|
||||||
proc processTree(n: PNode) =
|
proc processIdent(ident, prefix: string, n: PNode): string =
|
||||||
|
var pattern = sequence(capture(?(termIgnoreCase"T" / termIgnoreCase"P")),
|
||||||
|
termIgnoreCase(prefix), capture(*any))
|
||||||
|
if ident =~ pattern:
|
||||||
|
result = matches[0] & matches[1]
|
||||||
|
else:
|
||||||
|
result = ident
|
||||||
|
|
||||||
|
proc processTree(n: PNode, prefix: string) =
|
||||||
if n == nil: return
|
if n == nil: return
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkEmpty..nkNilLit: nil
|
of nkEmpty..pred(nkIdent), succ(nkIdent)..nkNilLit: nil
|
||||||
of nkProcDef, nkConverterDef: processRoutine(n)
|
of nkIdent:
|
||||||
|
if prefix.len > 0:
|
||||||
|
n.ident = getIdent(processIdent(n.ident.s, prefix, n))
|
||||||
|
of nkProcDef, nkConverterDef:
|
||||||
|
processRoutine(n)
|
||||||
|
for i in 0..sonsLen(n)-1: processTree(n.sons[i], prefix)
|
||||||
else:
|
else:
|
||||||
for i in 0..sonsLen(n)-1: processTree(n.sons[i])
|
for i in 0..sonsLen(n)-1: processTree(n.sons[i], prefix)
|
||||||
|
|
||||||
proc main(infile, outfile: string) =
|
proc main(infile, outfile, prefix: string) =
|
||||||
var module = ParseFile(infile)
|
var module = ParseFile(infile)
|
||||||
processTree(module)
|
processTree(module, prefix)
|
||||||
renderModule(module, outfile)
|
renderModule(module, outfile)
|
||||||
|
|
||||||
if paramcount() >= 1:
|
if paramcount() >= 1:
|
||||||
|
|
@ -54,6 +67,9 @@ if paramcount() >= 1:
|
||||||
var outfile = changeFileExt(infile, "new.nim")
|
var outfile = changeFileExt(infile, "new.nim")
|
||||||
if paramCount() >= 2:
|
if paramCount() >= 2:
|
||||||
outfile = addFileExt(paramStr(2), "new.nim")
|
outfile = addFileExt(paramStr(2), "new.nim")
|
||||||
main(infile, outfile)
|
var prefix = ""
|
||||||
|
if paramCount() >= 3:
|
||||||
|
prefix = paramStr(3)
|
||||||
|
main(infile, outfile, prefix)
|
||||||
else:
|
else:
|
||||||
echo "usage: expand_importc filename[.nim] outfilename[.nim]"
|
echo "usage: expand_importc filename[.nim] outfilename[.nim] [prefix]"
|
||||||
|
|
|
||||||
|
|
@ -35,38 +35,32 @@ proc getArg(n: PNode, name: string, pos: int): PNode =
|
||||||
return n.sons[i]
|
return n.sons[i]
|
||||||
|
|
||||||
proc charArg(n: PNode, name: string, pos: int, default: Char): Char =
|
proc charArg(n: PNode, name: string, pos: int, default: Char): Char =
|
||||||
var x: PNode
|
var x = getArg(n, name, pos)
|
||||||
x = getArg(n, name, pos)
|
|
||||||
if x == nil: result = default
|
if x == nil: result = default
|
||||||
elif x.kind == nkCharLit: result = chr(int(x.intVal))
|
elif x.kind == nkCharLit: result = chr(int(x.intVal))
|
||||||
else: invalidPragma(n)
|
else: invalidPragma(n)
|
||||||
|
|
||||||
proc strArg(n: PNode, name: string, pos: int, default: string): string =
|
proc strArg(n: PNode, name: string, pos: int, default: string): string =
|
||||||
var x: PNode
|
var x = getArg(n, name, pos)
|
||||||
x = getArg(n, name, pos)
|
|
||||||
if x == nil: result = default
|
if x == nil: result = default
|
||||||
elif x.kind in {nkStrLit..nkTripleStrLit}: result = x.strVal
|
elif x.kind in {nkStrLit..nkTripleStrLit}: result = x.strVal
|
||||||
else: invalidPragma(n)
|
else: invalidPragma(n)
|
||||||
|
|
||||||
proc boolArg(n: PNode, name: string, pos: int, default: bool): bool =
|
proc boolArg(n: PNode, name: string, pos: int, default: bool): bool =
|
||||||
var x: PNode
|
var x = getArg(n, name, pos)
|
||||||
x = getArg(n, name, pos)
|
|
||||||
if x == nil: result = default
|
if x == nil: result = default
|
||||||
elif (x.kind == nkIdent) and IdentEq(x.ident, "true"): result = true
|
elif (x.kind == nkIdent) and IdentEq(x.ident, "true"): result = true
|
||||||
elif (x.kind == nkIdent) and IdentEq(x.ident, "false"): result = false
|
elif (x.kind == nkIdent) and IdentEq(x.ident, "false"): result = false
|
||||||
else: invalidPragma(n)
|
else: invalidPragma(n)
|
||||||
|
|
||||||
proc filterStrip(stdin: PLLStream, filename: string, call: PNode): PLLStream =
|
proc filterStrip(stdin: PLLStream, filename: string, call: PNode): PLLStream =
|
||||||
var
|
var pattern = strArg(call, "startswith", 1, "")
|
||||||
line, pattern, stripped: string
|
var leading = boolArg(call, "leading", 2, true)
|
||||||
leading, trailing: bool
|
var trailing = boolArg(call, "trailing", 3, true)
|
||||||
pattern = strArg(call, "startswith", 1, "")
|
|
||||||
leading = boolArg(call, "leading", 2, true)
|
|
||||||
trailing = boolArg(call, "trailing", 3, true)
|
|
||||||
result = LLStreamOpen("")
|
result = LLStreamOpen("")
|
||||||
while not LLStreamAtEnd(stdin):
|
while not LLStreamAtEnd(stdin):
|
||||||
line = LLStreamReadLine(stdin)
|
var line = LLStreamReadLine(stdin)
|
||||||
stripped = strip(line, leading, trailing)
|
var stripped = strip(line, leading, trailing)
|
||||||
if (len(pattern) == 0) or startsWith(stripped, pattern):
|
if (len(pattern) == 0) or startsWith(stripped, pattern):
|
||||||
LLStreamWriteln(result, stripped)
|
LLStreamWriteln(result, stripped)
|
||||||
else:
|
else:
|
||||||
|
|
@ -74,12 +68,11 @@ proc filterStrip(stdin: PLLStream, filename: string, call: PNode): PLLStream =
|
||||||
LLStreamClose(stdin)
|
LLStreamClose(stdin)
|
||||||
|
|
||||||
proc filterReplace(stdin: PLLStream, filename: string, call: PNode): PLLStream =
|
proc filterReplace(stdin: PLLStream, filename: string, call: PNode): PLLStream =
|
||||||
var line, sub, by: string
|
var sub = strArg(call, "sub", 1, "")
|
||||||
sub = strArg(call, "sub", 1, "")
|
|
||||||
if len(sub) == 0: invalidPragma(call)
|
if len(sub) == 0: invalidPragma(call)
|
||||||
by = strArg(call, "by", 2, "")
|
var by = strArg(call, "by", 2, "")
|
||||||
result = LLStreamOpen("")
|
result = LLStreamOpen("")
|
||||||
while not LLStreamAtEnd(stdin):
|
while not LLStreamAtEnd(stdin):
|
||||||
line = LLStreamReadLine(stdin)
|
var line = LLStreamReadLine(stdin)
|
||||||
LLStreamWriteln(result, replace(line, sub, by))
|
LLStreamWriteln(result, replace(line, sub, by))
|
||||||
LLStreamClose(stdin)
|
LLStreamClose(stdin)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ Files: "doc/*.html"
|
||||||
Files: "doc/*.cfg"
|
Files: "doc/*.cfg"
|
||||||
|
|
||||||
[Other]
|
[Other]
|
||||||
Files: "readme.txt;install.txt"
|
Files: "readme.txt;install.txt;contributors.txt"
|
||||||
Files: "configure;makefile"
|
Files: "configure;makefile"
|
||||||
Files: "*.html"
|
Files: "*.html"
|
||||||
Files: "*.ini"
|
Files: "*.ini"
|
||||||
|
|
|
||||||
42
web/news.txt
42
web/news.txt
|
|
@ -6,17 +6,55 @@ News
|
||||||
2009-XX-XX Version 0.8.6 released
|
2009-XX-XX Version 0.8.6 released
|
||||||
=================================
|
=================================
|
||||||
|
|
||||||
|
Version 0.8.6 has been released! Get it `here <download.html>`_. The version
|
||||||
|
jump from 0.8.2 to 0.8.6 acknowledges the fact that all development of the
|
||||||
|
compiler is now done in Nimrod.
|
||||||
|
|
||||||
|
|
||||||
Bugfixes
|
Bugfixes
|
||||||
--------
|
--------
|
||||||
|
- The pragmas ``hint[X]:off`` and ``warning[X]:off`` now work.
|
||||||
|
- Method call syntax for iterators works again (``for x in lines.split()``).
|
||||||
|
- Many bugfixes concerning macro evaluation.
|
||||||
|
- Many bugfixes concerning compile-time evaluation.
|
||||||
|
- Fixed a typo in ``removeDir`` for POSIX that lead to an infinite recursion.
|
||||||
|
- The compiler now checks that module filenames are valid identifiers.
|
||||||
|
- Empty patterns for the ``dynlib`` pragma are now possible.
|
||||||
|
- ``os.parseCmdLine`` returned wrong results for trailing whitespace.
|
||||||
|
- Inconsequent tuple usage (using the same tuple with and without named fields)
|
||||||
|
does not crash the code generator anymore.
|
||||||
|
- A better error message is provided when the loading of a proc within a
|
||||||
|
dynamic lib fails.
|
||||||
|
|
||||||
|
|
||||||
Additions
|
Additions
|
||||||
---------
|
---------
|
||||||
|
- Added ``system.contains`` for open arrays.
|
||||||
|
- The PEG module now supports the *search loop operator* ``@``.
|
||||||
|
- Grammar/parser: ``SAD|IND`` is allowed before any kind of closing bracket.
|
||||||
|
This allows for more flexible source code formating.
|
||||||
|
- The compiler now uses a *bind* table for symbol lookup within a ``bind``
|
||||||
|
context. (See `<manual/#templates>`_ for details.)
|
||||||
|
- ``discard """my long comment"""`` is now optimized away.
|
||||||
|
- New ``--floatChecks: on|off`` switches and pragmas for better debugging
|
||||||
|
of floating point operations. (See
|
||||||
|
`<manual/#pre-defined-floating-point-types>`_ for details.)
|
||||||
|
|
||||||
|
|
||||||
Changes affecting backwards compatibility
|
Changes affecting backwards compatibility
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
- The compiler does not skip the linking step anymore even if no file
|
- The compiler does not skip the linking step anymore even if no file
|
||||||
has changed.
|
has changed.
|
||||||
|
- ``os.splitFile(".xyz")`` now returns ``("", ".xyz", "")`` instead of
|
||||||
|
``("", "", ".xyz")``. Filenames starting with a dot are handled
|
||||||
|
differently.
|
||||||
|
- ``strutils.split(s: string, seps: set[char])`` never yields the empty string
|
||||||
|
anymore. This behaviour is probably more appropriate for whitespace splitting.
|
||||||
|
- The compiler now stops after the ``--version`` command line switch.
|
||||||
|
- Removed support for enum inheritance in the parser; enum inheritance has
|
||||||
|
never been documented anyway.
|
||||||
|
- The ``msg`` field of ``system.E_base`` has now the type ``string``, instead
|
||||||
|
of ``cstring``. This improves memory safety.
|
||||||
|
|
||||||
|
|
||||||
2009-10-21 Version 0.8.2 released
|
2009-10-21 Version 0.8.2 released
|
||||||
|
|
@ -144,7 +182,7 @@ Documentation
|
||||||
2009-06-08 Version 0.7.10 released
|
2009-06-08 Version 0.7.10 released
|
||||||
==================================
|
==================================
|
||||||
|
|
||||||
Nimrod version 0.7.10 has been released! Get it `here <./download.html>`_.
|
Nimrod version 0.7.10 has been released!
|
||||||
|
|
||||||
Bugfixes
|
Bugfixes
|
||||||
--------
|
--------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue