added tools and web dirs
This commit is contained in:
parent
300430fbba
commit
66a7e3d37c
489 changed files with 4593 additions and 9878 deletions
0
lib/copying.txt
Normal file → Executable file
0
lib/copying.txt
Normal file → Executable file
0
lib/cycle.h
Normal file → Executable file
0
lib/cycle.h
Normal file → Executable file
0
lib/ecmas/dom.nim
Normal file → Executable file
0
lib/ecmas/dom.nim
Normal file → Executable file
0
lib/impure/dialogs.nim
Normal file → Executable file
0
lib/impure/dialogs.nim
Normal file → Executable file
0
lib/impure/web.nim
Normal file → Executable file
0
lib/impure/web.nim
Normal file → Executable file
0
lib/impure/zipfiles.nim
Normal file → Executable file
0
lib/impure/zipfiles.nim
Normal file → Executable file
0
lib/lgpl.txt
Normal file → Executable file
0
lib/lgpl.txt
Normal file → Executable file
0
lib/nimbase.h
Normal file → Executable file
0
lib/nimbase.h
Normal file → Executable file
0
lib/posix/posix.nim
Normal file → Executable file
0
lib/posix/posix.nim
Normal file → Executable file
0
lib/pure/cgi.nim
Normal file → Executable file
0
lib/pure/cgi.nim
Normal file → Executable file
0
lib/pure/complex.nim
Normal file → Executable file
0
lib/pure/complex.nim
Normal file → Executable file
0
lib/pure/dynlib.nim
Normal file → Executable file
0
lib/pure/dynlib.nim
Normal file → Executable file
0
lib/pure/hashes.nim
Normal file → Executable file
0
lib/pure/hashes.nim
Normal file → Executable file
0
lib/pure/lexbase.nim
Normal file → Executable file
0
lib/pure/lexbase.nim
Normal file → Executable file
104
lib/pure/macros.nim
Normal file → Executable file
104
lib/pure/macros.nim
Normal file → Executable 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
10
lib/pure/math.nim
Normal file → Executable 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
0
lib/pure/md5.nim
Normal file → Executable file
16
lib/pure/os.nim
Normal file → Executable file
16
lib/pure/os.nim
Normal file → Executable 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
0
lib/pure/osproc.nim
Normal file → Executable file
0
lib/pure/parsecfg.nim
Normal file → Executable file
0
lib/pure/parsecfg.nim
Normal file → Executable file
0
lib/pure/parsecsv.nim
Normal file → Executable file
0
lib/pure/parsecsv.nim
Normal file → Executable file
0
lib/pure/parseopt.nim
Normal file → Executable file
0
lib/pure/parseopt.nim
Normal file → Executable file
1
lib/pure/parsesql.nim
Normal file → Executable file
1
lib/pure/parsesql.nim
Normal file → Executable 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
0
lib/pure/parsexml.nim
Normal file → Executable file
2
lib/pure/regexprs.nim
Normal file → Executable file
2
lib/pure/regexprs.nim
Normal file → Executable 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
4
lib/pure/streams.nim
Normal file → Executable 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
0
lib/pure/strtabs.nim
Normal file → Executable file
73
lib/pure/strutils.nim
Normal file → Executable file
73
lib/pure/strutils.nim
Normal file → Executable 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
0
lib/pure/terminal.nim
Normal file → Executable file
6
lib/pure/times.nim
Normal file → Executable file
6
lib/pure/times.nim
Normal file → Executable 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
0
lib/pure/unicode.nim
Normal file → Executable file
0
lib/pure/xmlgen.nim
Normal file → Executable file
0
lib/pure/xmlgen.nim
Normal file → Executable file
93
lib/system.nim
Normal file → Executable file
93
lib/system.nim
Normal file → Executable file
|
|
@ -42,8 +42,12 @@ type
|
|||
|
||||
type
|
||||
`nil` {.magic: "Nil".}
|
||||
expr* {.magic: Expr.} ## meta type to denote an expression (for templates)
|
||||
stmt* {.magic: Stmt.} ## meta type to denote a statement (for templates)
|
||||
typeDesc* {.magic: TypeDesc.} ## meta type to denote
|
||||
## a type description (for templates)
|
||||
|
||||
proc defined*[T] (x: T): bool {.magic: "Defined", noSideEffect.}
|
||||
proc defined*[T](x: T): bool {.magic: "Defined", noSideEffect.}
|
||||
## Special comile-time procedure that checks whether `x` is
|
||||
## defined. `x` has to be an identifier or a qualified identifier.
|
||||
## This can be used to check whether a library provides a certain
|
||||
|
|
@ -54,6 +58,12 @@ proc defined*[T] (x: T): bool {.magic: "Defined", noSideEffect.}
|
|||
## # provide our own toUpper proc here, because strutils is
|
||||
## # missing it.
|
||||
|
||||
proc definedInScope*[T](x: T, scope=0): bool {.
|
||||
magic: "DefinedInScope", noSideEffect.}
|
||||
## Special comile-time procedure that checks whether `x` is
|
||||
## defined in the scope `scope`. `x` has to be an identifier.
|
||||
## 0 means the current scope, 1 means the scope above the current scope, etc.
|
||||
|
||||
# these require compiler magic:
|
||||
proc `not` *(x: bool): bool {.magic: "Not", noSideEffect.}
|
||||
## Boolean not; returns true iff ``x == false``.
|
||||
|
|
@ -434,30 +444,6 @@ proc abs*(x: int64): int64 {.magic: "AbsI64", noSideEffect.}
|
|||
## is -MININT for its type), an overflow exception is thrown (if overflow
|
||||
## checking is turned on).
|
||||
|
||||
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.}
|
||||
proc min*(x, y: int8): int8 {.magic: "MinI", noSideEffect.}
|
||||
proc min*(x, y: int16): int16 {.magic: "MinI", noSideEffect.}
|
||||
proc min*(x, y: int32): int32 {.magic: "MinI", noSideEffect.}
|
||||
proc min*(x, y: int64): int64 {.magic: "MinI64", noSideEffect.}
|
||||
## The minimum value of two integers.
|
||||
|
||||
proc min*[T](x: openarray[T]): T =
|
||||
## The minimum value of an openarray.
|
||||
result = x[0]
|
||||
for i in 1..high(x): result = min(result, x[i])
|
||||
|
||||
proc max*(x, y: int): int {.magic: "MaxI", noSideEffect.}
|
||||
proc max*(x, y: int8): int8 {.magic: "MaxI", noSideEffect.}
|
||||
proc max*(x, y: int16): int16 {.magic: "MaxI", noSideEffect.}
|
||||
proc max*(x, y: int32): int32 {.magic: "MaxI", noSideEffect.}
|
||||
proc max*(x, y: int64): int64 {.magic: "MaxI64", noSideEffect.}
|
||||
## The maximum value of two integers.
|
||||
|
||||
proc max*[T](x: openarray[T]): T =
|
||||
## The maximum value of an openarray.
|
||||
result = x[0]
|
||||
for i in 1..high(x): result = max(result, x[i])
|
||||
|
||||
proc `+%` *(x, y: int): int {.magic: "AddU", noSideEffect.}
|
||||
proc `+%` *(x, y: int8): int8 {.magic: "AddU", noSideEffect.}
|
||||
proc `+%` *(x, y: int16): int16 {.magic: "AddU", noSideEffect.}
|
||||
|
|
@ -613,7 +599,7 @@ template `not_in` * (x, y: expr): expr = not contains(y, x)
|
|||
proc `is` *[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.}
|
||||
template `is_not` *(x, y: expr): expr = not (x is y)
|
||||
|
||||
proc cmp*[T](x, y: T): int =
|
||||
proc cmp*[T, S: typeDesc](x: T, y: S): int =
|
||||
## Generic compare proc. Returns a value < 0 iff x < y, a value > 0 iff x > y
|
||||
## and 0 iff x == y. This is useful for writing generic algorithms without
|
||||
## performance loss. This generic implementation uses the `==` and `<`
|
||||
|
|
@ -999,6 +985,32 @@ iterator countup*[T](a, b: T, step = 1): T {.inline.} =
|
|||
# we cannot use ``for x in a..b: `` here, because that is not
|
||||
# known in the System module
|
||||
|
||||
|
||||
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.}
|
||||
proc min*(x, y: int8): int8 {.magic: "MinI", noSideEffect.}
|
||||
proc min*(x, y: int16): int16 {.magic: "MinI", noSideEffect.}
|
||||
proc min*(x, y: int32): int32 {.magic: "MinI", noSideEffect.}
|
||||
proc min*(x, y: int64): int64 {.magic: "MinI64", noSideEffect.}
|
||||
## The minimum value of two integers.
|
||||
|
||||
proc min*[T](x: openarray[T]): T =
|
||||
## The minimum value of an openarray.
|
||||
result = x[0]
|
||||
for i in 1..high(x): result = min(result, x[i])
|
||||
|
||||
proc max*(x, y: int): int {.magic: "MaxI", noSideEffect.}
|
||||
proc max*(x, y: int8): int8 {.magic: "MaxI", noSideEffect.}
|
||||
proc max*(x, y: int16): int16 {.magic: "MaxI", noSideEffect.}
|
||||
proc max*(x, y: int32): int32 {.magic: "MaxI", noSideEffect.}
|
||||
proc max*(x, y: int64): int64 {.magic: "MaxI64", noSideEffect.}
|
||||
## The maximum value of two integers.
|
||||
|
||||
proc max*[T](x: openarray[T]): T =
|
||||
## The maximum value of an openarray.
|
||||
result = x[0]
|
||||
for i in 1..high(x): result = max(result, x[i])
|
||||
|
||||
|
||||
iterator items*[T](a: openarray[T]): T {.inline.} =
|
||||
## iterates over each item of `a`.
|
||||
var i = 0
|
||||
|
|
@ -1009,9 +1021,11 @@ iterator items*[T](a: openarray[T]): T {.inline.} =
|
|||
iterator items*[IX, T](a: array[IX, T]): T {.inline.} =
|
||||
## iterates over each item of `a`.
|
||||
var i = low(IX)
|
||||
while i <= high(IX):
|
||||
yield a[i]
|
||||
inc(i)
|
||||
if i <= high(IX):
|
||||
while true:
|
||||
yield a[i]
|
||||
if i >= high(IX): break
|
||||
inc(i)
|
||||
|
||||
iterator items*[T](a: seq[T]): T {.inline.} =
|
||||
## iterates over each item of `a`.
|
||||
|
|
@ -1032,9 +1046,11 @@ iterator items*[T](a: set[T]): T {.inline.} =
|
|||
## elements that are really in the set (and not over the ones the set is
|
||||
## able to hold).
|
||||
var i = low(T)
|
||||
while i <= high(T):
|
||||
if i in a: yield i
|
||||
inc(i)
|
||||
if i <= high(T):
|
||||
while true:
|
||||
if i in a: yield i
|
||||
if i >= high(T): break
|
||||
inc(i)
|
||||
|
||||
iterator items*(a: cstring): char {.inline.} =
|
||||
## iterates over each item of `a`.
|
||||
|
|
@ -1082,14 +1098,13 @@ proc `&` *[T](x, y: T): seq[T] {.noSideEffect.} =
|
|||
|
||||
when not defined(NimrodVM):
|
||||
when not defined(ECMAScript):
|
||||
# XXX make this local procs
|
||||
proc seqToPtr*[T](x: seq[T]): pointer {.inline, nosideeffect.} =
|
||||
proc seqToPtr[T](x: seq[T]): pointer {.inline, nosideeffect.} =
|
||||
result = cast[pointer](x)
|
||||
else:
|
||||
proc seqToPtr*[T](x: seq[T]): pointer {.pure, nosideeffect.} =
|
||||
proc seqToPtr[T](x: seq[T]): pointer {.pure, nosideeffect.} =
|
||||
asm """return `x`"""
|
||||
|
||||
proc `==` *[T](x, y: seq[T]): bool {.noSideEffect.} =
|
||||
proc `==` *[T: typeDesc](x, y: seq[T]): bool {.noSideEffect.} =
|
||||
## Generic equals operator for sequences: relies on a equals operator for
|
||||
## the element type `T`.
|
||||
if seqToPtr(x) == seqToPtr(y):
|
||||
|
|
@ -1101,10 +1116,9 @@ when not defined(NimrodVM):
|
|||
if x[i] != y[i]: return false
|
||||
result = true
|
||||
|
||||
proc find*[T, S](a: T, item: S): int {.inline.} =
|
||||
proc find*[T, S: typeDesc](a: T, item: S): int {.inline.}=
|
||||
## Returns the first index of `item` in `a` or -1 if not found. This requires
|
||||
## appropriate `==` and `items` procs to work.
|
||||
result = 0
|
||||
## appropriate `items` and `==` procs to work.
|
||||
for i in items(a):
|
||||
if i == item: return
|
||||
inc(result)
|
||||
|
|
@ -1437,6 +1451,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
|||
include "system/arithm"
|
||||
{.pop.} # stack trace
|
||||
include "system/dyncalls"
|
||||
include "system/sets"
|
||||
|
||||
const
|
||||
GenericSeqSize = (2 * sizeof(int))
|
||||
|
|
|
|||
0
lib/system/alloc.nim
Normal file → Executable file
0
lib/system/alloc.nim
Normal file → Executable file
0
lib/system/ansi_c.nim
Normal file → Executable file
0
lib/system/ansi_c.nim
Normal file → Executable file
0
lib/system/arithm.nim
Normal file → Executable file
0
lib/system/arithm.nim
Normal file → Executable file
2
lib/system/assign.nim
Normal file → Executable file
2
lib/system/assign.nim
Normal file → Executable file
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2006 Andreas Rumpf
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
|
|
|
|||
0
lib/system/cellsets.nim
Normal file → Executable file
0
lib/system/cellsets.nim
Normal file → Executable file
10
lib/system/cntbits.nim
Normal file → Executable file
10
lib/system/cntbits.nim
Normal file → Executable file
|
|
@ -8,13 +8,5 @@
|
|||
#
|
||||
|
||||
|
||||
proc population16(a: int): int {.inline.} =
|
||||
var x = a
|
||||
x = ((x and 0xAAAA) shr 1) + (x and 0x5555)
|
||||
x = ((x and 0xCCCC) shr 2) + (x and 0x3333)
|
||||
x = ((x and 0xF0F0) shr 4) + (x and 0x0F0F)
|
||||
x = ((x and 0xFF00) shr 8) + (x and 0x00FF)
|
||||
return x
|
||||
|
||||
proc countBits(n: int32): int =
|
||||
result = population16(n and 0xffff'i32) + population16(n shr 16'i32)
|
||||
|
||||
|
|
|
|||
6
lib/system/debugger.nim
Normal file → Executable file
6
lib/system/debugger.nim
Normal file → Executable 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.
|
||||
|
|
@ -11,9 +11,9 @@
|
|||
# with the application. We should not use dynamic memory here as that
|
||||
# would interfere with the GC and trigger ON/OFF errors if the
|
||||
# user program corrupts memory. Unfortunately, for dispaying
|
||||
# variables we use the system.repr() proc which uses Nimrod
|
||||
# variables we use the ``system.repr()`` proc which uses Nimrod
|
||||
# strings and thus allocates memory from the heap. Pity, but
|
||||
# I do not want to implement repr() twice. We also cannot deactivate
|
||||
# I do not want to implement ``repr()`` twice. We also cannot deactivate
|
||||
# the GC here as that might run out of memory too quickly...
|
||||
|
||||
type
|
||||
|
|
|
|||
0
lib/system/dyncalls.nim
Normal file → Executable file
0
lib/system/dyncalls.nim
Normal file → Executable file
0
lib/system/ecmasys.nim
Normal file → Executable file
0
lib/system/ecmasys.nim
Normal file → Executable file
0
lib/system/excpt.nim
Normal file → Executable file
0
lib/system/excpt.nim
Normal file → Executable file
6
lib/system/gc.nim
Normal file → Executable file
6
lib/system/gc.nim
Normal file → Executable file
|
|
@ -468,10 +468,10 @@ proc collectCycles(gch: var TGcHeap) =
|
|||
Init(gch.cycleRoots)
|
||||
|
||||
proc gcMark(p: pointer) {.inline.} =
|
||||
# the addresses are not as objects on the stack, so turn them to objects:
|
||||
# the addresses are not as cells on the stack, so turn them to cells:
|
||||
var cell = usrToCell(p)
|
||||
var c = cast[TAddress](cell)
|
||||
if c >% PageSize:
|
||||
if c >% PageSize and (c and (MemAlign-1)) == 0:
|
||||
# fast check: does it look like a cell?
|
||||
if isAllocatedPtr(allocator, cell):
|
||||
# mark the cell:
|
||||
|
|
@ -585,7 +585,7 @@ proc CollectZCT(gch: var TGcHeap) =
|
|||
# it has not been removed yet from the ZCT. This is because
|
||||
# ``incref`` does not bother to remove the cell from the ZCT
|
||||
# as this might be too slow.
|
||||
# In any case, it should be removed from the ZCT. But not
|
||||
# In any case, it should be removed from the ZCT. But not
|
||||
# freed. **KEEP THIS IN MIND WHEN MAKING THIS INCREMENTAL!**
|
||||
if canBeCycleRoot(c): excl(gch.cycleRoots, c)
|
||||
when logGC: writeCell("zct dealloc cell", c)
|
||||
|
|
|
|||
51
lib/system/hti.nim
Normal file → Executable file
51
lib/system/hti.nim
Normal file → Executable file
|
|
@ -8,38 +8,31 @@
|
|||
#
|
||||
|
||||
type # This should be he same as ast.TTypeKind
|
||||
# some enum fields are not used at runtime
|
||||
# many enum fields are not used at runtime
|
||||
TNimKind = enum
|
||||
tyNone, # 0
|
||||
tyBool, # 1
|
||||
tyChar, # 2
|
||||
tyEmpty, # 3
|
||||
tyArrayConstr, # 4
|
||||
tyNil, # 5
|
||||
tyGeneric, # 6
|
||||
tyGenericInst, # 7
|
||||
tyGenericParam, # 8
|
||||
tyAbstract, # 9
|
||||
tyEnum, # 10
|
||||
tyOrdinal, # 11
|
||||
tyArray, # 12
|
||||
tyObject, # 13
|
||||
tyTuple, # 14
|
||||
tySet, # 15
|
||||
tyRange, # 16
|
||||
tyPtr, # 17
|
||||
tyRef, # 18
|
||||
tyVar, # 19
|
||||
tySequence, # 20
|
||||
tyProc, # 21
|
||||
tyPointer, # 22
|
||||
tyOpenArray, # 23
|
||||
tyString, # 24
|
||||
tyCString, # 25
|
||||
tyForward, # 26
|
||||
tyNone, tyBool, tyChar,
|
||||
tyEmpty, tyArrayConstr, tyNil, tyExpr, tyStmt, tyTypeDesc,
|
||||
tyGenericInvokation, # ``T[a, b]`` for types to invoke
|
||||
tyGenericBody, # ``T[a, b, body]`` last parameter is the body
|
||||
tyGenericInst, # ``T[a, b, realInstance]`` instantiated generic type
|
||||
tyGenericParam, # ``a`` in the example
|
||||
tyDistinct, # distinct type
|
||||
tyEnum,
|
||||
tyOrdinal,
|
||||
tyArray,
|
||||
tyObject,
|
||||
tyTuple,
|
||||
tySet,
|
||||
tyRange,
|
||||
tyPtr, tyRef,
|
||||
tyVar,
|
||||
tySequence,
|
||||
tyProc,
|
||||
tyPointer, tyOpenArray,
|
||||
tyString, tyCString, tyForward,
|
||||
tyInt, tyInt8, tyInt16, tyInt32, tyInt64,
|
||||
tyFloat, tyFloat32, tyFloat64, tyFloat128,
|
||||
tyPureObject # 36: signals that object has no `n_type` field
|
||||
tyPureObject # signals that object has no `n_type` field
|
||||
|
||||
TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase
|
||||
TNimNode {.compilerproc, final.} = object
|
||||
|
|
|
|||
0
lib/system/mm.nim
Normal file → Executable file
0
lib/system/mm.nim
Normal file → Executable file
0
lib/system/profiler.nim
Normal file → Executable file
0
lib/system/profiler.nim
Normal file → Executable file
2
lib/system/repr.nim
Normal file → Executable file
2
lib/system/repr.nim
Normal file → Executable file
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2006 Andreas Rumpf
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
|
|
|
|||
84
lib/system/sets.nim
Normal file → Executable file
84
lib/system/sets.nim
Normal file → Executable file
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2006 Andreas Rumpf
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
|
|
@ -10,79 +10,19 @@
|
|||
# set handling
|
||||
|
||||
type
|
||||
TMyByte = int8
|
||||
TNimSet = array [0..4*2048-1, TMyByte]
|
||||
TNimSet = array [0..4*2048-1, int8]
|
||||
|
||||
# implementation:
|
||||
proc countBits32(n: int32): int {.compilerproc.} =
|
||||
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 countBits(n: int32): int {.exportc: "countBits".}
|
||||
# We use a prototype here, not in "cntbits.nim", because that is included
|
||||
# in math.nim too. So when linking with math.nim it'd give a duplicated
|
||||
# symbol error which we avoid by renaming here.
|
||||
proc countBits64(n: int64): int {.compilerproc.} =
|
||||
result = countBits32(toU32(n and 0xffff'i64)) +
|
||||
countBits32(toU32(n shr 16'i64))
|
||||
|
||||
include "system/cntbits"
|
||||
|
||||
proc unionSets(res: var TNimSet, a, b: TNimSet, len: int) {.
|
||||
compilerproc, inline.} =
|
||||
for i in countup(0, len-1): res[i] = a[i] or b[i]
|
||||
|
||||
proc diffSets(res: var TNimSet, a, b: TNimSet, len: int) {.
|
||||
compilerproc, inline.} =
|
||||
for i in countup(0, len-1): res[i] = a[i] and not b[i]
|
||||
|
||||
proc intersectSets(res: var TNimSet, a, b: TNimSet, len: int) {.
|
||||
compilerproc, inline.} =
|
||||
for i in countup(0, len-1): res[i] = a[i] and b[i]
|
||||
|
||||
proc symdiffSets(res: var TNimSet, a, b: TNimSet, len: int) {.
|
||||
compilerproc, inline.} =
|
||||
for i in countup(0, len-1): res[i] = a[i] xor b[i]
|
||||
|
||||
proc containsSets(a, b: TNimSet, len: int): bool {.compilerproc, inline.} =
|
||||
# s1 <= s2 ?
|
||||
for i in countup(0, len-1):
|
||||
if (a[i] and not b[i]) != 0'i8: return false
|
||||
return true
|
||||
|
||||
proc containsSubsets(a, b: TNimSet, len: int): bool {.compilerproc, inline.} =
|
||||
# s1 < s2 ?
|
||||
result = false # assume they are equal
|
||||
for i in countup(0, len-1):
|
||||
if (a[i]) and not b[i]) != 0'i32: return false
|
||||
if a[i] != b[i]: result = true # they are not equal
|
||||
|
||||
proc equalSets(a, b: TNimSet, len: int): bool {.compilerproc, inline.} =
|
||||
for i in countup(0, len-1):
|
||||
if a[i] != b[i]: return false
|
||||
return true
|
||||
|
||||
proc cardSet(s: TNimSet, len: int): int {.compilerproc, inline.} =
|
||||
proc cardSet(s: TNimSet, len: int): int {.compilerproc.} =
|
||||
result = 0
|
||||
for i in countup(0, len-1):
|
||||
inc(result, countBits(ze(s[i])))
|
||||
|
||||
const
|
||||
WORD_SIZE = sizeof(TMyByte)*8
|
||||
|
||||
proc inSet(s: TNimSet, elem: int): bool {.compilerproc, inline.} =
|
||||
return (s[elem /% WORD_SIZE] and (1 shl (elem %% WORD_SIZE))) != 0
|
||||
|
||||
proc inclSets(s: var TNimSet, e: int) {.compilerproc, inline.} =
|
||||
s[e /% WORD_SIZE] = s[e /% WORD_SIZE] or toU8(1 shl (e %% WORD_SIZE))
|
||||
|
||||
proc inclRange(s: var TNimSet, first, last: int) {.compilerproc.} =
|
||||
# not very fast, but it is seldom used
|
||||
for i in countup(first, last): inclSets(s, i)
|
||||
|
||||
proc smallInclRange(s: var int, first, last: int) {.compilerproc.} =
|
||||
# not very fast, but it is seldom used
|
||||
for i in countup(first, last):
|
||||
s = s or (1 shl (i %% sizeof(int)*8))
|
||||
|
||||
proc exclSets(s: var TNimSet, e: int) {.compilerproc, inline.} =
|
||||
s[e /% WORD_SIZE] = s[e /% WORD_SIZE] and
|
||||
not toU8(1 shl (e %% WORD_SIZE))
|
||||
|
||||
proc smallContainsSubsets(a, b: int): bool {.compilerProc, inline.} =
|
||||
# not used by new code generator
|
||||
return ((a and not b) != 0) and (a != b)
|
||||
inc(result, countBits32(int32(ze(s[i]))))
|
||||
|
|
|
|||
14
lib/system/sysio.nim
Normal file → Executable file
14
lib/system/sysio.nim
Normal file → Executable file
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
proc fputs(c: cstring, f: TFile) {.importc: "fputs", noDecl.}
|
||||
proc fgets(c: cstring, n: int, f: TFile): cstring {.importc: "fgets", noDecl.}
|
||||
proc fgetc(stream: TFile): int {.importc: "fgetc", nodecl.}
|
||||
proc fgetc(stream: TFile): cint {.importc: "fgetc", nodecl.}
|
||||
proc ungetc(c: cint, f: TFile) {.importc: "ungetc", nodecl.}
|
||||
proc putc(c: Char, stream: TFile) {.importc: "putc", nodecl.}
|
||||
proc fprintf(f: TFile, frmt: CString) {.importc: "fprintf", nodecl, varargs.}
|
||||
|
|
@ -36,11 +36,9 @@ var
|
|||
proc rawReadLine(f: TFile, result: var string) =
|
||||
# of course this could be optimized a bit; but IO is slow anyway...
|
||||
# and it was difficult to get this CORRECT with Ansi C's methods
|
||||
var
|
||||
c: cint
|
||||
setLen(result, 0) # reuse the buffer!
|
||||
while True:
|
||||
c = fgetc(f)
|
||||
var c = fgetc(f)
|
||||
if c < 0'i32: break # EOF
|
||||
if c == 10'i32: break # LF
|
||||
if c == 13'i32: # CR
|
||||
|
|
@ -68,6 +66,8 @@ proc write(f: TFile, c: Char) = putc(c, f)
|
|||
proc write(f: TFile, a: openArray[string]) =
|
||||
for x in items(a): write(f, x)
|
||||
|
||||
#{.error: "for debugging.".}
|
||||
|
||||
proc readFile(filename: string): string =
|
||||
var f: TFile
|
||||
try:
|
||||
|
|
@ -85,11 +85,9 @@ proc readFile(filename: string): string =
|
|||
|
||||
proc EndOfFile(f: TFile): bool =
|
||||
# do not blame me; blame the ANSI C standard this is so brain-damaged
|
||||
var
|
||||
c: int
|
||||
c = fgetc(f)
|
||||
var c = fgetc(f)
|
||||
ungetc(c, f)
|
||||
return c == -1
|
||||
return c == -1'i32
|
||||
|
||||
proc writeln[Ty](f: TFile, x: Ty) =
|
||||
write(f, x)
|
||||
|
|
|
|||
0
lib/system/sysstr.nim
Normal file → Executable file
0
lib/system/sysstr.nim
Normal file → Executable file
0
lib/ucmaps/8859-1.txt
Normal file → Executable file
0
lib/ucmaps/8859-1.txt
Normal file → Executable file
0
lib/ucmaps/8859-10.txt
Normal file → Executable file
0
lib/ucmaps/8859-10.txt
Normal file → Executable file
0
lib/ucmaps/8859-13.txt
Normal file → Executable file
0
lib/ucmaps/8859-13.txt
Normal file → Executable file
0
lib/ucmaps/8859-14.txt
Normal file → Executable file
0
lib/ucmaps/8859-14.txt
Normal file → Executable file
0
lib/ucmaps/8859-15.txt
Normal file → Executable file
0
lib/ucmaps/8859-15.txt
Normal file → Executable file
0
lib/ucmaps/8859-2.txt
Normal file → Executable file
0
lib/ucmaps/8859-2.txt
Normal file → Executable file
0
lib/ucmaps/8859-3.txt
Normal file → Executable file
0
lib/ucmaps/8859-3.txt
Normal file → Executable file
0
lib/ucmaps/8859-4.txt
Normal file → Executable file
0
lib/ucmaps/8859-4.txt
Normal file → Executable file
0
lib/ucmaps/8859-5.txt
Normal file → Executable file
0
lib/ucmaps/8859-5.txt
Normal file → Executable file
0
lib/ucmaps/8859-6.txt
Normal file → Executable file
0
lib/ucmaps/8859-6.txt
Normal file → Executable file
0
lib/ucmaps/8859-7.txt
Normal file → Executable file
0
lib/ucmaps/8859-7.txt
Normal file → Executable file
0
lib/ucmaps/8859-8.txt
Normal file → Executable file
0
lib/ucmaps/8859-8.txt
Normal file → Executable file
0
lib/ucmaps/8859-9.txt
Normal file → Executable file
0
lib/ucmaps/8859-9.txt
Normal file → Executable file
0
lib/ucmaps/cp1250.txt
Normal file → Executable file
0
lib/ucmaps/cp1250.txt
Normal file → Executable file
0
lib/ucmaps/cp1251.txt
Normal file → Executable file
0
lib/ucmaps/cp1251.txt
Normal file → Executable file
0
lib/ucmaps/cp1252.txt
Normal file → Executable file
0
lib/ucmaps/cp1252.txt
Normal file → Executable file
0
lib/ucmaps/cp1253.txt
Normal file → Executable file
0
lib/ucmaps/cp1253.txt
Normal file → Executable file
0
lib/ucmaps/cp1254.txt
Normal file → Executable file
0
lib/ucmaps/cp1254.txt
Normal file → Executable file
0
lib/ucmaps/cp1255.txt
Normal file → Executable file
0
lib/ucmaps/cp1255.txt
Normal file → Executable file
0
lib/ucmaps/cp1256.txt
Normal file → Executable file
0
lib/ucmaps/cp1256.txt
Normal file → Executable file
0
lib/ucmaps/cp1257.txt
Normal file → Executable file
0
lib/ucmaps/cp1257.txt
Normal file → Executable file
0
lib/ucmaps/cp1258.txt
Normal file → Executable file
0
lib/ucmaps/cp1258.txt
Normal file → Executable file
0
lib/ucmaps/cp437.txt
Normal file → Executable file
0
lib/ucmaps/cp437.txt
Normal file → Executable file
0
lib/ucmaps/cp737.txt
Normal file → Executable file
0
lib/ucmaps/cp737.txt
Normal file → Executable file
0
lib/ucmaps/cp775.txt
Normal file → Executable file
0
lib/ucmaps/cp775.txt
Normal file → Executable file
0
lib/ucmaps/cp850.txt
Normal file → Executable file
0
lib/ucmaps/cp850.txt
Normal file → Executable file
0
lib/ucmaps/cp852.txt
Normal file → Executable file
0
lib/ucmaps/cp852.txt
Normal file → Executable file
0
lib/ucmaps/cp855.txt
Normal file → Executable file
0
lib/ucmaps/cp855.txt
Normal file → Executable file
0
lib/ucmaps/cp856.txt
Normal file → Executable file
0
lib/ucmaps/cp856.txt
Normal file → Executable file
0
lib/ucmaps/cp857.txt
Normal file → Executable file
0
lib/ucmaps/cp857.txt
Normal file → Executable file
0
lib/ucmaps/cp860.txt
Normal file → Executable file
0
lib/ucmaps/cp860.txt
Normal file → Executable file
0
lib/ucmaps/cp861.txt
Normal file → Executable file
0
lib/ucmaps/cp861.txt
Normal file → Executable file
0
lib/ucmaps/cp862.txt
Normal file → Executable file
0
lib/ucmaps/cp862.txt
Normal file → Executable file
0
lib/ucmaps/cp863.txt
Normal file → Executable file
0
lib/ucmaps/cp863.txt
Normal file → Executable file
0
lib/ucmaps/cp864.txt
Normal file → Executable file
0
lib/ucmaps/cp864.txt
Normal file → Executable file
0
lib/ucmaps/cp865.txt
Normal file → Executable file
0
lib/ucmaps/cp865.txt
Normal file → Executable file
0
lib/ucmaps/cp866.txt
Normal file → Executable file
0
lib/ucmaps/cp866.txt
Normal file → Executable file
0
lib/ucmaps/cp869.txt
Normal file → Executable file
0
lib/ucmaps/cp869.txt
Normal file → Executable file
0
lib/ucmaps/cp874.txt
Normal file → Executable file
0
lib/ucmaps/cp874.txt
Normal file → Executable file
0
lib/ucmaps/cp932.txt
Normal file → Executable file
0
lib/ucmaps/cp932.txt
Normal file → Executable file
33
lib/windows/mmsystem.nim
Normal file → Executable file
33
lib/windows/mmsystem.nim
Normal file → Executable file
|
|
@ -2605,52 +2605,49 @@ proc PlaySound*(x1: cstring, x2: HMODULE, x3: DWORD): BOOL{.stdcall,
|
|||
# implementation
|
||||
|
||||
proc MEVT_EVENTTYPE(x: int8): int8 =
|
||||
result = (x shr 24) And 0x000000FF
|
||||
result = toU8(x shr 24)
|
||||
|
||||
proc MEVT_EVENTPARM(x: DWORD): DWORD =
|
||||
result = x And 0x00FFFFFF
|
||||
|
||||
type
|
||||
TFourBytes = array[0..3, int8]
|
||||
|
||||
proc MCI_MSF_MINUTE(msf: int32): int8 =
|
||||
result = msf and 0xff
|
||||
result = toU8(msf and 0xff)
|
||||
|
||||
proc MCI_TMSF_TRACK(tmsf: int32): int8 =
|
||||
result = tmsf and 0xff
|
||||
result = toU8(tmsf and 0xff)
|
||||
|
||||
proc MCI_HMS_HOUR(h: int32): int8 =
|
||||
result = h and 0xff
|
||||
result = toU8(h and 0xff)
|
||||
|
||||
proc MCI_MSF_SECOND(msf: int32): int8 =
|
||||
result = msf shr 8 and 0xff
|
||||
result = toU8(msf shr 8)
|
||||
|
||||
proc MCI_TMSF_MINUTE(tmsf: int32): int8 =
|
||||
result = tmsf shr 8 and 0xff
|
||||
result = toU8(tmsf shr 8)
|
||||
|
||||
proc MCI_HMS_MINUTE(h: int32): int8 =
|
||||
result = h shr 8 and 0xff
|
||||
result = toU8(h shr 8)
|
||||
|
||||
proc MCI_MSF_FRAME(msf: int32): int8 =
|
||||
result = msf shr 16 and 0xff
|
||||
result = toU8(msf shr 16)
|
||||
|
||||
proc MCI_TMSF_SECOND(tmsf: int32): int8 =
|
||||
result = tmsf shr 16 and 0xff
|
||||
result = toU8(tmsf shr 16)
|
||||
|
||||
proc MCI_HMS_SECOND(h: int32): int8 =
|
||||
result = h shr 16 and 0xff
|
||||
result = toU8(h shr 16)
|
||||
|
||||
proc MCI_MAKE_MSF(m, s, f: int8): int32 =
|
||||
result = m or s shl 8 or f shl 16
|
||||
result = toU32(ze(m) or ze(s) shl 8 or ze(f) shl 16)
|
||||
|
||||
proc MCI_MAKE_HMS(h, m, s: int8): int32 =
|
||||
result = h or m shl 8 or s shl 16
|
||||
result = toU32(ze(h) or ze(m) shl 8 or ze(s) shl 16)
|
||||
|
||||
proc MCI_TMSF_FRAME(tmsf: int32): int8 =
|
||||
result = tmsf shr 24 and 0xff
|
||||
result = toU8(tmsf shr 24)
|
||||
|
||||
proc mci_Make_TMSF(t, m, s, f: int8): int32 =
|
||||
result = t or m shl 8 or s shl 16 or f shl 24
|
||||
result = ze(t) or ze(m) shl 8 or ze(s) shl 16 or ze(f) shl 24
|
||||
|
||||
proc DIBINDEX(n: int32): int32 =
|
||||
result = n Or 0x000010FF shl 16
|
||||
result = n Or 0x000010FF'i32 shl 16'i32
|
||||
|
|
|
|||
0
lib/windows/nb30.nim
Normal file → Executable file
0
lib/windows/nb30.nim
Normal file → Executable file
0
lib/windows/ole2.nim
Normal file → Executable file
0
lib/windows/ole2.nim
Normal file → Executable file
0
lib/windows/shellapi.nim
Normal file → Executable file
0
lib/windows/shellapi.nim
Normal file → Executable file
0
lib/windows/shfolder.nim
Normal file → Executable file
0
lib/windows/shfolder.nim
Normal file → Executable file
0
lib/windows/windows.nim
Normal file → Executable file
0
lib/windows/windows.nim
Normal file → Executable file
0
lib/windows/winlean.nim
Normal file → Executable file
0
lib/windows/winlean.nim
Normal file → Executable file
0
lib/wrappers/cairo/cairo.nim
Normal file → Executable file
0
lib/wrappers/cairo/cairo.nim
Normal file → Executable file
0
lib/wrappers/cairo/cairoft.nim
Normal file → Executable file
0
lib/wrappers/cairo/cairoft.nim
Normal file → Executable file
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue