summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-12-11 20:06:15 +0100
committerAraq <rumpf_a@web.de>2012-12-11 20:06:15 +0100
commitc98696d7428346b53c8998bf8fab77fe08830e2e (patch)
treef28cfd250d0b64fe5c5259908df52fdf5d9c8366 /compiler
parenta840a4ce53c2344f77c6e07b4f8cbed0af2820dd (diff)
downloadNim-c98696d7428346b53c8998bf8fab77fe08830e2e.tar.gz
lazy paths for Babel support
Diffstat (limited to 'compiler')
-rw-r--r--compiler/babelcmd.nim20
-rwxr-xr-xcompiler/commands.nim1
-rwxr-xr-xcompiler/lists.nim11
-rwxr-xr-xcompiler/main.nim6
-rwxr-xr-xcompiler/options.nim29
-rw-r--r--compiler/patterns.nim9
6 files changed, 55 insertions, 21 deletions
diff --git a/compiler/babelcmd.nim b/compiler/babelcmd.nim
index 97d3bcf6c..956c6a6ae 100644
--- a/compiler/babelcmd.nim
+++ b/compiler/babelcmd.nim
@@ -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)
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 4a72e25f3..4b9a47d37 100755
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -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)
diff --git a/compiler/lists.nim b/compiler/lists.nim
index 9da4db177..67b32f919 100755
--- a/compiler/lists.nim
+++ b/compiler/lists.nim
@@ -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
diff --git a/compiler/main.nim b/compiler/main.nim
index dabd5309b..edd4fda68 100755
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -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()
diff --git a/compiler/options.nim b/compiler/options.nim
index 42fca1ad1..b8e65f8e3 100755
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -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
diff --git a/compiler/patterns.nim b/compiler/patterns.nim
index b7792100f..ff7f18ac0 100644
--- a/compiler/patterns.nim
+++ b/compiler/patterns.nim
@@ -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