got rid of platdef.c generation
This commit is contained in:
parent
10ab814fba
commit
8ce705f686
27 changed files with 184 additions and 173 deletions
10
koch.nim
10
koch.nim
|
|
@ -20,7 +20,7 @@ const
|
||||||
Build time: $2, $3
|
Build time: $2, $3
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
koch.py [options] command [options for command]
|
koch [options] command [options for command]
|
||||||
Options:
|
Options:
|
||||||
--help, -h shows this help and quits
|
--help, -h shows this help and quits
|
||||||
Possible Commands:
|
Possible Commands:
|
||||||
|
|
@ -90,7 +90,7 @@ proc writePlatdefC =
|
||||||
quit("Cannot write 'build/platdef.c'\n")
|
quit("Cannot write 'build/platdef.c'\n")
|
||||||
|
|
||||||
const
|
const
|
||||||
bootOptions = "--compile:build/platdef.c"
|
bootOptions = "" # "--compile:build/platdef.c"
|
||||||
|
|
||||||
proc findStartNimrod: string =
|
proc findStartNimrod: string =
|
||||||
const buildScript = "build.sh"
|
const buildScript = "build.sh"
|
||||||
|
|
@ -118,16 +118,18 @@ proc findStartNimrod: string =
|
||||||
|
|
||||||
proc bootIteration(args: string): bool =
|
proc bootIteration(args: string): bool =
|
||||||
var nimrod1 = "rod" / "nimrod1".exe
|
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
|
moveFile nimrod1, "rod" / "nimrod".exe
|
||||||
exec "rod" / "nimrod1 cc $# $# rod/nimrod.nim" % [bootOptions, args]
|
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:
|
if result:
|
||||||
moveFile "bin" / "nimrod".exe, "rod" / "nimrod".exe
|
moveFile "bin" / "nimrod".exe, "rod" / "nimrod".exe
|
||||||
echo "executables are equal: SUCCESS!"
|
echo "executables are equal: SUCCESS!"
|
||||||
removeFile nimrod1
|
removeFile nimrod1
|
||||||
|
|
||||||
proc boot(args: string) =
|
proc boot(args: string) =
|
||||||
writePlatdefC()
|
#writePlatdefC()
|
||||||
echo "iteration: 1"
|
echo "iteration: 1"
|
||||||
exec findStartNimrod() & " cc $# $# rod" / "nimrod.nim" % [bootOptions, args]
|
exec findStartNimrod() & " cc $# $# rod" / "nimrod.nim" % [bootOptions, args]
|
||||||
echo "iteration: 2"
|
echo "iteration: 2"
|
||||||
|
|
|
||||||
13
rod/ast.nim
Executable file → Normal file
13
rod/ast.nim
Executable file → Normal file
|
|
@ -845,13 +845,10 @@ proc sonsLen(n: PType): int =
|
||||||
else: result = len(n.sons)
|
else: result = len(n.sons)
|
||||||
|
|
||||||
proc newSons(father: PType, length: int) =
|
proc newSons(father: PType, length: int) =
|
||||||
var i, L: int
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
if isNil(father.sons): father.sons = @[]
|
||||||
L = len(father.sons)
|
setlen(father.sons, len(father.sons) + length)
|
||||||
setlen(father.sons, L + length)
|
|
||||||
|
|
||||||
proc addSon(father, son: PType) =
|
proc addSon(father, son: PType) =
|
||||||
var L: int
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
if isNil(father.sons): father.sons = @[]
|
||||||
add(father.sons, son)
|
add(father.sons, son)
|
||||||
assert((father.kind != tyGenericInvokation) or (son.kind != tyGenericInst))
|
assert((father.kind != tyGenericInvokation) or (son.kind != tyGenericInst))
|
||||||
|
|
@ -861,20 +858,16 @@ proc sonsLen(n: PNode): int =
|
||||||
else: result = len(n.sons)
|
else: result = len(n.sons)
|
||||||
|
|
||||||
proc newSons(father: PNode, length: int) =
|
proc newSons(father: PNode, length: int) =
|
||||||
var i, L: int
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
if isNil(father.sons): father.sons = @[]
|
||||||
L = len(father.sons)
|
setlen(father.sons, len(father.sons) + length)
|
||||||
setlen(father.sons, L + length)
|
|
||||||
|
|
||||||
proc addSon(father, son: PNode) =
|
proc addSon(father, son: PNode) =
|
||||||
var L: int
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
if isNil(father.sons): father.sons = @[]
|
||||||
add(father.sons, son)
|
add(father.sons, son)
|
||||||
|
|
||||||
proc delSon(father: PNode, idx: int) =
|
proc delSon(father: PNode, idx: int) =
|
||||||
var length: int
|
|
||||||
if isNil(father.sons): return
|
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]
|
for i in countup(idx, length - 2): father.sons[i] = father.sons[i + 1]
|
||||||
setlen(father.sons, length - 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')) & "")])
|
toRope(chr(n.level - 1 + ord('A')) & "")])
|
||||||
|
|
||||||
proc renderOverline(d: PDoc, n: PRstNode): PRope =
|
proc renderOverline(d: PDoc, n: PRstNode): PRope =
|
||||||
var t: PRope
|
var t: PRope = nil
|
||||||
t = nil
|
|
||||||
for i in countup(0, rsonsLen(n) - 1): app(t, renderRstToOut(d, n.sons[i]))
|
for i in countup(0, rsonsLen(n) - 1): app(t, renderRstToOut(d, n.sons[i]))
|
||||||
result = nil
|
result = nil
|
||||||
if d.meta[metaTitle] == 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])
|
"\\item\\label{$1_toc} $2\\ref{$1}$n", [e.refname, e.header])
|
||||||
|
|
||||||
proc renderTocEntries(d: PDoc, j: var int, lvl: int): PRope =
|
proc renderTocEntries(d: PDoc, j: var int, lvl: int): PRope =
|
||||||
var a: int
|
|
||||||
result = nil
|
result = nil
|
||||||
while (j <= high(d.tocPart)):
|
while (j <= high(d.tocPart)):
|
||||||
a = abs(d.tocPart[j].n.level)
|
var a = abs(d.tocPart[j].n.level)
|
||||||
if (a == lvl):
|
if (a == lvl):
|
||||||
app(result, renderTocEntry(d, d.tocPart[j]))
|
app(result, renderTocEntry(d, d.tocPart[j]))
|
||||||
inc(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
|
proc finishHash*(h: THash): THash
|
||||||
# implementation
|
# 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 =
|
proc concHash(h: THash, val: int): THash =
|
||||||
result = h +% val
|
result = h +% val
|
||||||
result = result +% result shl 10
|
result = result +% result shl 10
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,3 @@
|
||||||
@elif vcc:
|
@elif vcc:
|
||||||
# cgen.speed = ""
|
# cgen.speed = ""
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ options -> nstrtabs;
|
||||||
msgs -> options;
|
msgs -> options;
|
||||||
msgs -> strutils;
|
msgs -> strutils;
|
||||||
msgs -> os;
|
msgs -> os;
|
||||||
nversion -> strutils;
|
|
||||||
crc -> strutils;
|
crc -> strutils;
|
||||||
platform -> strutils;
|
platform -> strutils;
|
||||||
ropes -> msgs;
|
ropes -> msgs;
|
||||||
|
|
@ -52,6 +51,7 @@ hashes -> strutils;
|
||||||
strtabs -> os;
|
strtabs -> os;
|
||||||
strtabs -> hashes;
|
strtabs -> hashes;
|
||||||
strtabs -> strutils;
|
strtabs -> strutils;
|
||||||
|
osproc -> strutils;
|
||||||
osproc -> os;
|
osproc -> os;
|
||||||
osproc -> strtabs;
|
osproc -> strtabs;
|
||||||
osproc -> streams;
|
osproc -> streams;
|
||||||
|
|
@ -108,6 +108,13 @@ pnimsyn -> idents;
|
||||||
pnimsyn -> strutils;
|
pnimsyn -> strutils;
|
||||||
pnimsyn -> ast;
|
pnimsyn -> ast;
|
||||||
pnimsyn -> msgs;
|
pnimsyn -> msgs;
|
||||||
|
pbraces -> llstream;
|
||||||
|
pbraces -> scanner;
|
||||||
|
pbraces -> idents;
|
||||||
|
pbraces -> strutils;
|
||||||
|
pbraces -> ast;
|
||||||
|
pbraces -> msgs;
|
||||||
|
pbraces -> pnimsyn;
|
||||||
rnimsyn -> scanner;
|
rnimsyn -> scanner;
|
||||||
rnimsyn -> options;
|
rnimsyn -> options;
|
||||||
rnimsyn -> idents;
|
rnimsyn -> idents;
|
||||||
|
|
@ -115,6 +122,40 @@ rnimsyn -> strutils;
|
||||||
rnimsyn -> ast;
|
rnimsyn -> ast;
|
||||||
rnimsyn -> msgs;
|
rnimsyn -> msgs;
|
||||||
rnimsyn -> lists;
|
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 -> nhashes;
|
||||||
paslex -> options;
|
paslex -> options;
|
||||||
paslex -> msgs;
|
paslex -> msgs;
|
||||||
|
|
@ -194,7 +235,7 @@ passes -> math;
|
||||||
passes -> magicsys;
|
passes -> magicsys;
|
||||||
passes -> nversion;
|
passes -> nversion;
|
||||||
passes -> nimsets;
|
passes -> nimsets;
|
||||||
passes -> pnimsyn;
|
passes -> syntaxes;
|
||||||
passes -> times;
|
passes -> times;
|
||||||
passes -> rodread;
|
passes -> rodread;
|
||||||
treetab -> nhashes;
|
treetab -> nhashes;
|
||||||
|
|
@ -302,6 +343,7 @@ procfind -> astalgo;
|
||||||
procfind -> msgs;
|
procfind -> msgs;
|
||||||
procfind -> semdata;
|
procfind -> semdata;
|
||||||
procfind -> types;
|
procfind -> types;
|
||||||
|
procfind -> trees;
|
||||||
pragmas -> os;
|
pragmas -> os;
|
||||||
pragmas -> platform;
|
pragmas -> platform;
|
||||||
pragmas -> condsyms;
|
pragmas -> condsyms;
|
||||||
|
|
@ -319,7 +361,9 @@ pragmas -> lists;
|
||||||
pragmas -> extccomp;
|
pragmas -> extccomp;
|
||||||
pragmas -> math;
|
pragmas -> math;
|
||||||
pragmas -> magicsys;
|
pragmas -> magicsys;
|
||||||
|
pragmas -> trees;
|
||||||
sem -> strutils;
|
sem -> strutils;
|
||||||
|
sem -> nhashes;
|
||||||
sem -> lists;
|
sem -> lists;
|
||||||
sem -> options;
|
sem -> options;
|
||||||
sem -> scanner;
|
sem -> scanner;
|
||||||
|
|
@ -378,7 +422,7 @@ docgen -> ropes;
|
||||||
docgen -> idents;
|
docgen -> idents;
|
||||||
docgen -> wordrecg;
|
docgen -> wordrecg;
|
||||||
docgen -> math;
|
docgen -> math;
|
||||||
docgen -> pnimsyn;
|
docgen -> syntaxes;
|
||||||
docgen -> rnimsyn;
|
docgen -> rnimsyn;
|
||||||
docgen -> scanner;
|
docgen -> scanner;
|
||||||
docgen -> rst;
|
docgen -> rst;
|
||||||
|
|
@ -392,6 +436,14 @@ ccgutils -> nhashes;
|
||||||
ccgutils -> strutils;
|
ccgutils -> strutils;
|
||||||
ccgutils -> types;
|
ccgutils -> types;
|
||||||
ccgutils -> msgs;
|
ccgutils -> msgs;
|
||||||
|
cgmeth -> options;
|
||||||
|
cgmeth -> ast;
|
||||||
|
cgmeth -> astalgo;
|
||||||
|
cgmeth -> msgs;
|
||||||
|
cgmeth -> idents;
|
||||||
|
cgmeth -> rnimsyn;
|
||||||
|
cgmeth -> types;
|
||||||
|
cgmeth -> magicsys;
|
||||||
cgen -> ast;
|
cgen -> ast;
|
||||||
cgen -> astalgo;
|
cgen -> astalgo;
|
||||||
cgen -> strutils;
|
cgen -> strutils;
|
||||||
|
|
@ -419,6 +471,7 @@ cgen -> rodread;
|
||||||
cgen -> wordrecg;
|
cgen -> wordrecg;
|
||||||
cgen -> rnimsyn;
|
cgen -> rnimsyn;
|
||||||
cgen -> treetab;
|
cgen -> treetab;
|
||||||
|
cgen -> cgmeth;
|
||||||
ecmasgen -> ast;
|
ecmasgen -> ast;
|
||||||
ecmasgen -> astalgo;
|
ecmasgen -> astalgo;
|
||||||
ecmasgen -> strutils;
|
ecmasgen -> strutils;
|
||||||
|
|
@ -445,15 +498,6 @@ ecmasgen -> ccgutils;
|
||||||
ecmasgen -> wordrecg;
|
ecmasgen -> wordrecg;
|
||||||
ecmasgen -> rnimsyn;
|
ecmasgen -> rnimsyn;
|
||||||
ecmasgen -> rodread;
|
ecmasgen -> rodread;
|
||||||
ptmplsyn -> llstream;
|
|
||||||
ptmplsyn -> os;
|
|
||||||
ptmplsyn -> wordrecg;
|
|
||||||
ptmplsyn -> strutils;
|
|
||||||
ptmplsyn -> ast;
|
|
||||||
ptmplsyn -> astalgo;
|
|
||||||
ptmplsyn -> msgs;
|
|
||||||
ptmplsyn -> options;
|
|
||||||
ptmplsyn -> pnimsyn;
|
|
||||||
interact -> llstream;
|
interact -> llstream;
|
||||||
interact -> strutils;
|
interact -> strutils;
|
||||||
interact -> ropes;
|
interact -> ropes;
|
||||||
|
|
@ -481,6 +525,7 @@ transf -> ast;
|
||||||
transf -> astalgo;
|
transf -> astalgo;
|
||||||
transf -> trees;
|
transf -> trees;
|
||||||
transf -> treetab;
|
transf -> treetab;
|
||||||
|
transf -> evals;
|
||||||
transf -> msgs;
|
transf -> msgs;
|
||||||
transf -> os;
|
transf -> os;
|
||||||
transf -> idents;
|
transf -> idents;
|
||||||
|
|
@ -489,12 +534,13 @@ transf -> types;
|
||||||
transf -> passes;
|
transf -> passes;
|
||||||
transf -> semfold;
|
transf -> semfold;
|
||||||
transf -> magicsys;
|
transf -> magicsys;
|
||||||
|
transf -> cgmeth;
|
||||||
main -> llstream;
|
main -> llstream;
|
||||||
main -> strutils;
|
main -> strutils;
|
||||||
main -> ast;
|
main -> ast;
|
||||||
main -> astalgo;
|
main -> astalgo;
|
||||||
main -> scanner;
|
main -> scanner;
|
||||||
main -> pnimsyn;
|
main -> syntaxes;
|
||||||
main -> rnimsyn;
|
main -> rnimsyn;
|
||||||
main -> options;
|
main -> options;
|
||||||
main -> msgs;
|
main -> msgs;
|
||||||
|
|
@ -517,7 +563,6 @@ main -> extccomp;
|
||||||
main -> cgen;
|
main -> cgen;
|
||||||
main -> ecmasgen;
|
main -> ecmasgen;
|
||||||
main -> platform;
|
main -> platform;
|
||||||
main -> ptmplsyn;
|
|
||||||
main -> interact;
|
main -> interact;
|
||||||
main -> nimconf;
|
main -> nimconf;
|
||||||
main -> importer;
|
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
|
# Nimrod's Runtime Library
|
||||||
# (c) Copyright 2008 Andreas Rumpf
|
# (c) Copyright 2009 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
@ -52,12 +52,11 @@ const
|
||||||
|
|
||||||
proc newStringTable(keyValuePairs: openarray[string],
|
proc newStringTable(keyValuePairs: openarray[string],
|
||||||
mode: TStringTableMode = modeCaseSensitive): PStringTable =
|
mode: TStringTableMode = modeCaseSensitive): PStringTable =
|
||||||
var i: int
|
|
||||||
new(result)
|
new(result)
|
||||||
result.mode = mode
|
result.mode = mode
|
||||||
result.counter = 0
|
result.counter = 0
|
||||||
newSeq(result.data, startSize)
|
newSeq(result.data, startSize)
|
||||||
i = 0
|
var i = 0
|
||||||
while i < high(keyValuePairs):
|
while i < high(keyValuePairs):
|
||||||
put(result, keyValuePairs[i], keyValuePairs[i + 1])
|
put(result, keyValuePairs[i], keyValuePairs[i + 1])
|
||||||
inc(i, 2)
|
inc(i, 2)
|
||||||
|
|
@ -81,17 +80,14 @@ proc mustRehash(length, counter: int): bool =
|
||||||
proc length(t: PStringTable): int =
|
proc length(t: PStringTable): int =
|
||||||
result = t.counter
|
result = t.counter
|
||||||
|
|
||||||
const
|
|
||||||
EmptySeq = []
|
|
||||||
|
|
||||||
proc nextTry(h, maxHash: THash): THash =
|
proc nextTry(h, maxHash: THash): THash =
|
||||||
result = ((5 * h) + 1) and maxHash # For any initial h in range(maxHash), repeating that maxHash times
|
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
|
# generates each int in range(maxHash) exactly once (see any text on
|
||||||
# random-number generation for proof).
|
# random-number generation for proof).
|
||||||
|
|
||||||
proc RawGet(t: PStringTable, key: string): int =
|
proc RawGet(t: PStringTable, key: string): int =
|
||||||
var h: THash
|
var h = myhash(t, key) and high(t.data) # start with real hash value
|
||||||
h = myhash(t, key) and high(t.data) # start with real hash value
|
|
||||||
while not isNil(t.data[h].key):
|
while not isNil(t.data[h].key):
|
||||||
if mycmp(t, t.data[h].key, key):
|
if mycmp(t, t.data[h].key, key):
|
||||||
return h
|
return h
|
||||||
|
|
@ -99,8 +95,7 @@ proc RawGet(t: PStringTable, key: string): int =
|
||||||
result = - 1
|
result = - 1
|
||||||
|
|
||||||
proc get(t: PStringTable, key: string): string =
|
proc get(t: PStringTable, key: string): string =
|
||||||
var index: int
|
var index = RawGet(t, key)
|
||||||
index = RawGet(t, key)
|
|
||||||
if index >= 0: result = t.data[index].val
|
if index >= 0: result = t.data[index].val
|
||||||
else: result = ""
|
else: result = ""
|
||||||
|
|
||||||
|
|
@ -108,8 +103,7 @@ proc hasKey(t: PStringTable, key: string): bool =
|
||||||
result = rawGet(t, key) >= 0
|
result = rawGet(t, key) >= 0
|
||||||
|
|
||||||
proc RawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) =
|
proc RawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) =
|
||||||
var h: THash
|
var h = myhash(t, key) and high(data)
|
||||||
h = myhash(t, key) and high(data)
|
|
||||||
while not isNil(data[h].key):
|
while not isNil(data[h].key):
|
||||||
h = nextTry(h, high(data))
|
h = nextTry(h, high(data))
|
||||||
data[h].key = key
|
data[h].key = key
|
||||||
|
|
@ -123,8 +117,7 @@ proc Enlarge(t: PStringTable) =
|
||||||
swap(t.data, n)
|
swap(t.data, n)
|
||||||
|
|
||||||
proc Put(t: PStringTable, key, val: string) =
|
proc Put(t: PStringTable, key, val: string) =
|
||||||
var index: int
|
var index = RawGet(t, key)
|
||||||
index = RawGet(t, key)
|
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
t.data[index].val = val
|
t.data[index].val = val
|
||||||
else:
|
else:
|
||||||
|
|
@ -139,22 +132,18 @@ proc RaiseFormatException(s: string) =
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
proc getValue(t: PStringTable, flags: TFormatFlags, key: string): string =
|
proc getValue(t: PStringTable, flags: TFormatFlags, key: string): string =
|
||||||
if hasKey(t, key):
|
if hasKey(t, key): return get(t, key)
|
||||||
return get(t, key)
|
|
||||||
if useEnvironment in flags: result = os.getEnv(key)
|
if useEnvironment in flags: result = os.getEnv(key)
|
||||||
else: result = ""
|
else: result = ""
|
||||||
if (result == ""):
|
if result.len == 0:
|
||||||
if useKey in flags: result = '$' & key
|
if useKey in flags: result = '$' & key
|
||||||
elif not (useEmpty in flags): raiseFormatException(key)
|
elif not (useEmpty in flags): raiseFormatException(key)
|
||||||
|
|
||||||
proc `%`(f: string, t: PStringTable, flags: TFormatFlags = {}): string =
|
proc `%`(f: string, t: PStringTable, flags: TFormatFlags = {}): string =
|
||||||
const
|
const
|
||||||
PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\x80'..'\xFF'}
|
PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\x80'..'\xFF'}
|
||||||
var
|
|
||||||
i, j: int
|
|
||||||
key: string
|
|
||||||
result = ""
|
result = ""
|
||||||
i = 0
|
var i = 0
|
||||||
while i <= len(f) + 0 - 1:
|
while i <= len(f) + 0 - 1:
|
||||||
if f[i] == '$':
|
if f[i] == '$':
|
||||||
case f[i + 1]
|
case f[i + 1]
|
||||||
|
|
@ -162,15 +151,15 @@ proc `%`(f: string, t: PStringTable, flags: TFormatFlags = {}): string =
|
||||||
add(result, '$')
|
add(result, '$')
|
||||||
inc(i, 2)
|
inc(i, 2)
|
||||||
of '{':
|
of '{':
|
||||||
j = i + 1
|
var j = i + 1
|
||||||
while (j <= len(f) + 0 - 1) and (f[j] != '}'): inc(j)
|
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))
|
add(result, getValue(t, flags, key))
|
||||||
i = j + 1
|
i = j + 1
|
||||||
of 'a'..'z', 'A'..'Z', '\x80'..'\xFF', '_':
|
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)
|
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))
|
add(result, getValue(t, flags, key))
|
||||||
i = j
|
i = j
|
||||||
else:
|
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
|
return i
|
||||||
result = cpuNone
|
result = cpuNone
|
||||||
|
|
||||||
proc nimCPU(): cstring{.importc, noconv.}
|
#proc nimCPU(): cstring{.importc, noconv.}
|
||||||
proc nimOS(): 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
|
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 = ""
|
result = ""
|
||||||
|
|
||||||
proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
||||||
var
|
var c: int
|
||||||
le, r, y, t: PRope
|
var t = tree
|
||||||
c: int
|
|
||||||
t = tree
|
|
||||||
N.left = nil
|
N.left = nil
|
||||||
N.right = nil # reset to nil
|
N.right = nil # reset to nil
|
||||||
le = N
|
var le = N
|
||||||
r = N
|
var r = N
|
||||||
while true:
|
while true:
|
||||||
c = cmp(s, t.data)
|
c = cmp(s, t.data)
|
||||||
if c < 0:
|
if c < 0:
|
||||||
if (t.left != nil) and (s < t.left.data):
|
if (t.left != nil) and (s < t.left.data):
|
||||||
y = t.left
|
var y = t.left
|
||||||
t.left = y.right
|
t.left = y.right
|
||||||
y.right = t
|
y.right = t
|
||||||
t = y
|
t = y
|
||||||
|
|
@ -145,7 +143,7 @@ proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
||||||
t = t.left
|
t = t.left
|
||||||
elif c > 0:
|
elif c > 0:
|
||||||
if (t.right != nil) and (s > t.right.data):
|
if (t.right != nil) and (s > t.right.data):
|
||||||
y = t.right
|
var y = t.right
|
||||||
t.right = y.left
|
t.right = y.left
|
||||||
y.left = t
|
y.left = t
|
||||||
t = y
|
t = y
|
||||||
|
|
@ -165,14 +163,12 @@ proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
||||||
proc insertInCache(s: string, tree: PRope): PRope =
|
proc insertInCache(s: string, tree: PRope): PRope =
|
||||||
# Insert i into the tree t, unless it's already there.
|
# Insert i into the tree t, unless it's already there.
|
||||||
# Return a pointer to the resulting tree.
|
# Return a pointer to the resulting tree.
|
||||||
var
|
var t = tree
|
||||||
t: PRope
|
|
||||||
cmp: int
|
|
||||||
t = tree
|
|
||||||
if t == nil:
|
if t == nil:
|
||||||
result = newRope(s)
|
result = newRope(s)
|
||||||
if countCacheMisses: inc(misses)
|
if countCacheMisses: inc(misses)
|
||||||
return
|
return
|
||||||
|
var cmp: int
|
||||||
t = splay(s, t, cmp)
|
t = splay(s, t, cmp)
|
||||||
if cmp == 0:
|
if cmp == 0:
|
||||||
# We get here if it's already in the Tree
|
# We get here if it's already in the Tree
|
||||||
|
|
@ -216,8 +212,7 @@ proc toRope(s: string): PRope =
|
||||||
assert(RopeInvariant(result))
|
assert(RopeInvariant(result))
|
||||||
|
|
||||||
proc RopeSeqInsert(rs: var TRopeSeq, r: PRope, at: Natural) =
|
proc RopeSeqInsert(rs: var TRopeSeq, r: PRope, at: Natural) =
|
||||||
var length: int
|
var length = len(rs)
|
||||||
length = len(rs)
|
|
||||||
if at > length:
|
if at > length:
|
||||||
setlen(rs, at + 1)
|
setlen(rs, at + 1)
|
||||||
else:
|
else:
|
||||||
|
|
@ -241,12 +236,11 @@ proc con(a, b: PRope): PRope =
|
||||||
assert(RopeInvariant(result))
|
assert(RopeInvariant(result))
|
||||||
|
|
||||||
proc con(a: PRope, b: string): PRope =
|
proc con(a: PRope, b: string): PRope =
|
||||||
var r: PRope
|
|
||||||
assert(RopeInvariant(a))
|
assert(RopeInvariant(a))
|
||||||
if b == "":
|
if b == "":
|
||||||
result = a
|
result = a
|
||||||
else:
|
else:
|
||||||
r = toRope(b)
|
var r = toRope(b)
|
||||||
if a == nil:
|
if a == nil:
|
||||||
result = r
|
result = r
|
||||||
else:
|
else:
|
||||||
|
|
@ -257,12 +251,11 @@ proc con(a: PRope, b: string): PRope =
|
||||||
assert(RopeInvariant(result))
|
assert(RopeInvariant(result))
|
||||||
|
|
||||||
proc con(a: string, b: PRope): PRope =
|
proc con(a: string, b: PRope): PRope =
|
||||||
var r: PRope
|
|
||||||
assert(RopeInvariant(b))
|
assert(RopeInvariant(b))
|
||||||
if a == "":
|
if a == "":
|
||||||
result = b
|
result = b
|
||||||
else:
|
else:
|
||||||
r = toRope(a)
|
var r = toRope(a)
|
||||||
if b == nil:
|
if b == nil:
|
||||||
result = r
|
result = r
|
||||||
else:
|
else:
|
||||||
|
|
@ -295,21 +288,6 @@ proc prepend(a: var PRope, b: PRope) =
|
||||||
a = con(b, a)
|
a = con(b, a)
|
||||||
assert(RopeInvariant(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) =
|
proc WriteRopeRec(f: var tfile, c: PRope) =
|
||||||
assert(RopeInvariant(c))
|
assert(RopeInvariant(c))
|
||||||
if c == nil: return
|
if c == nil: return
|
||||||
|
|
@ -320,16 +298,11 @@ proc WriteRopeRec(f: var tfile, c: PRope) =
|
||||||
writeRopeRec(f, c.right)
|
writeRopeRec(f, c.right)
|
||||||
|
|
||||||
proc newWriteRopeRec(f: var tfile, c: PRope) =
|
proc newWriteRopeRec(f: var tfile, c: PRope) =
|
||||||
var
|
var stack: TRopeSeq = @[c]
|
||||||
stack: TRopeSeq
|
|
||||||
it: PRope
|
|
||||||
assert(RopeInvariant(c))
|
|
||||||
initStack(stack)
|
|
||||||
push(stack, c)
|
|
||||||
while len(stack) > 0:
|
while len(stack) > 0:
|
||||||
it = pop(stack)
|
var it = pop(stack)
|
||||||
while it.data == nil:
|
while it.data == nil:
|
||||||
push(stack, it.right)
|
add(stack, it.right)
|
||||||
it = it.left
|
it = it.left
|
||||||
assert(it != nil)
|
assert(it != nil)
|
||||||
assert(it.data != nil)
|
assert(it.data != nil)
|
||||||
|
|
@ -355,15 +328,11 @@ proc recRopeToStr(result: var string, resultLen: var int, p: PRope) =
|
||||||
assert(resultLen <= len(result))
|
assert(resultLen <= len(result))
|
||||||
|
|
||||||
proc newRecRopeToStr(result: var string, resultLen: var int, r: PRope) =
|
proc newRecRopeToStr(result: var string, resultLen: var int, r: PRope) =
|
||||||
var
|
var stack: TRopeSeq = @[r]
|
||||||
stack: TRopeSeq
|
|
||||||
it: PRope
|
|
||||||
initStack(stack)
|
|
||||||
push(stack, r)
|
|
||||||
while len(stack) > 0:
|
while len(stack) > 0:
|
||||||
it = pop(stack)
|
var it = pop(stack)
|
||||||
while it.data == nil:
|
while it.data == nil:
|
||||||
push(stack, it.right)
|
add(stack, it.right)
|
||||||
it = it.left
|
it = it.left
|
||||||
assert(it.data != nil)
|
assert(it.data != nil)
|
||||||
CopyMem(addr(result[resultLen + 0]), addr(it.data[0]), it.length)
|
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))
|
assert(resultLen <= len(result))
|
||||||
|
|
||||||
proc ropeToStr(p: PRope): string =
|
proc ropeToStr(p: PRope): string =
|
||||||
var resultLen: int
|
|
||||||
assert(RopeInvariant(p))
|
|
||||||
if p == nil:
|
if p == nil:
|
||||||
result = ""
|
result = ""
|
||||||
else:
|
else:
|
||||||
result = newString(p.length)
|
result = newString(p.length)
|
||||||
resultLen = 0
|
var resultLen = 0
|
||||||
newRecRopeToStr(result, resultLen, p)
|
newRecRopeToStr(result, resultLen, p)
|
||||||
|
|
||||||
proc ropef(frmt: TFormatStr, args: openarray[PRope]): PRope =
|
proc ropef(frmt: TFormatStr, args: openarray[PRope]): PRope =
|
||||||
|
|
@ -426,11 +393,10 @@ const
|
||||||
bufSize = 1024 # 1 KB is reasonable
|
bufSize = 1024 # 1 KB is reasonable
|
||||||
|
|
||||||
proc auxRopeEqualsFile(r: PRope, bin: var tfile, buf: Pointer): bool =
|
proc auxRopeEqualsFile(r: PRope, bin: var tfile, buf: Pointer): bool =
|
||||||
var readBytes: int
|
|
||||||
if (r.data != nil):
|
if (r.data != nil):
|
||||||
if r.length > bufSize:
|
if r.length > bufSize:
|
||||||
internalError("ropes: token too long")
|
internalError("ropes: token too long")
|
||||||
readBytes = readBuffer(bin, buf, r.length)
|
var readBytes = readBuffer(bin, buf, r.length)
|
||||||
result = (readBytes == r.length) and
|
result = (readBytes == r.length) and
|
||||||
equalMem(buf, addr(r.data[0]), r.length) # BUGFIX
|
equalMem(buf, addr(r.data[0]), r.length) # BUGFIX
|
||||||
else:
|
else:
|
||||||
|
|
@ -438,13 +404,11 @@ proc auxRopeEqualsFile(r: PRope, bin: var tfile, buf: Pointer): bool =
|
||||||
if result: result = auxRopeEqualsFile(r.right, bin, buf)
|
if result: result = auxRopeEqualsFile(r.right, bin, buf)
|
||||||
|
|
||||||
proc RopeEqualsFile(r: PRope, f: string): bool =
|
proc RopeEqualsFile(r: PRope, f: string): bool =
|
||||||
var
|
var bin: tfile
|
||||||
bin: tfile
|
|
||||||
buf: Pointer
|
|
||||||
result = open(bin, f)
|
result = open(bin, f)
|
||||||
if not result:
|
if not result:
|
||||||
return # not equal if file does not exist
|
return # not equal if file does not exist
|
||||||
buf = alloc(BufSize)
|
var buf = alloc(BufSize)
|
||||||
result = auxRopeEqualsFile(r, bin, buf)
|
result = auxRopeEqualsFile(r, bin, buf)
|
||||||
if result:
|
if result:
|
||||||
result = readBuffer(bin, buf, bufSize) == 0 # really at the end of file?
|
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)
|
result = crcFromRopeAux(r.right, result)
|
||||||
|
|
||||||
proc newCrcFromRopeAux(r: PRope, startVal: TCrc32): TCrc32 =
|
proc newCrcFromRopeAux(r: PRope, startVal: TCrc32): TCrc32 =
|
||||||
var
|
var stack: TRopeSeq = @[r]
|
||||||
stack: TRopeSeq
|
|
||||||
it: PRope
|
|
||||||
L, i: int
|
|
||||||
initStack(stack)
|
|
||||||
push(stack, r)
|
|
||||||
result = startVal
|
result = startVal
|
||||||
while len(stack) > 0:
|
while len(stack) > 0:
|
||||||
it = pop(stack)
|
var it = pop(stack)
|
||||||
while it.data == nil:
|
while it.data == nil:
|
||||||
push(stack, it.right)
|
add(stack, it.right)
|
||||||
it = it.left
|
it = it.left
|
||||||
assert(it.data != nil)
|
assert(it.data != nil)
|
||||||
i = 0
|
var i = 0
|
||||||
L = len(it.data) + 0
|
var L = len(it.data)
|
||||||
while i < L:
|
while i < L:
|
||||||
result = updateCrc32(it.data[i], result)
|
result = updateCrc32(it.data[i], result)
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
@ -493,5 +452,4 @@ proc writeRopeIfNotEqual(r: PRope, filename: string): bool =
|
||||||
else:
|
else:
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
new(N)
|
new(N) # init dummy node for splay algorithm
|
||||||
# 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
Loading…
Add table
Add a link
Reference in a new issue