unary <; countup two type parameters; --recursivePath should work now

This commit is contained in:
Araq 2011-01-29 14:18:43 +01:00
commit 36accda8aa
13 changed files with 69 additions and 54 deletions

View file

@ -30,7 +30,7 @@ path="$lib/windows"
path="$lib/posix" path="$lib/posix"
path="$lib/ecmas" path="$lib/ecmas"
path="$lib/pure/unidecode" path="$lib/pure/unidecode"
#recursivePath:"$user/.babel/lib" #recursivePath:"$home/.babel/lib"
@if release or quick: @if release or quick:
obj_checks:off obj_checks:off

View file

@ -861,7 +861,7 @@ iterator walkDir*(dir: string): tuple[kind: TPathComponent, path: string] =
if y != "." and y != "..": if y != "." and y != "..":
var s: TStat var s: TStat
y = dir / y y = dir / y
if stat(y, s) < 0'i32: break if lstat(y, s) < 0'i32: break
var k = pcFile var k = pcFile
if S_ISDIR(s.st_mode): k = pcDir if S_ISDIR(s.st_mode): k = pcDir
if S_ISLNK(s.st_mode): k = succ(k) if S_ISLNK(s.st_mode): k = succ(k)
@ -1245,3 +1245,4 @@ proc findExe*(exe: string): string =
result = "" result = ""
{.pop.} {.pop.}

View file

@ -1,7 +1,7 @@
# #
# #
# Nimrod's Runtime Library # Nimrod's Runtime Library
# (c) Copyright 2010 Andreas Rumpf # (c) Copyright 2011 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.
@ -247,6 +247,14 @@ proc sizeof*[T](x: T): natural {.magic: "SizeOf", noSideEffect.}
## that one never needs to know ``x``'s size. As a special semantic rule, ## that one never needs to know ``x``'s size. As a special semantic rule,
## ``x`` may also be a type identifier (``sizeof(int)`` is valid). ## ``x`` may also be a type identifier (``sizeof(int)`` is valid).
proc `<`*[T](x: ordinal[T]): T {.magic: "UnaryLt", noSideEffect.}
## unary ``<`` that can be used for nice looking excluding ranges:
##
## .. code-block:: nimrod
## for i in 0 .. <10: echo i
##
## Semantically this is the same as ``pred``.
proc succ*[T](x: ordinal[T], y = 1): T {.magic: "Succ", noSideEffect.} proc succ*[T](x: ordinal[T], y = 1): T {.magic: "Succ", noSideEffect.}
## returns the ``y``-th successor of the value ``x``. ``T`` has to be ## returns the ``y``-th successor of the value ``x``. ``T`` has to be
## an ordinal type. If such a value does not exist, ``EOutOfRange`` is raised ## an ordinal type. If such a value does not exist, ``EOutOfRange`` is raised
@ -1017,11 +1025,11 @@ iterator countdown*[T](a, b: T, step = 1): T {.inline.} =
yield res yield res
dec(res, step) dec(res, step)
iterator countup*[T](a, b: T, step = 1): T {.inline.} = iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
## Counts from ordinal value `a` up to `b` with the given ## Counts from ordinal value `a` up to `b` with the given
## step count. `T` may be any ordinal type, `step` may only ## step count. `S`, `T` may be any ordinal type, `step` may only
## be positive. ## be positive.
var res = a var res: T = a
while res <= b: while res <= b:
yield res yield res
inc(res, step) inc(res, step)
@ -1459,6 +1467,8 @@ when not defined(EcmaScript) and not defined(NimrodVM):
proc write*(f: TFile, r: float) proc write*(f: TFile, r: float)
proc write*(f: TFile, i: int) proc write*(f: TFile, i: int)
proc write*(f: TFile, i: biggestInt)
proc write*(f: TFile, r: biggestFloat)
proc write*(f: TFile, s: string) proc write*(f: TFile, s: string)
proc write*(f: TFile, b: Bool) proc write*(f: TFile, b: Bool)
proc write*(f: TFile, c: char) proc write*(f: TFile, c: char)

View file

