lazy paths for Babel support

This commit is contained in:
Araq 2012-12-11 20:06:15 +01:00
commit c98696d742
8 changed files with 57 additions and 23 deletions

View file

@ -58,22 +58,22 @@ iterator chosen(packages: PStringTable): string =
let res = if val == latest: key else: key & '-' & val let res = if val == latest: key else: key & '-' & val
yield res yield res
proc addBabelPath(p: string, info: TLineInfo) =
if not contains(options.searchPaths, p):
Message(info, hintPath, p)
lists.PrependStr(options.lazyPaths, p)
proc addPathWithNimFiles(p: string, info: TLineInfo) = proc addPathWithNimFiles(p: string, info: TLineInfo) =
proc hasNimFile(dir: string): bool = proc hasNimFile(dir: string): bool =
for kind, path in walkDir(dir): for kind, path in walkDir(dir):
if kind == pcFile and path.endsWith(".nim"): if kind == pcFile and path.endsWith(".nim"):
return true result = true
break
proc addPath(p: string) =
if not contains(options.searchPaths, p):
Message(info, hintPath, p)
lists.PrependStr(options.searchPaths, p)
if hasNimFile(p): if hasNimFile(p):
addPath(p) addBabelPath(p, info)
else: else:
for kind, p2 in walkDir(p): for kind, p2 in walkDir(p):
if hasNimFile(p2): addPath(p2) if hasNimFile(p2): addBabelPath(p2, info)
proc addPathRec(dir: string, info: TLineInfo) = proc addPathRec(dir: string, info: TLineInfo) =
var packages = newStringTable(modeStyleInsensitive) var packages = newStringTable(modeStyleInsensitive)
@ -87,4 +87,4 @@ proc addPathRec(dir: string, info: TLineInfo) =
proc babelPath*(path: string, info: TLineInfo) = proc babelPath*(path: string, info: TLineInfo) =
addPathRec(path, info) addPathRec(path, info)
addPath(path, info) addBabelPath(path, info)

View file

@ -221,6 +221,7 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
let path = processPath(arg) let path = processPath(arg)
lists.ExcludeStr(options.searchPaths, path) lists.ExcludeStr(options.searchPaths, path)
lists.ExcludeStr(options.lazyPaths, path)
of "nimcache": of "nimcache":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
options.nimcacheDir = processPath(arg) options.nimcacheDir = processPath(arg)

View file

@ -90,6 +90,15 @@ proc Remove*(list: var TLinkedList, entry: PListEntry) =
if entry.next != nil: entry.next.prev = entry.prev if entry.next != nil: entry.next.prev = entry.prev
if entry.prev != nil: entry.prev.next = entry.next if entry.prev != nil: entry.prev.next = entry.next
proc bringToFront*(list: var TLinkedList, entry: PListEntry) =
if entry == list.head: return
if entry == list.tail: list.tail = entry.prev
if entry.next != nil: entry.next.prev = entry.prev
if entry.prev != nil: entry.prev.next = entry.next
entry.prev = nil
entry.next = list.head
list.head = entry
proc ExcludeStr*(list: var TLinkedList, data: string) = proc ExcludeStr*(list: var TLinkedList, data: string) =
var it = list.head var it = list.head
while it != nil: while it != nil:
@ -99,6 +108,6 @@ proc ExcludeStr*(list: var TLinkedList, data: string) =
proc Find*(list: TLinkedList, fn: TCompareProc, closure: Pointer): PListEntry = proc Find*(list: TLinkedList, fn: TCompareProc, closure: Pointer): PListEntry =
result = list.head result = list.head
while result != nil: while result != nil:
if fn(result, closure): return if fn(result, closure): return
result = result.next result = result.next

View file

@ -279,11 +279,11 @@ proc MainCommand =
gCmd = cmdGenDepend gCmd = cmdGenDepend
wantMainModule() wantMainModule()
CommandGenDepend() CommandGenDepend()
of "dump": of "dump":
gCmd = cmdDump gCmd = cmdDump
condsyms.ListSymbols() condsyms.ListSymbols()
for it in iterSearchPath(): MsgWriteln(it) for it in iterSearchPath(searchPaths): MsgWriteln(it)
of "check": of "check":
gCmd = cmdCheck gCmd = cmdCheck
wantMainModule() wantMainModule()
CommandCheck() CommandCheck()

