mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-10 15:04:59 +00:00
got rid of platdef.c generation
This commit is contained in:
10
koch.nim
10
koch.nim
@@ -20,7 +20,7 @@ const
|
||||
Build time: $2, $3
|
||||
|
||||
Usage:
|
||||
koch.py [options] command [options for command]
|
||||
koch [options] command [options for command]
|
||||
Options:
|
||||
--help, -h shows this help and quits
|
||||
Possible Commands:
|
||||
@@ -90,7 +90,7 @@ proc writePlatdefC =
|
||||
quit("Cannot write 'build/platdef.c'\n")
|
||||
|
||||
const
|
||||
bootOptions = "--compile:build/platdef.c"
|
||||
bootOptions = "" # "--compile:build/platdef.c"
|
||||
|
||||
proc findStartNimrod: string =
|
||||
const buildScript = "build.sh"
|
||||
@@ -118,16 +118,18 @@ proc findStartNimrod: string =
|
||||
|
||||
proc bootIteration(args: string): bool =
|
||||
var nimrod1 = "rod" / "nimrod1".exe
|
||||
if not ExistsFile("rod" / "nimrod".exe):
|
||||
quit("no binary has been created! Failed! Try with --forcebuild")
|
||||
moveFile nimrod1, "rod" / "nimrod".exe
|
||||
exec "rod" / "nimrod1 cc $# $# rod/nimrod.nim" % [bootOptions, args]
|
||||
result = sameFileContent("rod" / "nimrod".exe, "rod" / "nimrod1".exe)
|
||||
result = sameFileContent("rod" / "nimrod".exe, nimrod1)
|
||||
if result:
|
||||
moveFile "bin" / "nimrod".exe, "rod" / "nimrod".exe
|
||||
echo "executables are equal: SUCCESS!"
|
||||
removeFile nimrod1
|
||||
|
||||
proc boot(args: string) =
|
||||
writePlatdefC()
|
||||
#writePlatdefC()
|
||||
echo "iteration: 1"
|
||||
exec findStartNimrod() & " cc $# $# rod" / "nimrod.nim" % [bootOptions, args]
|
||||
echo "iteration: 2"
|
||||
|
||||
21
rod/ast.nim
Executable file → Normal file
21
rod/ast.nim
Executable file → Normal file
@@ -845,14 +845,11 @@ proc sonsLen(n: PType): int =
|
||||
else: result = len(n.sons)
|
||||
|
||||
proc newSons(father: PType, length: int) =
|
||||
var i, L: int
|
||||
if isNil(father.sons): father.sons = @ []
|
||||
L = len(father.sons)
|
||||
setlen(father.sons, L + length)
|
||||
if isNil(father.sons): father.sons = @[]
|
||||
setlen(father.sons, len(father.sons) + length)
|
||||
|
||||
proc addSon(father, son: PType) =
|
||||
var L: int
|
||||
if isNil(father.sons): father.sons = @ []
|
||||
if isNil(father.sons): father.sons = @[]
|
||||
add(father.sons, son)
|
||||
assert((father.kind != tyGenericInvokation) or (son.kind != tyGenericInst))
|
||||
|
||||
@@ -861,20 +858,16 @@ proc sonsLen(n: PNode): int =
|
||||
else: result = len(n.sons)
|
||||
|
||||
proc newSons(father: PNode, length: int) =
|
||||
var i, L: int
|
||||
if isNil(father.sons): father.sons = @ []
|
||||
L = len(father.sons)
|
||||
setlen(father.sons, L + length)
|
||||
if isNil(father.sons): father.sons = @[]
|
||||
setlen(father.sons, len(father.sons) + length)
|
||||
|
||||
proc addSon(father, son: PNode) =
|
||||
var L: int
|
||||
if isNil(father.sons): father.sons = @ []
|
||||
if isNil(father.sons): father.sons = @[]
|
||||
add(father.sons, son)
|
||||
|
||||
proc delSon(father: PNode, idx: int) =
|
||||
var length: int
|
||||
if isNil(father.sons): return
|
||||
length = sonsLen(father)
|
||||
var length = sonsLen(father)
|
||||
for i in countup(idx, length - 2): father.sons[i] = father.sons[i + 1]
|
||||
setlen(father.sons, length - 1)
|
||||
|
||||
|
||||
0
rod/ccgexprs.nim
Executable file → Normal file
0
rod/ccgexprs.nim
Executable file → Normal file
0
rod/cgen.nim
Executable file → Normal file
0
rod/cgen.nim
Executable file → Normal file
0
rod/condsyms.nim
Executable file → Normal file
0
rod/condsyms.nim
Executable file → Normal file
@@ -410,8 +410,7 @@ proc renderHeadline(d: PDoc, n: PRstNode): PRope =
|
||||
toRope(chr(n.level - 1 + ord('A')) & "")])
|
||||
|
||||
proc renderOverline(d: PDoc, n: PRstNode): PRope =
|
||||
var t: PRope
|
||||
t = nil
|
||||
var t: PRope = nil
|
||||
for i in countup(0, rsonsLen(n) - 1): app(t, renderRstToOut(d, n.sons[i]))
|
||||
result = nil
|
||||
if d.meta[metaTitle] == nil:
|
||||
@@ -543,10 +542,9 @@ proc renderTocEntry(d: PDoc, e: TTocEntry): PRope =
|
||||
"\\item\\label{$1_toc} $2\\ref{$1}$n", [e.refname, e.header])
|
||||
|
||||
proc renderTocEntries(d: PDoc, j: var int, lvl: int): PRope =
|
||||
var a: int
|
||||
result = nil
|
||||
while (j <= high(d.tocPart)):
|
||||
a = abs(d.tocPart[j].n.level)
|
||||
var a = abs(d.tocPart[j].n.level)
|
||||
if (a == lvl):
|
||||
app(result, renderTocEntry(d, d.tocPart[j]))
|
||||
inc(j)
|
||||
|
||||
0
rod/evals.nim
Executable file → Normal file
0
rod/evals.nim
Executable file → Normal file
@@ -1,23 +0,0 @@
|
||||
#
|
||||
#
|
||||
# The Nimrod Compiler
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
## Simple tool to expand ``importc`` pragmas. Used for the clean up process of
|
||||
## the diverse wrappers.
|
||||
|
||||
import
|
||||
os, ropes, idents, ast, pnimsyn, rnimsyn
|
||||
|
||||
times, commands, scanner, condsyms, options, msgs, nversion, nimconf, ropes,
|
||||
extccomp, strutils, os, platform, main, parseopt
|
||||
|
||||
if paramcount() == 0:
|
||||
echo ""
|
||||
|
||||
|
||||
|
||||
58
rod/expandimportc.nim
Executable file
58
rod/expandimportc.nim
Executable file
@@ -0,0 +1,58 @@
|
||||
#
|
||||
#
|
||||
# The Nimrod Compiler
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
## Simple tool to expand ``importc`` pragmas. Used for the clean up process of
|
||||
## the diverse wrappers.
|
||||
|
||||
import
|
||||
os, ropes, idents, ast, pnimsyn, rnimsyn, msgs, wordrecg, syntaxes
|
||||
|
||||
proc modifyPragmas(n: PNode, name: string) =
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
var it = n.sons[i]
|
||||
if it.kind == nkIdent and whichKeyword(it.ident) == wImportc:
|
||||
var x = newNode(nkExprColonExpr)
|
||||
addSon(x, it)
|
||||
addSon(x, newStrNode(nkStrLit, name))
|
||||
n.sons[i] = x
|
||||
|
||||
proc getName(n: PNode): string =
|
||||
case n.kind
|
||||
of nkPostfix: result = getName(n.sons[1])
|
||||
of nkPragmaExpr: result = getName(n.sons[0])
|
||||
of nkSym: result = n.sym.name.s
|
||||
of nkIdent: result = n.ident.s
|
||||
of nkAccQuoted: result = getName(n.sons[0])
|
||||
else: internalError(n.info, "getName()")
|
||||
|
||||
proc processRoutine(n: PNode) =
|
||||
var name = getName(n.sons[namePos])
|
||||
modifyPragmas(n.sons[pragmasPos], name)
|
||||
|
||||
proc processTree(n: PNode) =
|
||||
if n == nil: return
|
||||
case n.kind
|
||||
of nkEmpty..nkNilLit: nil
|
||||
of nkProcDef, nkConverterDef: processRoutine(n)
|
||||
else:
|
||||
for i in 0..sonsLen(n)-1: processTree(n.sons[i])
|
||||
|
||||
proc main(infile, outfile: string) =
|
||||
var module = ParseFile(infile)
|
||||
processTree(module)
|
||||
renderModule(module, outfile)
|
||||
|
||||
if paramcount() >= 1:
|
||||
var infile = addFileExt(paramStr(1), "nim")
|
||||
var outfile = changeFileExt(infile, "new.nim")
|
||||
if paramCount() >= 2:
|
||||
outfile = addFileExt(paramStr(2), "new.nim")
|
||||
main(infile, outfile)
|
||||
else:
|
||||
echo "usage: expand_importc filename[.nim] outfilename[.nim]"
|
||||
@@ -32,17 +32,6 @@ proc concHash*(h: THash, val: int): THash
|
||||
proc finishHash*(h: THash): THash
|
||||
# implementation
|
||||
|
||||
proc nextPowerOfTwo(x: int): int =
|
||||
result = x -% 1 # complicated, to make it a nop if sizeof(int) == 4,
|
||||
# because shifting more than 31 bits is undefined in C
|
||||
result = result or (result shr ((sizeof(int) - 4) * 8))
|
||||
result = result or (result shr 16)
|
||||
result = result or (result shr 8)
|
||||
result = result or (result shr 4)
|
||||
result = result or (result shr 2)
|
||||
result = result or (result shr 1)
|
||||
Inc(result)
|
||||
|
||||
proc concHash(h: THash, val: int): THash =
|
||||
result = h +% val
|
||||
result = result +% result shl 10
|
||||
|
||||
@@ -9,4 +9,3 @@
|
||||
@elif vcc:
|
||||
# cgen.speed = ""
|
||||
@end
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ options -> nstrtabs;
|
||||
msgs -> options;
|
||||
msgs -> strutils;
|
||||
msgs -> os;
|
||||
nversion -> strutils;
|
||||
crc -> strutils;
|
||||
platform -> strutils;
|
||||
ropes -> msgs;
|
||||
@@ -52,6 +51,7 @@ hashes -> strutils;
|
||||
strtabs -> os;
|
||||
strtabs -> hashes;
|
||||
strtabs -> strutils;
|
||||
osproc -> strutils;
|
||||
osproc -> os;
|
||||
osproc -> strtabs;
|
||||
osproc -> streams;
|
||||
@@ -108,6 +108,13 @@ pnimsyn -> idents;
|
||||
pnimsyn -> strutils;
|
||||
pnimsyn -> ast;
|
||||
pnimsyn -> msgs;
|
||||
pbraces -> llstream;
|
||||
pbraces -> scanner;
|
||||
pbraces -> idents;
|
||||
pbraces -> strutils;
|
||||
pbraces -> ast;
|
||||
pbraces -> msgs;
|
||||
pbraces -> pnimsyn;
|
||||
rnimsyn -> scanner;
|
||||
rnimsyn -> options;
|
||||
rnimsyn -> idents;
|
||||
@@ -115,6 +122,40 @@ rnimsyn -> strutils;
|
||||
rnimsyn -> ast;
|
||||
rnimsyn -> msgs;
|
||||
rnimsyn -> lists;
|
||||
filters -> llstream;
|
||||
filters -> os;
|
||||
filters -> wordrecg;
|
||||
filters -> idents;
|
||||
filters -> strutils;
|
||||
filters -> ast;
|
||||
filters -> astalgo;
|
||||
filters -> msgs;
|
||||
filters -> options;
|
||||
filters -> rnimsyn;
|
||||
ptmplsyn -> llstream;
|
||||
ptmplsyn -> os;
|
||||
ptmplsyn -> wordrecg;
|
||||
ptmplsyn -> idents;
|
||||
ptmplsyn -> strutils;
|
||||
ptmplsyn -> ast;
|
||||
ptmplsyn -> astalgo;
|
||||
ptmplsyn -> msgs;
|
||||
ptmplsyn -> options;
|
||||
ptmplsyn -> rnimsyn;
|
||||
ptmplsyn -> filters;
|
||||
syntaxes -> strutils;
|
||||
syntaxes -> llstream;
|
||||
syntaxes -> ast;
|
||||
syntaxes -> astalgo;
|
||||
syntaxes -> idents;
|
||||
syntaxes -> scanner;
|
||||
syntaxes -> options;
|
||||
syntaxes -> msgs;
|
||||
syntaxes -> pnimsyn;
|
||||
syntaxes -> pbraces;
|
||||
syntaxes -> ptmplsyn;
|
||||
syntaxes -> filters;
|
||||
syntaxes -> rnimsyn;
|
||||
paslex -> nhashes;
|
||||
paslex -> options;
|
||||
paslex -> msgs;
|
||||
@@ -194,7 +235,7 @@ passes -> math;
|
||||
passes -> magicsys;
|
||||
passes -> nversion;
|
||||
passes -> nimsets;
|
||||
passes -> pnimsyn;
|
||||
passes -> syntaxes;
|
||||
passes -> times;
|
||||
passes -> rodread;
|
||||
treetab -> nhashes;
|
||||
@@ -302,6 +343,7 @@ procfind -> astalgo;
|
||||
procfind -> msgs;
|
||||
procfind -> semdata;
|
||||
procfind -> types;
|
||||
procfind -> trees;
|
||||
pragmas -> os;
|
||||
pragmas -> platform;
|
||||
pragmas -> condsyms;
|
||||
@@ -319,7 +361,9 @@ pragmas -> lists;
|
||||
pragmas -> extccomp;
|
||||
pragmas -> math;
|
||||
pragmas -> magicsys;
|
||||
pragmas -> trees;
|
||||
sem -> strutils;
|
||||
sem -> nhashes;
|
||||
sem -> lists;
|
||||
sem -> options;
|
||||
sem -> scanner;
|
||||
@@ -378,7 +422,7 @@ docgen -> ropes;
|
||||
docgen -> idents;
|
||||
docgen -> wordrecg;
|
||||
docgen -> math;
|
||||
docgen -> pnimsyn;
|
||||
docgen -> syntaxes;
|
||||
docgen -> rnimsyn;
|
||||
docgen -> scanner;
|
||||
docgen -> rst;
|
||||
@@ -392,6 +436,14 @@ ccgutils -> nhashes;
|
||||
ccgutils -> strutils;
|
||||
ccgutils -> types;
|
||||
ccgutils -> msgs;
|
||||
cgmeth -> options;
|
||||
cgmeth -> ast;
|
||||
cgmeth -> astalgo;
|
||||
cgmeth -> msgs;
|
||||
cgmeth -> idents;
|
||||
cgmeth -> rnimsyn;
|
||||
cgmeth -> types;
|
||||
cgmeth -> magicsys;
|
||||
cgen -> ast;
|
||||
cgen -> astalgo;
|
||||
cgen -> strutils;
|
||||
@@ -419,6 +471,7 @@ cgen -> rodread;
|
||||
cgen -> wordrecg;
|
||||
cgen -> rnimsyn;
|
||||
cgen -> treetab;
|
||||
cgen -> cgmeth;
|
||||
ecmasgen -> ast;
|
||||
ecmasgen -> astalgo;
|
||||
ecmasgen -> strutils;
|
||||
@@ -445,15 +498,6 @@ ecmasgen -> ccgutils;
|
||||
ecmasgen -> wordrecg;
|
||||
ecmasgen -> rnimsyn;
|
||||
ecmasgen -> rodread;
|
||||
ptmplsyn -> llstream;
|
||||
ptmplsyn -> os;
|
||||
ptmplsyn -> wordrecg;
|
||||
ptmplsyn -> strutils;
|
||||
ptmplsyn -> ast;
|
||||
ptmplsyn -> astalgo;
|
||||
ptmplsyn -> msgs;
|
||||
ptmplsyn -> options;
|
||||
ptmplsyn -> pnimsyn;
|
||||
interact -> llstream;
|
||||
interact -> strutils;
|
||||
interact -> ropes;
|
||||
@@ -481,6 +525,7 @@ transf -> ast;
|
||||
transf -> astalgo;
|
||||
transf -> trees;
|
||||
transf -> treetab;
|
||||
transf -> evals;
|
||||
transf -> msgs;
|
||||
transf -> os;
|
||||
transf -> idents;
|
||||
@@ -489,12 +534,13 @@ transf -> types;
|
||||
transf -> passes;
|
||||
transf -> semfold;
|
||||
transf -> magicsys;
|
||||
transf -> cgmeth;
|
||||
main -> llstream;
|
||||
main -> strutils;
|
||||
main -> ast;
|
||||
main -> astalgo;
|
||||
main -> scanner;
|
||||
main -> pnimsyn;
|
||||
main -> syntaxes;
|
||||
main -> rnimsyn;
|
||||
main -> options;
|
||||
main -> msgs;
|
||||
@@ -517,7 +563,6 @@ main -> extccomp;
|
||||
main -> cgen;
|
||||
main -> ecmasgen;
|
||||
main -> platform;
|
||||
main -> ptmplsyn;
|
||||
main -> interact;
|
||||
main -> nimconf;
|
||||
main -> importer;
|
||||
|
||||
0
rod/nimrod.nim
Executable file → Normal file
0
rod/nimrod.nim
Executable file → Normal 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.
|
||||
@@ -52,12 +52,11 @@ const
|
||||
|
||||
proc newStringTable(keyValuePairs: openarray[string],
|
||||
mode: TStringTableMode = modeCaseSensitive): PStringTable =
|
||||
var i: int
|
||||
new(result)
|
||||
result.mode = mode
|
||||
result.counter = 0
|
||||
newSeq(result.data, startSize)
|
||||
i = 0
|
||||
var i = 0
|
||||
while i < high(keyValuePairs):
|
||||
put(result, keyValuePairs[i], keyValuePairs[i + 1])
|
||||
inc(i, 2)
|
||||
@@ -81,17 +80,14 @@ proc mustRehash(length, counter: int): bool =
|
||||
proc length(t: PStringTable): int =
|
||||
result = t.counter
|
||||
|
||||
const
|
||||
EmptySeq = []
|
||||
|
||||
proc nextTry(h, maxHash: THash): THash =
|
||||
result = ((5 * h) + 1) and maxHash # For any initial h in range(maxHash), repeating that maxHash times
|
||||
# generates each int in range(maxHash) exactly once (see any text on
|
||||
# random-number generation for proof).
|
||||
result = ((5 * h) + 1) and maxHash
|
||||
# For any initial h in range(maxHash), repeating that maxHash times
|
||||
# generates each int in range(maxHash) exactly once (see any text on
|
||||
# random-number generation for proof).
|
||||
|
||||
proc RawGet(t: PStringTable, key: string): int =
|
||||
var h: THash
|
||||
h = myhash(t, key) and high(t.data) # start with real hash value
|
||||
var h = myhash(t, key) and high(t.data) # start with real hash value
|
||||
while not isNil(t.data[h].key):
|
||||
if mycmp(t, t.data[h].key, key):
|
||||
return h
|
||||
@@ -99,8 +95,7 @@ proc RawGet(t: PStringTable, key: string): int =
|
||||
result = - 1
|
||||
|
||||
proc get(t: PStringTable, key: string): string =
|
||||
var index: int
|
||||
index = RawGet(t, key)
|
||||
var index = RawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
else: result = ""
|
||||
|
||||
@@ -108,8 +103,7 @@ proc hasKey(t: PStringTable, key: string): bool =
|
||||
result = rawGet(t, key) >= 0
|
||||
|
||||
proc RawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) =
|
||||
var h: THash
|
||||
h = myhash(t, key) and high(data)
|
||||
var h = myhash(t, key) and high(data)
|
||||
while not isNil(data[h].key):
|
||||
h = nextTry(h, high(data))
|
||||
data[h].key = key
|
||||
@@ -123,8 +117,7 @@ proc Enlarge(t: PStringTable) =
|
||||
swap(t.data, n)
|
||||
|
||||
proc Put(t: PStringTable, key, val: string) =
|
||||
var index: int
|
||||
index = RawGet(t, key)
|
||||
var index = RawGet(t, key)
|
||||
if index >= 0:
|
||||
t.data[index].val = val
|
||||
else:
|
||||
@@ -139,22 +132,18 @@ proc RaiseFormatException(s: string) =
|
||||
raise e
|
||||
|
||||
proc getValue(t: PStringTable, flags: TFormatFlags, key: string): string =
|
||||
if hasKey(t, key):
|
||||
return get(t, key)
|
||||
if hasKey(t, key): return get(t, key)
|
||||
if useEnvironment in flags: result = os.getEnv(key)
|
||||
else: result = ""
|
||||
if (result == ""):
|
||||
if result.len == 0:
|
||||
if useKey in flags: result = '$' & key
|
||||
elif not (useEmpty in flags): raiseFormatException(key)
|
||||
|
||||
proc `%`(f: string, t: PStringTable, flags: TFormatFlags = {}): string =
|
||||
const
|
||||
PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\x80'..'\xFF'}
|
||||
var
|
||||
i, j: int
|
||||
key: string
|
||||
result = ""
|
||||
i = 0
|
||||
var i = 0
|
||||
while i <= len(f) + 0 - 1:
|
||||
if f[i] == '$':
|
||||
case f[i + 1]
|
||||
@@ -162,15 +151,15 @@ proc `%`(f: string, t: PStringTable, flags: TFormatFlags = {}): string =
|
||||
add(result, '$')
|
||||
inc(i, 2)
|
||||
of '{':
|
||||
j = i + 1
|
||||
var j = i + 1
|
||||
while (j <= len(f) + 0 - 1) and (f[j] != '}'): inc(j)
|
||||
key = copy(f, i + 2 + 0 - 1, j - 1 + 0 - 1)
|
||||
var key = copy(f, i + 2 + 0 - 1, j - 1 + 0 - 1)
|
||||
add(result, getValue(t, flags, key))
|
||||
i = j + 1
|
||||
of 'a'..'z', 'A'..'Z', '\x80'..'\xFF', '_':
|
||||
j = i + 1
|
||||
var j = i + 1
|
||||
while (j <= len(f) + 0 - 1) and (f[j] in PatternChars): inc(j)
|
||||
key = copy(f, i + 1 + 0 - 1, j - 1 + 0 - 1)
|
||||
var key = copy(f, i + 1 + 0 - 1, j - 1 + 0 - 1)
|
||||
add(result, getValue(t, flags, key))
|
||||
i = j
|
||||
else:
|
||||
|
||||
0
rod/options.nim
Executable file → Normal file
0
rod/options.nim
Executable file → Normal file
0
rod/pbraces.nim
Executable file → Normal file
0
rod/pbraces.nim
Executable file → Normal file
@@ -203,10 +203,13 @@ proc NameToCPU(name: string): TSystemCPU =
|
||||
return i
|
||||
result = cpuNone
|
||||
|
||||
proc nimCPU(): cstring{.importc, noconv.}
|
||||
proc nimOS(): cstring{.importc, noconv.}
|
||||
#proc nimCPU(): cstring{.importc, noconv.}
|
||||
#proc nimOS(): cstring{.importc, noconv.}
|
||||
|
||||
#hostCPU = nameToCPU($nimCPU())
|
||||
#hostOS = nameToOS($nimOS())
|
||||
hostCPU = nameToCPU(system.hostCPU)
|
||||
hostOS = nameToOS(system.hostOS)
|
||||
|
||||
hostCPU = nameToCPU($(nimCPU()))
|
||||
hostOS = nameToOS($(nimOS()))
|
||||
setTarget(hostOS, hostCPU) # assume no cross-compiling
|
||||
|
||||
|
||||
0
rod/pnimsyn.nim
Executable file → Normal file
0
rod/pnimsyn.nim
Executable file → Normal file
0
rod/pragmas.nim
Executable file → Normal file
0
rod/pragmas.nim
Executable file → Normal file
0
rod/rodread.nim
Executable file → Normal file
0
rod/rodread.nim
Executable file → Normal file
0
rod/rodwrite.nim
Executable file → Normal file
0
rod/rodwrite.nim
Executable file → Normal file
@@ -123,19 +123,17 @@ proc getCacheStats(): string =
|
||||
result = ""
|
||||
|
||||
proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
||||
var
|
||||
le, r, y, t: PRope
|
||||
c: int
|
||||
t = tree
|
||||
var c: int
|
||||
var t = tree
|
||||
N.left = nil
|
||||
N.right = nil # reset to nil
|
||||
le = N
|
||||
r = N
|
||||
var le = N
|
||||
var r = N
|
||||
while true:
|
||||
c = cmp(s, t.data)
|
||||
if c < 0:
|
||||
if (t.left != nil) and (s < t.left.data):
|
||||
y = t.left
|
||||
var y = t.left
|
||||
t.left = y.right
|
||||
y.right = t
|
||||
t = y
|
||||
@@ -145,7 +143,7 @@ proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
||||
t = t.left
|
||||
elif c > 0:
|
||||
if (t.right != nil) and (s > t.right.data):
|
||||
y = t.right
|
||||
var y = t.right
|
||||
t.right = y.left
|
||||
y.left = t
|
||||
t = y
|
||||
@@ -165,14 +163,12 @@ proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
||||
proc insertInCache(s: string, tree: PRope): PRope =
|
||||
# Insert i into the tree t, unless it's already there.
|
||||
# Return a pointer to the resulting tree.
|
||||
var
|
||||
t: PRope
|
||||
cmp: int
|
||||
t = tree
|
||||
var t = tree
|
||||
if t == nil:
|
||||
result = newRope(s)
|
||||
if countCacheMisses: inc(misses)
|
||||
return
|
||||
var cmp: int
|
||||
t = splay(s, t, cmp)
|
||||
if cmp == 0:
|
||||
# We get here if it's already in the Tree
|
||||
@@ -216,14 +212,13 @@ proc toRope(s: string): PRope =
|
||||
assert(RopeInvariant(result))
|
||||
|
||||
proc RopeSeqInsert(rs: var TRopeSeq, r: PRope, at: Natural) =
|
||||
var length: int
|
||||
length = len(rs)
|
||||
var length = len(rs)
|
||||
if at > length:
|
||||
setlen(rs, at + 1)
|
||||
else:
|
||||
setlen(rs, length + 1) # move old rope elements:
|
||||
for i in countdown(length, at + 1):
|
||||
rs[i] = rs[i - 1] # this is correct, I used pen and paper to validate it
|
||||
rs[i] = rs[i - 1] # this is correct, I used pen and paper to validate it
|
||||
rs[at] = r
|
||||
|
||||
proc con(a, b: PRope): PRope =
|
||||
@@ -241,12 +236,11 @@ proc con(a, b: PRope): PRope =
|
||||
assert(RopeInvariant(result))
|
||||
|
||||
proc con(a: PRope, b: string): PRope =
|
||||
var r: PRope
|
||||
assert(RopeInvariant(a))
|
||||
if b == "":
|
||||
result = a
|
||||
else:
|
||||
r = toRope(b)
|
||||
var r = toRope(b)
|
||||
if a == nil:
|
||||
result = r
|
||||
else:
|
||||
@@ -257,12 +251,11 @@ proc con(a: PRope, b: string): PRope =
|
||||
assert(RopeInvariant(result))
|
||||
|
||||
proc con(a: string, b: PRope): PRope =
|
||||
var r: PRope
|
||||
assert(RopeInvariant(b))
|
||||
if a == "":
|
||||
result = b
|
||||
else:
|
||||
r = toRope(a)
|
||||
var r = toRope(a)
|
||||
if b == nil:
|
||||
result = r
|
||||
else:
|
||||
@@ -295,21 +288,6 @@ proc prepend(a: var PRope, b: PRope) =
|
||||
a = con(b, a)
|
||||
assert(RopeInvariant(a))
|
||||
|
||||
proc InitStack(stack: var TRopeSeq) =
|
||||
stack = @ []
|
||||
|
||||
proc push(stack: var TRopeSeq, r: PRope) =
|
||||
var length: int
|
||||
length = len(stack)
|
||||
setlen(stack, length + 1)
|
||||
stack[length] = r
|
||||
|
||||
proc pop(stack: var TRopeSeq): PRope =
|
||||
var length: int
|
||||
length = len(stack)
|
||||
result = stack[length - 1]
|
||||
setlen(stack, length - 1)
|
||||
|
||||
proc WriteRopeRec(f: var tfile, c: PRope) =
|
||||
assert(RopeInvariant(c))
|
||||
if c == nil: return
|
||||
@@ -320,16 +298,11 @@ proc WriteRopeRec(f: var tfile, c: PRope) =
|
||||
writeRopeRec(f, c.right)
|
||||
|
||||
proc newWriteRopeRec(f: var tfile, c: PRope) =
|
||||
var
|
||||
stack: TRopeSeq
|
||||
it: PRope
|
||||
assert(RopeInvariant(c))
|
||||
initStack(stack)
|
||||
push(stack, c)
|
||||
var stack: TRopeSeq = @[c]
|
||||
while len(stack) > 0:
|
||||
it = pop(stack)
|
||||
var it = pop(stack)
|
||||
while it.data == nil:
|
||||
push(stack, it.right)
|
||||
add(stack, it.right)
|
||||
it = it.left
|
||||
assert(it != nil)
|
||||
assert(it.data != nil)
|
||||
@@ -355,15 +328,11 @@ proc recRopeToStr(result: var string, resultLen: var int, p: PRope) =
|
||||
assert(resultLen <= len(result))
|
||||
|
||||
proc newRecRopeToStr(result: var string, resultLen: var int, r: PRope) =
|
||||
var
|
||||
stack: TRopeSeq
|
||||
it: PRope
|
||||
initStack(stack)
|
||||
push(stack, r)
|
||||
var stack: TRopeSeq = @[r]
|
||||
while len(stack) > 0:
|
||||
it = pop(stack)
|
||||
var it = pop(stack)
|
||||
while it.data == nil:
|
||||
push(stack, it.right)
|
||||
add(stack, it.right)
|
||||
it = it.left
|
||||
assert(it.data != nil)
|
||||
CopyMem(addr(result[resultLen + 0]), addr(it.data[0]), it.length)
|
||||
@@ -371,13 +340,11 @@ proc newRecRopeToStr(result: var string, resultLen: var int, r: PRope) =
|
||||
assert(resultLen <= len(result))
|
||||
|
||||
proc ropeToStr(p: PRope): string =
|
||||
var resultLen: int
|
||||
assert(RopeInvariant(p))
|
||||
if p == nil:
|
||||
result = ""
|
||||
else:
|
||||
result = newString(p.length)
|
||||
resultLen = 0
|
||||
var resultLen = 0
|
||||
newRecRopeToStr(result, resultLen, p)
|
||||
|
||||
proc ropef(frmt: TFormatStr, args: openarray[PRope]): PRope =
|
||||
@@ -426,11 +393,10 @@ const
|
||||
bufSize = 1024 # 1 KB is reasonable
|
||||
|
||||
proc auxRopeEqualsFile(r: PRope, bin: var tfile, buf: Pointer): bool =
|
||||
var readBytes: int
|
||||
if (r.data != nil):
|
||||
if r.length > bufSize:
|
||||
internalError("ropes: token too long")
|
||||
readBytes = readBuffer(bin, buf, r.length)
|
||||
var readBytes = readBuffer(bin, buf, r.length)
|
||||
result = (readBytes == r.length) and
|
||||
equalMem(buf, addr(r.data[0]), r.length) # BUGFIX
|
||||
else:
|
||||
@@ -438,13 +404,11 @@ proc auxRopeEqualsFile(r: PRope, bin: var tfile, buf: Pointer): bool =
|
||||
if result: result = auxRopeEqualsFile(r.right, bin, buf)
|
||||
|
||||
proc RopeEqualsFile(r: PRope, f: string): bool =
|
||||
var
|
||||
bin: tfile
|
||||
buf: Pointer
|
||||
var bin: tfile
|
||||
result = open(bin, f)
|
||||
if not result:
|
||||
return # not equal if file does not exist
|
||||
buf = alloc(BufSize)
|
||||
var buf = alloc(BufSize)
|
||||
result = auxRopeEqualsFile(r, bin, buf)
|
||||
if result:
|
||||
result = readBuffer(bin, buf, bufSize) == 0 # really at the end of file?
|
||||
@@ -461,21 +425,16 @@ proc crcFromRopeAux(r: PRope, startVal: TCrc32): TCrc32 =
|
||||
result = crcFromRopeAux(r.right, result)
|
||||
|
||||
proc newCrcFromRopeAux(r: PRope, startVal: TCrc32): TCrc32 =
|
||||
var
|
||||
stack: TRopeSeq
|
||||
it: PRope
|
||||
L, i: int
|
||||
initStack(stack)
|
||||
push(stack, r)
|
||||
var stack: TRopeSeq = @[r]
|
||||
result = startVal
|
||||
while len(stack) > 0:
|
||||
it = pop(stack)
|
||||
var it = pop(stack)
|
||||
while it.data == nil:
|
||||
push(stack, it.right)
|
||||
add(stack, it.right)
|
||||
it = it.left
|
||||
assert(it.data != nil)
|
||||
i = 0
|
||||
L = len(it.data) + 0
|
||||
var i = 0
|
||||
var L = len(it.data)
|
||||
while i < L:
|
||||
result = updateCrc32(it.data[i], result)
|
||||
inc(i)
|
||||
@@ -493,5 +452,4 @@ proc writeRopeIfNotEqual(r: PRope, filename: string): bool =
|
||||
else:
|
||||
result = false
|
||||
|
||||
new(N)
|
||||
# init dummy node for splay algorithm
|
||||
new(N) # init dummy node for splay algorithm
|
||||
0
rod/sem.nim
Executable file → Normal file
0
rod/sem.nim
Executable file → Normal file
0
rod/semdata.nim
Executable file → Normal file
0
rod/semdata.nim
Executable file → Normal file
0
rod/semfold.nim
Executable file → Normal file
0
rod/semfold.nim
Executable file → Normal file
0
rod/transf.nim
Executable file → Normal file
0
rod/transf.nim
Executable file → Normal file
0
rod/trees.nim
Executable file → Normal file
0
rod/trees.nim
Executable file → Normal file
Reference in New Issue
Block a user