@ -1,7 +1,7 @@
# #
# #
# Nimrod's Runtime Library # Nimrod's Runtime Library
# (c) Copyright 2009 Andreas Rumpf # (c) Copyright 2011 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.
@ -59,11 +59,19 @@ proc write(f: TFile, i: int) =
fprintf(f, "%lld", i) fprintf(f, "%lld", i)
else: else:
fprintf(f, "%ld", i) fprintf(f, "%ld", i)
proc write(f: TFile, i: biggestInt) =
when sizeof(biggestint) == 8:
fprintf(f, "%lld", i)
else:
fprintf(f, "%ld", i)
proc write(f: TFile, b: bool) = proc write(f: TFile, b: bool) =
if b: write(f, "true") if b: write(f, "true")
else: write(f, "false") else: write(f, "false")
proc write(f: TFile, r: float) = fprintf(f, "%g", r) proc write(f: TFile, r: float) = fprintf(f, "%g", r)
proc write(f: TFile, r: biggestFloat) = fprintf(f, "%g", r)
proc write(f: TFile, c: Char) = putc(c, f) proc write(f: TFile, c: Char) = putc(c, f)
proc write(f: TFile, a: openArray[string]) = proc write(f: TFile, a: openArray[string]) =
for x in items(a): write(f, x) for x in items(a): write(f, x)

View file

@ -300,7 +300,8 @@ type
TSymKinds* = set[TSymKind] TSymKinds* = set[TSymKind]
TMagic* = enum # symbols that require compiler magic: TMagic* = enum # symbols that require compiler magic:
mNone, mDefined, mDefinedInScope, mLow, mHigh, mSizeOf, mIs, mEcho, mSucc, mNone, mDefined, mDefinedInScope, mLow, mHigh, mSizeOf, mIs, mEcho,
mUnaryLt, mSucc,
mPred, mInc, mDec, mOrd, mNew, mNewFinalize, mNewSeq, mLengthOpenArray, mPred, mInc, mDec, mOrd, mNew, mNewFinalize, mNewSeq, mLengthOpenArray,
mLengthStr, mLengthArray, mLengthSeq, mIncl, mExcl, mCard, mChr, mGCref, mLengthStr, mLengthArray, mLengthSeq, mIncl, mExcl, mCard, mChr, mGCref,
mGCunref, mAddI, mSubI, mMulI, mDivI, mModI, mAddI64, mSubI64, mMulI64, mGCunref, mAddI, mSubI, mMulI, mDivI, mModI, mAddI64, mSubI64, mMulI64,

View file

@ -1369,6 +1369,9 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
of mAddi..mModi64: binaryArithOverflow(p, e, d, op) of mAddi..mModi64: binaryArithOverflow(p, e, d, op)
of mRepr: genRepr(p, e, d) of mRepr: genRepr(p, e, d)
of mSwap: genSwap(p, e, d) of mSwap: genSwap(p, e, d)
of mUnaryLt:
if not (optOverflowCheck in p.Options): unaryExpr(p, e, d, "$1 - 1")
else: unaryExpr(p, e, d, "#subInt($1, 1)")
of mPred: of mPred:
# XXX: range checking? # XXX: range checking?
if not (optOverflowCheck in p.Options): binaryExpr(p, e, d, "$1 - $2") if not (optOverflowCheck in p.Options): binaryExpr(p, e, d, "$1 - $2")

View file

@ -274,10 +274,18 @@ proc processPath(path: string): string =
result = UnixToNativePath(path % ["nimrod", getPrefixDir(), "lib", libpath, result = UnixToNativePath(path % ["nimrod", getPrefixDir(), "lib", libpath,
"home", removeTrailingDirSep(os.getHomeDir())]) "home", removeTrailingDirSep(os.getHomeDir())])
proc addPath(path: string) = proc addPath(path: string, info: TLineInfo) =
if not contains(options.searchPaths, path): if not contains(options.searchPaths, path):
lists.PrependStr(options.searchPaths, path) lists.PrependStr(options.searchPaths, path)
proc addPathRec(dir: string, info: TLineInfo) =
for k,p in os.walkDir(dir):
if k == pcDir and '.' notin p:
addPathRec(p, info)
if not contains(options.searchPaths, p):
liMessage(info, hintPath, p)
lists.PrependStr(options.searchPaths, p)
proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) = proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
var var
theOS: TSystemOS theOS: TSystemOS
@ -286,13 +294,12 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
case whichKeyword(switch) case whichKeyword(switch)
of wPath, wP: of wPath, wP:
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
addPath(processPath(arg)) addPath(processPath(arg), info)
#discard lists.IncludeStr(options.searchPaths, path)
of wRecursivePath: of wRecursivePath:
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
var path = processPath(arg) var path = processPath(arg)
for p in os.walkDirRec(path, {pcDir}): addPath(p) addPathRec(path, info)
addPath(path) addPath(path, info)
of wOut, wO: of wOut, wO:
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
options.outFile = arg options.outFile = arg