View file

@ -88,7 +88,7 @@ var
optPatterns} optPatterns}
gGlobalOptions*: TGlobalOptions = {optRefcGC, optThreadAnalysis} gGlobalOptions*: TGlobalOptions = {optRefcGC, optThreadAnalysis}
gExitcode*: int8 gExitcode*: int8
searchPaths*: TLinkedList searchPaths*, lazyPaths*: TLinkedList
outFile*: string = "" outFile*: string = ""
headerFile*: string = "" headerFile*: string = ""
gCmd*: TCommands = cmdNone # the command gCmd*: TCommands = cmdNone # the command
@ -194,22 +194,37 @@ proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
result = joinPath(subdir, tail) result = joinPath(subdir, tail)
#echo "completeGeneratedFilePath(", f, ") = ", result #echo "completeGeneratedFilePath(", f, ") = ", result
iterator iterSearchPath*(): string = iterator iterSearchPath*(SearchPaths: TLinkedList): string =
var it = PStrEntry(SearchPaths.head) var it = PStrEntry(SearchPaths.head)
while it != nil: while it != nil:
yield it.data yield it.data
it = PStrEntry(it.Next) it = PStrEntry(it.Next)
proc rawFindFile(f: string): string = proc rawFindFile(f: string): string =
for it in iterSearchPath(): for it in iterSearchPath(SearchPaths):
result = JoinPath(it, f) result = JoinPath(it, f)
if ExistsFile(result): if existsFile(result):
return result.canonicalizePath return result.canonicalizePath
result = "" result = ""
proc rawFindFile2(f: string): string =
var it = PStrEntry(lazyPaths.head)
while it != nil:
result = JoinPath(it.data, f)
if existsFile(result):
bringToFront(lazyPaths, it)
return result.canonicalizePath
it = PStrEntry(it.Next)
result = ""
proc FindFile*(f: string): string {.procvar.} = proc FindFile*(f: string): string {.procvar.} =
result = rawFindFile(f) result = f.rawFindFile
if len(result) == 0: result = rawFindFile(toLower(f)) if result.len == 0:
result = f.toLower.rawFindFile
if result.len == 0:
result = f.rawFindFile2
if result.len == 0:
result = f.toLower.rawFindFile2
proc findModule*(modulename: string): string {.inline.} = proc findModule*(modulename: string): string {.inline.} =
# returns path to module # returns path to module

View file

@ -237,6 +237,15 @@ proc addToArgList(result, n: PNode) =
else: else:
for i in 0 .. <n.len: result.add(n.sons[i]) for i in 0 .. <n.len: result.add(n.sons[i])
when false:
proc procPatternMatches*(c: PContext, s: PSym, n: PNode): bool =
## for AST-based overloading:
var ctx: TPatternContext
ctx.owner = s
ctx.c = c
ctx.formals = sonsLen(s.typ)-1
result = matches(ctx, s.ast.sons[patternPos], n)
proc applyRule*(c: PContext, s: PSym, n: PNode): PNode = proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
## returns a tree to semcheck if the rule triggered; nil otherwise ## returns a tree to semcheck if the rule triggered; nil otherwise
var ctx: TPatternContext var ctx: TPatternContext

View file

@ -33,7 +33,7 @@ path="$lib/ecmas"
path="$lib/pure/unidecode" path="$lib/pure/unidecode"
@if nimbabel: @if nimbabel:
babelpath="$home/.babel/libs/" babelpath="$home/babeltest/"
@end @end
@if release or quick: @if release or quick:

View file

@ -4005,7 +4005,7 @@ The following example how some form of hoisting can be implemented:
The ``optPeg`` template optimizes the case of a peg constructor with a string The ``optPeg`` template optimizes the case of a peg constructor with a string
literal, so that the pattern will only be parsed once at program startup and literal, so that the pattern will only be parsed once at program startup and
stored in global ``gl`` which is then re-used. This optimization is called stored in a global ``gl`` which is then re-used. This optimization is called
hoisting because it is comparable to classical loop hoisting. hoisting because it is comparable to classical loop hoisting.