added tools and web dirs

This commit is contained in:
Andreas Rumpf 2009-09-15 23:22:22 +02:00
commit 66a7e3d37c
489 changed files with 4593 additions and 9878 deletions

0
lib/pure/cgi.nim Normal file → Executable file
View file

0
lib/pure/complex.nim Normal file → Executable file
View file

0
lib/pure/dynlib.nim Normal file → Executable file
View file

0
lib/pure/hashes.nim Normal file → Executable file
View file

0
lib/pure/lexbase.nim Normal file → Executable file
View file

104
lib/pure/macros.nim Normal file → Executable file
View file

@ -8,10 +8,10 @@
#
## This module contains the interface to the compiler's abstract syntax
## This module contains the interface to the compiler's abstract syntax
## tree (`AST`:idx:). Macros operate on this tree.
## .. include:: ../doc/astspec.txt
## .. include:: ../doc/astspec.txt
#[[[cog
#def toEnum(name, elems):
@ -39,38 +39,38 @@ type
nnkInt16Lit, nnkInt32Lit, nnkInt64Lit, nnkFloatLit,
nnkFloat32Lit, nnkFloat64Lit, nnkStrLit, nnkRStrLit,
nnkTripleStrLit, nnkMetaNode, nnkNilLit, nnkDotCall,
nnkCommand, nnkCall, nnkGenericCall, nnkExplicitTypeListCall,
nnkExprEqExpr, nnkExprColonExpr, nnkIdentDefs, nnkVarTuple,
nnkInfix, nnkPrefix, nnkPostfix, nnkPar,
nnkCurly, nnkBracket, nnkBracketExpr, nnkPragmaExpr,
nnkRange, nnkDotExpr, nnkCheckedFieldExpr, nnkDerefExpr,
nnkIfExpr, nnkElifExpr, nnkElseExpr, nnkLambda,
nnkAccQuoted, nnkTableConstr, nnkQualified, nnkBind,
nnkSymChoice, nnkHiddenStdConv, nnkHiddenSubConv, nnkHiddenCallConv,
nnkConv, nnkCast, nnkAddr, nnkHiddenAddr,
nnkHiddenDeref, nnkObjDownConv, nnkObjUpConv, nnkChckRangeF,
nnkChckRange64, nnkChckRange, nnkStringToCString, nnkCStringToString,
nnkPassAsOpenArray, nnkAsgn, nnkFastAsgn, nnkDefaultTypeParam,
nnkGenericParams, nnkFormalParams, nnkOfInherit, nnkModule,
nnkProcDef, nnkConverterDef, nnkMacroDef, nnkTemplateDef,
nnkIteratorDef, nnkOfBranch, nnkElifBranch, nnkExceptBranch,
nnkElse, nnkMacroStmt, nnkAsmStmt, nnkPragma,
nnkIfStmt, nnkWhenStmt, nnkForStmt, nnkWhileStmt,
nnkCaseStmt, nnkVarSection, nnkConstSection, nnkConstDef,
nnkTypeSection, nnkTypeDef, nnkYieldStmt, nnkTryStmt,
nnkFinally, nnkRaiseStmt, nnkReturnStmt, nnkBreakStmt,
nnkContinueStmt, nnkBlockStmt, nnkDiscardStmt, nnkStmtList,
nnkImportStmt, nnkFromStmt, nnkImportAs, nnkIncludeStmt,
nnkCommentStmt, nnkStmtListExpr, nnkBlockExpr, nnkStmtListType,
nnkBlockType, nnkVm, nnkTypeOfExpr, nnkObjectTy,
nnkCommand, nnkCall, nnkCallStrLit, nnkExprEqExpr,
nnkExprColonExpr, nnkIdentDefs, nnkVarTuple, nnkInfix,
nnkPrefix, nnkPostfix, nnkPar, nnkCurly,
nnkBracket, nnkBracketExpr, nnkPragmaExpr, nnkRange,
nnkDotExpr, nnkCheckedFieldExpr, nnkDerefExpr, nnkIfExpr,
nnkElifExpr, nnkElseExpr, nnkLambda, nnkAccQuoted,
nnkTableConstr, nnkQualified, nnkBind, nnkSymChoice,
nnkHiddenStdConv, nnkHiddenSubConv, nnkHiddenCallConv, nnkConv,
nnkCast, nnkAddr, nnkHiddenAddr, nnkHiddenDeref,
nnkObjDownConv, nnkObjUpConv, nnkChckRangeF, nnkChckRange64,
nnkChckRange, nnkStringToCString, nnkCStringToString, nnkPassAsOpenArray,
nnkAsgn, nnkFastAsgn, nnkGenericParams, nnkFormalParams,
nnkOfInherit, nnkModule, nnkProcDef, nnkConverterDef,
nnkMacroDef, nnkTemplateDef, nnkIteratorDef, nnkOfBranch,
nnkElifBranch, nnkExceptBranch, nnkElse, nnkMacroStmt,
nnkAsmStmt, nnkPragma, nnkIfStmt, nnkWhenStmt,
nnkForStmt, nnkWhileStmt, nnkCaseStmt, nnkVarSection,
nnkConstSection, nnkConstDef, nnkTypeSection, nnkTypeDef,
nnkYieldStmt, nnkTryStmt, nnkFinally, nnkRaiseStmt,
nnkReturnStmt, nnkBreakStmt, nnkContinueStmt, nnkBlockStmt,
nnkDiscardStmt, nnkStmtList, nnkImportStmt, nnkFromStmt,
nnkIncludeStmt, nnkCommentStmt, nnkStmtListExpr, nnkBlockExpr,
nnkStmtListType, nnkBlockType, nnkTypeOfExpr, nnkObjectTy,
nnkTupleTy, nnkRecList, nnkRecCase, nnkRecWhen,
nnkRefTy, nnkPtrTy, nnkVarTy, nnkAbstractTy,
nnkRefTy, nnkPtrTy, nnkVarTy, nnkDistinctTy,
nnkProcTy, nnkEnumTy, nnkEnumFieldDef, nnkReturnToken
TNimNodeKinds* = set[TNimrodNodeKind]
TNimrodTypeKind* = enum
ntyNone, ntyBool, ntyChar, ntyEmpty,
ntyArrayConstr, ntyNil, ntyGeneric, ntyGenericInst,
ntyGenericParam, ntyAbstract, ntyEnum, ntyOrdinal,
ntyArrayConstr, ntyNil, ntyExpr, ntyStmt,
ntyTypeDesc, ntyGenericInvokation, ntyGenericBody, ntyGenericInst,
ntyGenericParam, ntyDistinct, ntyEnum, ntyOrdinal,
ntyArray, ntyObject, ntyTuple, ntySet,
ntyRange, ntyPtr, ntyRef, ntyVar,
ntySequence, ntyProc, ntyPointer, ntyOpenArray,
@ -79,8 +79,8 @@ type
ntyFloat, ntyFloat32, ntyFloat64, ntyFloat128
TNimTypeKinds* = set[TNimrodTypeKind]
TNimrodSymKind* = enum
nskUnknownSym, nskConditional, nskDynLib, nskParam,
nskTypeParam, nskTemp, nskType, nskConst,
nskUnknown, nskConditional, nskDynLib, nskParam,
nskGenericParam, nskTemp, nskType, nskConst,
nskVar, nskProc, nskIterator, nskConverter,
nskMacro, nskTemplate, nskField, nskEnumField,
nskForVar, nskModule, nskLabel, nskStub
@ -91,7 +91,6 @@ type
TNimrodIdent = object of TObject
## represents a Nimrod identifier in the AST
TNimrodNode {.final.} = object # hidden
TNimrodSymbol {.final.} = object # hidden
TNimrodType {.final.} = object # hidden
@ -103,12 +102,9 @@ type
## represents a Nimrod *symbol* in the compiler; a *symbol* is a looked-up
## *ident*.
PNimrodNode* {.compilerproc.} = ref TNimrodNode
PNimrodNode* = expr
## represents a Nimrod AST node. Macros operate on this type.
expr* = PNimrodNode
stmt* = PNimrodNode
# Nodes should be reference counted to make the `copy` operation very fast!
# However, this is difficult to achieve: modify(n[0][1]) should propagate to
# its father. How to do this without back references?
@ -119,7 +115,7 @@ proc `[]`* (n: PNimrodNode, i: int): PNimrodNode {.magic: "NChild".}
proc `[]=`* (n: PNimrodNode, i: int, child: PNimrodNode) {.magic: "NSetChild".}
## set `n`'s `i`'th child to `child`.
proc `!` *(s: string): TNimrodIdent {.magic: "StrToIdent".}
proc `!` *(s: string): TNimrodIdent {.magic: "StrToIdent".}
## constructs an identifier from the string `s`
proc `$`*(i: TNimrodIdent): string {.magic: "IdentToStr".}
@ -159,8 +155,8 @@ proc `typ=`*(n: PNimrodNode, typ: PNimrodType) {.magic: "NSetType".}
proc `strVal=`*(n: PNimrodNode, val: string) {.magic: "NSetStrVal".}
proc newNimNode*(kind: TNimrodNodeKind,
n: PNimrodNode=nil): PNimrodNode {.magic: "NNewNimNode".}
n: PNimrodNode=nil): PNimrodNode {.magic: "NNewNimNode".}
proc copyNimNode*(n: PNimrodNode): PNimrodNode {.magic: "NCopyNimNode".}
proc copyNimTree*(n: PNimrodNode): PNimrodNode {.magic: "NCopyNimTree".}
@ -192,11 +188,11 @@ proc newIdentNode*(i: TNimrodIdent): PNimrodNode {.compileTime.} =
## creates an identifier node from `i`
result = newNimNode(nnkIdent)
result.ident = i
proc newIdentNode*(i: string): PNimrodNode {.compileTime.} =
## creates an identifier node from `i`
result = newNimNode(nnkIdent)
result.ident = !i
result.ident = !i
proc toStrLit*(n: PNimrodNode): PNimrodNode {.compileTime.} =
## converts the AST `n` to the concrete Nimrod code and wraps that
@ -227,7 +223,7 @@ proc newCall*(theProc: TNimrodIdent,
## the arguments ``args[0..]``.
result = newNimNode(nnkCall)
result.add(newIdentNode(theProc))
result.add(args)
result.add(args)
proc newCall*(theProc: string,
args: openArray[PNimrodNode]): PNimrodNode {.compileTime.} =
@ -236,14 +232,14 @@ proc newCall*(theProc: string,
result = newNimNode(nnkCall)
result.add(newIdentNode(theProc))
result.add(args)
proc nestList*(theProc: TNimrodIdent,
x: PNimrodNode): PNimrodNode {.compileTime.} =
## nests the list `x` into a tree of call expressions:
## ``[a, b, c]`` is transformed into ``theProc(a, theProc(c, d))``
var L = x.len
result = newCall(theProc, x[L-2], x[L-1])
var a = result
for i in countdown(L-3, 0):
a = newCall(theProc, x[i], copyNimTree(a))
proc nestList*(theProc: TNimrodIdent,
x: PNimrodNode): PNimrodNode {.compileTime.} =
## nests the list `x` into a tree of call expressions:
## ``[a, b, c]`` is transformed into ``theProc(a, theProc(c, d))``
var L = x.len
result = newCall(theProc, x[L-2], x[L-1])
var a = result
for i in countdown(L-3, 0):
a = newCall(theProc, x[i], copyNimTree(a))

10
lib/pure/math.nim Normal file → Executable file
View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2008 Andreas Rumpf
# (c) Copyright 2009 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -83,10 +83,12 @@ proc nextPowerOfTwo*(x: int): int =
result = result or (result shr 1)
Inc(result)
proc countBits*(n: int32): int {.noSideEffect.}
proc countBits32*(n: int32): int {.noSideEffect.} =
## counts the set bits in `n`.
include "system/cntbits"
var v = n
v = v -% ((v shr 1'i32) and 0x55555555'i32)
v = (v and 0x33333333'i32) +% ((v shr 2'i32) and 0x33333333'i32)
result = ((v +% (v shr 4'i32) and 0xF0F0F0F'i32) *% 0x1010101'i32) shr 24'i32
proc sum*[T](x: openarray[T]): T {.noSideEffect.} =
## computes the sum of the elements in `x`.

0
lib/pure/md5.nim Normal file → Executable file
View file

16
lib/pure/os.nim Normal file → Executable file
View file

@ -58,10 +58,6 @@ when defined(Nimdoc): # only for proper documentation:
## The character used by the operating system to separate pathname
## components, for example, '/' for POSIX or ':' for the classic
## Macintosh.
##
## Note that knowing this is not sufficient to be able to parse or
## concatenate pathnames -- use `splitPath` and `joinPath` instead --
## but it is occasionally useful.
AltSep* = '/'
## An alternative character used by the operating system to separate
@ -80,10 +76,10 @@ when defined(Nimdoc): # only for proper documentation:
ExeExt* = ""
## The file extension of native executables. For example:
## "" on UNIX, "exe" on Windows.
## "" for POSIX, "exe" on Windows.
ScriptExt* = ""
## The file extension of a script file. For example: "" on UNIX,
## The file extension of a script file. For example: "" for POSIX,
## "bat" on Windows.
elif defined(macos):
@ -111,7 +107,7 @@ elif defined(macos):
# In full paths the first name (e g HD above) is the name of a mounted
# volume.
# These names are not unique, because, for instance, two diskettes with the
# same names could be inserted. This means that paths on MacOS is not
# same names could be inserted. This means that paths on MacOS are not
# waterproof. In case of equal names the first volume found will do.
# Two colons "::" are the relative path to the parent. Three is to the
# grandparent etc.
@ -551,7 +547,7 @@ proc sameFile*(path1, path2: string): bool =
proc sameFileContent*(path1, path2: string): bool =
## Returns True if both pathname arguments refer to files with identical
## content. Content is compared byte for byte.
## binary content.
const
bufSize = 8192 # 8K buffer
var
@ -712,7 +708,7 @@ proc putEnv*(key, val: string) =
OSError()
iterator iterOverEnvironment*(): tuple[key, value: string] =
## Iterate over all environments varialbes. In the first component of the
## Iterate over all environments variables. In the first component of the
## tuple is the name of the current variable stored, in the second its value.
getEnvVarsC()
for i in 0..high(environment):
@ -760,7 +756,7 @@ iterator walkDir*(dir: string): tuple[kind: TPathComponent, path: string] =
## walks over the directory `dir` and yields for each directory or file in
## `dir`. The component type and full path for each item is returned.
## Walking is not recursive.
## Example: Assuming this directory structure::
## Example: This directory structure::
## dirA / dirB / fileB1.txt
## / dirC
## / fileA1.txt

0
lib/pure/osproc.nim Normal file → Executable file
View file

0
lib/pure/parsecfg.nim Normal file → Executable file
View file

0
lib/pure/parsecsv.nim Normal file → Executable file
View file

0
lib/pure/parseopt.nim Normal file → Executable file
View file

1
lib/pure/parsesql.nim Normal file → Executable file
View file

@ -571,6 +571,7 @@ proc getTok(p: var TSqlParser) =
proc sqlError(p: TSqlParser, msg: string) =
var e: ref EInvalidSql
new(e)
e.msg = errorStr(p, msg)
raise e

0
lib/pure/parsexml.nim Normal file → Executable file
View file

2
lib/pure/regexprs.nim Normal file → Executable file
View file

@ -54,10 +54,10 @@ proc find*(s, pattern: string, matches: var openarray[string],
## returns ``true`` if ``pattern`` occurs in ``s`` and the captured
## substrings in the array ``matches``. If it does not match, nothing
## is written into ``matches``.
proc find*(s, pattern: string, start: int = 0): bool
## returns ``true`` if ``pattern`` occurs in ``s``.
proc rawCompile(pattern: string, flags: cint): PPcre =
var
msg: CString

4
lib/pure/streams.nim Normal file → Executable file
View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2008 Andreas Rumpf
# (c) Copyright 2009 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -42,7 +42,7 @@ proc write*(s: PStream, x: string) =
s.writeData(s, cstring(x), x.len)
proc read[T](s: PStream, result: var T) =
## generic write procedure. Reads `result` from the stream `s`.
## generic read procedure. Reads `result` from the stream `s`.
if s.readData(s, addr(result), sizeof(T)) != sizeof(T):
raise newEIO("cannot read from stream")

0
lib/pure/strtabs.nim Normal file → Executable file
View file

73
lib/pure/strutils.nim Normal file → Executable file
View file

@ -27,7 +27,7 @@ template newException(exceptn, message: expr): expr =
type
TCharSet* = set[char] # for compability for Nim
TCharSet* = set[char] # for compability with Nim
const
Whitespace* = {' ', '\t', '\v', '\r', '\l', '\f'}
@ -45,9 +45,9 @@ const
IdentStartChars* = {'a'..'z', 'A'..'Z', '_'}
## the set of characters an identifier can start with
strStart* = 0 # this is only for bootstraping
# XXX: remove this someday
nl* = "\n" # this is only for bootstraping XXX: remove this somehow
strStart* = 0 ## this is only for bootstraping
## XXX: remove this someday
nl* = "\n" ## this is only for bootstraping XXX: remove this somehow
proc `%` *(formatstr: string, a: openarray[string]): string {.noSideEffect.}
## The `substitution`:idx: operator performs string substitutions in
@ -64,8 +64,13 @@ proc `%` *(formatstr: string, a: openarray[string]): string {.noSideEffect.}
## .. code-block:: nimrod
## "The cat eats fish."
##
## The substitution variables (the thing after the ``$``)
## are enumerated from 1 to 9.
## The substitution variables (the thing after the ``$``) are enumerated
## from 1 to ``a.len``.
## The notation ``$#`` can be used to refer to the next substitution variable:
##
## .. code-block:: nimrod
## "$# eats $#." % ["The cat", "fish"]
##
## Substitution variables can also be words (that is
## ``[A-Za-z_]+[A-Za-z0-9_]*``) in which case the arguments in `a` with even
## indices are keys and with odd indices are the corresponding values.
@ -267,19 +272,43 @@ iterator splitLines*(s: string): string =
else: break # was '\0'
first = last
proc splitLinesSeq*(s: string): seq[string] {.noSideEffect.} =
## The same as `split`, but is a proc that returns a sequence of substrings.
template iterToProc(iter: expr): stmt =
result = @[]
for line in splitLines(s): add(result, line)
for x in iter: add(result, x)
proc splitLinesSeq*(s: string): seq[string] {.noSideEffect, deprecated.} =
## The same as `splitLines`, but is a proc that returns a sequence
## of substrings.
## **Deprecated since version 0.8.0**: Use `splitLines` instead.
iterToProc(splitLines(s))
proc splitSeq*(s: string, seps: set[char] = Whitespace): seq[string] {.
noSideEffect.}
noSideEffect, deprecated.} =
## The same as `split`, but is a proc that returns a sequence of substrings.
## **Deprecated since version 0.8.0**: Use `split` instead.
iterToProc(split(s, seps))
proc splitSeq*(s: string, sep: char): seq[string] {.noSideEffect.} =
proc splitSeq*(s: string, sep: char): seq[string] {.noSideEffect,
deprecated.} =
## The same as `split`, but is a proc that returns a sequence of substrings.
result = @[]
for sub in split(s, sep): add(result, sub)
## **Deprecated since version 0.8.0**: Use `split` instead.
iterToProc(split(s, sep))
proc splitLines*(s: string): seq[string] {.noSideEffect.} =
## The same as the `splitLines` iterator, but is a proc that returns a
## sequence of substrings.
iterToProc(splitLines(s))
proc split*(s: string, seps: set[char] = Whitespace): seq[string] {.
noSideEffect.} =
## The same as the `split` iterator, but is a proc that returns a
## sequence of substrings.
iterToProc(split(s, seps))
proc split*(s: string, sep: char): seq[string] {.noSideEffect.} =
## The same as the `split` iterator, but is a proc that returns a sequence
## of substrings.
iterToProc(split(s, sep))
proc cmpIgnoreCase*(a, b: string): int {.noSideEffect.}
## Compares two strings in a case insensitive manner. Returns:
@ -308,7 +337,7 @@ proc contains*(s: string, chars: set[char]): bool {.noSideEffect.}
proc toHex*(x: BiggestInt, len: int): string {.noSideEffect.}
## Converts `x` to its hexadecimal representation. The resulting string
## will be exactly `len` characters long. No prefix like ``0x``
## is generated. `x` is treated as unsigned value.
## is generated. `x` is treated as an unsigned value.
proc intToStr*(x: int, minchars: int = 1): string
## Converts `x` to its decimal representation. The resulting string
@ -367,7 +396,7 @@ proc addSep*(dest: var string, sep = ", ", startLen = 0) {.noSideEffect,
proc allCharsInSet*(s: string, theSet: TCharSet): bool =
## returns true iff each character of `s` is in the set `theSet`.
for c in items(s):
if not (c in theSet): return false
if c notin theSet: return false
return true
proc quoteIfContainsWhite*(s: string): string =
@ -397,12 +426,12 @@ proc endsWith(s, suffix: string): bool =
when false:
proc abbrev(s: string, possibilities: openarray[string]): int =
## returns the index of the first item in `possibilities` if not
## ambigious; -1 if no item has been found; -2 if multiple items
## ambiguous; -1 if no item has been found; -2 if multiple items
## match.
result = -1 # none found
for i in 0..possibilities.len-1:
if possibilities[i].startsWith(s):
if result >= 0: return -2 # ambigious
if result >= 0: return -2 # ambiguous
result = i
proc repeatChar(count: int, c: Char = ' '): string =
@ -509,12 +538,6 @@ proc cmpIgnoreStyle(a, b: string): int =
{.pop.}
# ---------- splitting -----------------------------------------------------
proc splitSeq(s: string, seps: set[char]): seq[string] =
result = @[]
for sub in split(s, seps): add result, sub
# ---------------------------------------------------------------------------
proc join*(a: openArray[string], sep: string): string =
@ -732,7 +755,7 @@ proc rawParseInt(s: string, index: var int): BiggestInt =
# one more valid negative than prositive integer. Thus we perform the
# computation as a negative number and then change the sign at the end.
var
i: int = index # a local i is more efficient than accessing a var parameter
i = index # a local i is more efficient than accessing a var parameter
sign: BiggestInt = -1
if s[i] == '+':
inc(i)
@ -758,7 +781,7 @@ proc rawParseInt(s: string, index: var int): BiggestInt =
proc parseInt(s: string): int =
var
index: int = 0
index = 0
res = rawParseInt(s, index)
if index == -1:
raise newException(EInvalidValue, "invalid integer: " & s)

0
lib/pure/terminal.nim Normal file → Executable file
View file

6
lib/pure/times.nim Normal file → Executable file
View file

@ -25,13 +25,13 @@ type
when defined(posix):
type
TTime* = abstract int ## abstract type that represents a time
TTime* = distinct int ## distinct type that represents a time
elif defined(windows):
when defined(vcc):
# newest version of Visual C++ defines time_t to be of 64 bits
type TTime* = abstract int64
type TTime* = distinct int64
else:
type TTime* = abstract int32
type TTime* = distinct int32
elif defined(ECMAScript):
type
TTime* {.final.} = object

0
lib/pure/unicode.nim Normal file → Executable file
View file

0
lib/pure/xmlgen.nim Normal file → Executable file
View file