View file

@ -1074,6 +1074,10 @@ proc genMagic(p: var TProc, n: PNode, r: var TCompRes) =
of mAnd: genAnd(p, n.sons[1], n.sons[2], r) of mAnd: genAnd(p, n.sons[1], n.sons[2], r)
of mAddi..mStrToStr: arith(p, n, r, op) #mRepr: genRepr(p, n, r); of mAddi..mStrToStr: arith(p, n, r, op) #mRepr: genRepr(p, n, r);
of mSwap: genSwap(p, n, r) of mSwap: genSwap(p, n, r)
of mUnaryLt:
# XXX: range checking?
if not (optOverflowCheck in p.Options): unaryExpr(p, n, r, "", "$1 - 1")
else: unaryExpr(p, n, r, "subInt", "subInt($1, 1)")
of mPred: of mPred:
# XXX: range checking? # XXX: range checking?
if not (optOverflowCheck in p.Options): binaryExpr(p, n, r, "", "$1 - $2") if not (optOverflowCheck in p.Options): binaryExpr(p, n, r, "", "$1 - $2")

View file

@ -1,46 +1,13 @@
# #
# #
# The Nimrod Compiler # The Nimrod Compiler
# (c) Copyright 2010 Andreas Rumpf # (c) Copyright 2011 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.
# #
import #[[[cog import
#from string import replace
#enum = "type\n TMsgKind = (\n"
#msgs = "const\n MsgKindToStr: array [TMsgKind] of string = (\n"
#warns = "const\n WarningsToStr: array [0..%d] of string = (\n"
#hints = "const\n HintsToStr: array [0..%d] of string = (\n"
#w = 0 # counts the warnings
#h = 0 # counts the hints
#
#for elem in eval(open('data/messages.yml').read()):
# for key, val in elem.items():
# enum = enum + ' %s,\n' % key
# v = replace(val, "'", "''")
# if key[0:4] == 'warn':
# msgs = msgs + " '%s [%s]',\n" % (v, key[4:])
# warns = warns + " '%s',\n" % key[4:]
# w = w + 1
# elif key[0:4] == 'hint':
# msgs = msgs + " '%s [%s]',\n" % (v, key[4:])
# hints = hints + " '%s',\n" % key[4:]
# h = h + 1
# else:
# msgs = msgs + " '%s',\n" % v
#
#enum = enum[:-2] + ');\n\n'
#msgs = msgs[:-2] + '\n );\n'
#warns = (warns[:-2] + '\n );\n') % (w-1)
#hints = (hints[:-2] + '\n );\n') % (h-1)
#
#cog.out(enum)
#cog.out(msgs)
#cog.out(warns)
#cog.out(hints)
#]]]
options, strutils, os options, strutils, os
type type
@ -126,7 +93,7 @@ type
warnXisPassedToProcVar, warnUser, hintSuccess, hintSuccessX, warnXisPassedToProcVar, warnUser, hintSuccess, hintSuccessX,
hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded, hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded,
hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled, hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled,
hintProcessing, hintCodeBegin, hintCodeEnd, hintConf, hintUser hintProcessing, hintCodeBegin, hintCodeEnd, hintConf, hintPath, hintUser
const const
MsgKindToStr*: array[TMsgKind, string] = ["unknown error", MsgKindToStr*: array[TMsgKind, string] = ["unknown error",
@ -274,7 +241,9 @@ const
"expression evaluates always to \'$1\' [ExprAlwaysX]", "expression evaluates always to \'$1\' [ExprAlwaysX]",
"quit() called [QuitCalled]", "$1 [Processing]", "quit() called [QuitCalled]", "$1 [Processing]",
"generated code listing: [CodeBegin]", "end of listing [CodeEnd]", "generated code listing: [CodeBegin]", "end of listing [CodeEnd]",
"used config file \'$1\' [Conf]", "$1 [User]"] "used config file \'$1\' [Conf]",
"added path: '$1' [Path]",
"$1 [User]"]
const const
WarningsToStr*: array[0..14, string] = ["CannotOpenFile", "OctalEscape", WarningsToStr*: array[0..14, string] = ["CannotOpenFile", "OctalEscape",
@ -284,10 +253,11 @@ const
"CommentXIgnored", "XisPassedToProcVar", "User"] "CommentXIgnored", "XisPassedToProcVar", "User"]
const const
HintsToStr*: array[0..12, string] = ["Success", "SuccessX", "LineTooLong", HintsToStr*: array[0..13, string] = ["Success", "SuccessX", "LineTooLong",
"XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded", "XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded",
"ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf", "ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
"User"] #[[[end]]] "Path",
"User"]
const const
fatalMin* = errUnknown fatalMin* = errUnknown

View file

@ -95,6 +95,7 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
of mToU8: result = newIntNodeT(getInt(a) and 0x000000FF, n) of mToU8: result = newIntNodeT(getInt(a) and 0x000000FF, n)
of mToU16: result = newIntNodeT(getInt(a) and 0x0000FFFF, n) of mToU16: result = newIntNodeT(getInt(a) and 0x0000FFFF, n)
of mToU32: result = newIntNodeT(getInt(a) and 0x00000000FFFFFFFF'i64, n) of mToU32: result = newIntNodeT(getInt(a) and 0x00000000FFFFFFFF'i64, n)
of mUnaryLt: result = newIntNodeT(getOrdValue(a) - 1, n)
of mSucc: result = newIntNodeT(getOrdValue(a) + getInt(b), n) of mSucc: result = newIntNodeT(getOrdValue(a) + getInt(b), n)
of mPred: result = newIntNodeT(getOrdValue(a) - getInt(b), n) of mPred: result = newIntNodeT(getOrdValue(a) - getInt(b), n)
of mAddI, mAddI64: result = newIntNodeT(getInt(a) + getInt(b), n) of mAddI, mAddI64: result = newIntNodeT(getInt(a) + getInt(b), n)

View file

@ -19,6 +19,7 @@ tcnstseq.nim;AngelikaAnneAnnaAnkaAnja
tconstr2.nim;69 tconstr2.nim;69
tcontinuexc.nim;ECcaught tcontinuexc.nim;ECcaught
tcopy.nim;TEMP=C:\Programs\xyz\bin tcopy.nim;TEMP=C:\Programs\xyz\bin
tcountup.nim;0123456789
tcurrncy.nim;25 tcurrncy.nim;25
temit.nim;509 temit.nim;509
tenumhole;my value A1my value Bconc2valueCabc4abc tenumhole;my value A1my value Bconc2valueCabc4abc

1 tack.nim 125
19 tconstr2.nim 69
20 tcontinuexc.nim ECcaught
21 tcopy.nim TEMP=C:\Programs\xyz\bin
22 tcountup.nim 0123456789
23 tcurrncy.nim 25
24 temit.nim 509
25 tenumhole my value A1my value Bconc2valueCabc4abc

View file

@ -0,0 +1,8 @@
# Test new countup and unary <
for i in 0 .. < 10'i64:
stdout.write(i)
#OUT 0123456789

View file

@ -51,8 +51,9 @@ Additions
``array[TMyEnum, string]`` mapping. ``array[TMyEnum, string]`` mapping.
- Indices in array literals may be explicitly given, enhancing readability: - Indices in array literals may be explicitly given, enhancing readability:
``[enumValueA: "a", enumValueB: "b"]``. ``[enumValueA: "a", enumValueB: "b"]``.
- Added basic thread support via the ``threads`` core module. - Added basic thread support via the ``threads`` core module and
the ``--threads:on`` command line switch.
- Added unary ``<`` for nice looking excluding upper bounds in ranges.
2010-10-20 Version 0.8.10 released 2010-10-20 Version 0.8.10 released