mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-10 06:54:16 +00:00
lazy paths for Babel support
This commit is contained in:
@@ -58,22 +58,22 @@ iterator chosen(packages: PStringTable): string =
|
||||
let res = if val == latest: key else: key & '-' & val
|
||||
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 hasNimFile(dir: string): bool =
|
||||
for kind, path in walkDir(dir):
|
||||
if kind == pcFile and path.endsWith(".nim"):
|
||||
return true
|
||||
|
||||
proc addPath(p: string) =
|
||||
if not contains(options.searchPaths, p):
|
||||
Message(info, hintPath, p)
|
||||
lists.PrependStr(options.searchPaths, p)
|
||||
|
||||
result = true
|
||||
break
|
||||
if hasNimFile(p):
|
||||
addPath(p)
|
||||
addBabelPath(p, info)
|
||||
else:
|
||||
for kind, p2 in walkDir(p):
|
||||
if hasNimFile(p2): addPath(p2)
|
||||
if hasNimFile(p2): addBabelPath(p2, info)
|
||||
|
||||
proc addPathRec(dir: string, info: TLineInfo) =
|
||||
var packages = newStringTable(modeStyleInsensitive)
|
||||
@@ -87,4 +87,4 @@ proc addPathRec(dir: string, info: TLineInfo) =
|
||||
|
||||
proc babelPath*(path: string, info: TLineInfo) =
|
||||
addPathRec(path, info)
|
||||
addPath(path, info)
|
||||
addBabelPath(path, info)
|
||||
|
||||
@@ -221,6 +221,7 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
|
||||
expectArg(switch, arg, pass, info)
|
||||
let path = processPath(arg)
|
||||
lists.ExcludeStr(options.searchPaths, path)
|
||||
lists.ExcludeStr(options.lazyPaths, path)
|
||||
of "nimcache":
|
||||
expectArg(switch, arg, pass, info)
|
||||
options.nimcacheDir = processPath(arg)
|
||||
|
||||
@@ -90,6 +90,15 @@ proc Remove*(list: var TLinkedList, entry: PListEntry) =
|
||||
if entry.next != nil: entry.next.prev = entry.prev
|
||||
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) =
|
||||
var it = list.head
|
||||
while it != nil:
|
||||
@@ -99,6 +108,6 @@ proc ExcludeStr*(list: var TLinkedList, data: string) =
|
||||
|
||||
proc Find*(list: TLinkedList, fn: TCompareProc, closure: Pointer): PListEntry =
|
||||
result = list.head
|
||||
while result != nil:
|
||||
while result != nil:
|
||||
if fn(result, closure): return
|
||||
result = result.next
|
||||
|
||||
@@ -279,11 +279,11 @@ proc MainCommand =
|
||||
gCmd = cmdGenDepend
|
||||
wantMainModule()
|
||||
CommandGenDepend()
|
||||
of "dump":
|
||||
of "dump":
|
||||
gCmd = cmdDump
|
||||
condsyms.ListSymbols()
|
||||
for it in iterSearchPath(): MsgWriteln(it)
|
||||
of "check":
|
||||
for it in iterSearchPath(searchPaths): MsgWriteln(it)
|
||||
of "check":
|
||||
gCmd = cmdCheck
|
||||
wantMainModule()
|
||||
CommandCheck()
|
||||
|
||||
@@ -88,7 +88,7 @@ var
|
||||
optPatterns}
|
||||
gGlobalOptions*: TGlobalOptions = {optRefcGC, optThreadAnalysis}
|
||||
gExitcode*: int8
|
||||
searchPaths*: TLinkedList
|
||||
searchPaths*, lazyPaths*: TLinkedList
|
||||
outFile*: string = ""
|
||||
headerFile*: string = ""
|
||||
gCmd*: TCommands = cmdNone # the command
|
||||
@@ -194,22 +194,37 @@ proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
|
||||
result = joinPath(subdir, tail)
|
||||
#echo "completeGeneratedFilePath(", f, ") = ", result
|
||||
|
||||
iterator iterSearchPath*(): string =
|
||||
iterator iterSearchPath*(SearchPaths: TLinkedList): string =
|
||||
var it = PStrEntry(SearchPaths.head)
|
||||
while it != nil:
|
||||
while it != nil:
|
||||
yield it.data
|
||||
it = PStrEntry(it.Next)
|
||||
|
||||
proc rawFindFile(f: string): string =
|
||||
for it in iterSearchPath():
|
||||
for it in iterSearchPath(SearchPaths):
|
||||
result = JoinPath(it, f)
|
||||
if ExistsFile(result):
|
||||
if existsFile(result):
|
||||
return result.canonicalizePath
|
||||
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.} =
|
||||
result = rawFindFile(f)
|
||||
if len(result) == 0: result = rawFindFile(toLower(f))
|
||||
result = f.rawFindFile
|
||||
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.} =
|
||||
# returns path to module
|
||||
|
||||
@@ -237,6 +237,15 @@ proc addToArgList(result, n: PNode) =
|
||||
else:
|
||||
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 =
|
||||
## returns a tree to semcheck if the rule triggered; nil otherwise
|
||||
var ctx: TPatternContext
|
||||
|
||||
@@ -33,7 +33,7 @@ path="$lib/ecmas"
|
||||
path="$lib/pure/unidecode"
|
||||
|
||||
@if nimbabel:
|
||||
babelpath="$home/.babel/libs/"
|
||||
babelpath="$home/babeltest/"
|
||||
@end
|
||||
|
||||
@if release or quick:
|
||||
|
||||
@@ -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
|
||||
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.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user