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/system/alloc.nim Normal file → Executable file
View file

0
lib/system/ansi_c.nim Normal file → Executable file
View file

0
lib/system/arithm.nim Normal file → Executable file
View file

2
lib/system/assign.nim Normal file → Executable file
View 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
View file

10
lib/system/cntbits.nim Normal file → Executable file
View 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
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.
@ -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
View file

0
lib/system/ecmasys.nim Normal file → Executable file
View file

0
lib/system/excpt.nim Normal file → Executable file
View file

6
lib/system/gc.nim Normal file → Executable file
View 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
View 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
View file

0
lib/system/profiler.nim Normal file → Executable file
View file

2
lib/system/repr.nim Normal file → Executable file
View 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
View 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
View 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
View file