summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-05-04 19:10:12 +0200
committerAraq <rumpf_a@web.de>2013-05-04 19:10:12 +0200
commit23bd3ccd8bc1b6aae931a3754ad478849c3be82d (patch)
treef96245ae0b14225ba2f008d7949ce2b07e436ea7 /compiler
parentf8af7ed6b46d045b82b5b70370846fe857b5a39d (diff)
parent05fd46cdd1ce26b714888182ab69dcf2cd3d6ed2 (diff)
downloadNim-23bd3ccd8bc1b6aae931a3754ad478849c3be82d.tar.gz
Merge branch 'master' into newparser
Diffstat (limited to 'compiler')
-rw-r--r--compiler/babelcmd.nim4
-rw-r--r--compiler/ccgmerge.nim18
-rw-r--r--compiler/commands.nim7
-rw-r--r--compiler/condsyms.nim10
-rw-r--r--compiler/evals.nim4
-rw-r--r--compiler/lexer.nim16
-rw-r--r--compiler/main.nim40
-rw-r--r--compiler/msgs.nim5
-rw-r--r--compiler/nimlexbase.nim (renamed from compiler/lexbase.nim)0
-rw-r--r--compiler/nimsets.nim4
-rw-r--r--compiler/options.nim4
-rw-r--r--compiler/parsecfg.nim2
-rw-r--r--compiler/semmagic.nim3
-rw-r--r--compiler/service.nim3
14 files changed, 79 insertions, 41 deletions
diff --git a/compiler/babelcmd.nim b/compiler/babelcmd.nim
index 956c6a6ae..b67a26040 100644
--- a/compiler/babelcmd.nim
+++ b/compiler/babelcmd.nim
@@ -60,7 +60,7 @@ iterator chosen(packages: PStringTable): string =
 
 proc addBabelPath(p: string, info: TLineInfo) =
   if not contains(options.searchPaths, p):
-    Message(info, hintPath, p)
+    if gVerbosity >= 1: Message(info, hintPath, p)
     lists.PrependStr(options.lazyPaths, p)
 
 proc addPathWithNimFiles(p: string, info: TLineInfo) =
@@ -83,7 +83,7 @@ proc addPathRec(dir: string, info: TLineInfo) =
     if k == pcDir and p[pos] != '.':
       addPackage(packages, p)
   for p in packages.chosen:
-    addPathWithNimFiles(p, info)
+    addBabelPath(p, info)
 
 proc babelPath*(path: string, info: TLineInfo) =
   addPathRec(path, info)
diff --git a/compiler/ccgmerge.nim b/compiler/ccgmerge.nim
index 751e507e9..c6c294b97 100644
--- a/compiler/ccgmerge.nim
+++ b/compiler/ccgmerge.nim
@@ -11,7 +11,7 @@
 ## is needed for incremental compilation.
 
 import
-  ast, astalgo, ropes, options, strutils, lexbase, msgs, cgendata, rodutils,
+  ast, astalgo, ropes, options, strutils, nimlexbase, msgs, cgendata, rodutils,
   intsets, platform, llstream
 
 # Careful! Section marks need to contain a tabulator so that they cannot
@@ -119,8 +119,8 @@ proc skipWhite(L: var TBaseLexer) =
   var pos = L.bufpos
   while true:
     case ^pos
-    of CR: pos = lexbase.HandleCR(L, pos)
-    of LF: pos = lexbase.HandleLF(L, pos)
+    of CR: pos = nimlexbase.HandleCR(L, pos)
+    of LF: pos = nimlexbase.HandleLF(L, pos)
     of ' ': inc pos
     else: break
   L.bufpos = pos
@@ -129,8 +129,8 @@ proc skipUntilCmd(L: var TBaseLexer) =
   var pos = L.bufpos
   while true:
     case ^pos
-    of CR: pos = lexbase.HandleCR(L, pos)
-    of LF: pos = lexbase.HandleLF(L, pos)
+    of CR: pos = nimlexbase.HandleCR(L, pos)
+    of LF: pos = nimlexbase.HandleLF(L, pos)
     of '\0': break
     of '/': 
       if ^(pos+1) == '*' and ^(pos+2) == '\t':
@@ -153,11 +153,11 @@ when false:
     while true:
       case buf[pos]
       of CR:
-        pos = lexbase.HandleCR(L, pos)
+        pos = nimlexbase.HandleCR(L, pos)
         buf = L.buf
         result.data.add(tnl)
       of LF:
-        pos = lexbase.HandleLF(L, pos)
+        pos = nimlexbase.HandleLF(L, pos)
         buf = L.buf
         result.data.add(tnl)
       of '\0':
@@ -179,11 +179,11 @@ proc readVerbatimSection(L: var TBaseLexer): PRope =
   while true:
     case buf[pos]
     of CR:
-      pos = lexbase.HandleCR(L, pos)
+      pos = nimlexbase.HandleCR(L, pos)
       buf = L.buf
       r.add(tnl)
     of LF:
-      pos = lexbase.HandleLF(L, pos)
+      pos = nimlexbase.HandleLF(L, pos)
       buf = L.buf
       r.add(tnl)
     of '\0':
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 8b03dfec4..27da03bbe 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -197,8 +197,11 @@ proc testCompileOption*(switch: string, info: TLineInfo): bool =
   else: InvalidCmdLineOption(passCmd1, switch, info)
   
 proc processPath(path: string, notRelativeToProj = false): string =
-  let p = if notRelativeToProj or os.isAbsolute(path) or '$' in path: path 
-          else: options.gProjectPath / path
+  let p = if notRelativeToProj or os.isAbsolute(path) or
+              '$' in path or path[0] == '.': 
+            path 
+          else:
+            options.gProjectPath / path
   result = UnixToNativePath(p % ["nimrod", getPrefixDir(), "lib", libpath,
     "home", removeTrailingDirSep(os.getHomeDir()),
     "projectname", options.gProjectName,
diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim
index 17366f6e9..be6cb9875 100644
--- a/compiler/condsyms.nim
+++ b/compiler/condsyms.nim
@@ -10,7 +10,7 @@
 # This module handles the conditional symbols.
 
 import 
-  ast, astalgo, msgs, hashes, platform, strutils, idents
+  ast, astalgo, hashes, platform, strutils, idents
 
 var gSymbols*: TStrTable
 
@@ -35,14 +35,12 @@ proc isDefined*(symbol: PIdent): bool =
 proc isDefined*(symbol: string): bool = 
   result = isDefined(getIdent(symbol))
 
-proc ListSymbols*() = 
+iterator definedSymbolNames*: string =
   var it: TTabIter
   var s = InitTabIter(it, gSymbols)
-  OutWriteln("-- List of currently defined symbols --")
-  while s != nil: 
-    if s.position == 1: OutWriteln(s.name.s)
+  while s != nil:
+    if s.position == 1: yield s.name.s
     s = nextIter(it, gSymbols)
-  OutWriteln("-- End of list --")
 
 proc countDefinedSymbols*(): int = 
   var it: TTabIter
diff --git a/compiler/evals.nim b/compiler/evals.nim
index 2a9fae5f0..3f5b7887a 100644
--- a/compiler/evals.nim
+++ b/compiler/evals.nim
@@ -1099,7 +1099,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
     result = evalAux(c, n.sons[2], {efLValue})
     if isSpecial(result): return 
     addSon(a, result)
-    result = emptyNode
+    result = a
   of mNAddMultiple: 
     result = evalAux(c, n.sons[1], {efLValue})
     if isSpecial(result): return 
@@ -1107,7 +1107,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
     result = evalAux(c, n.sons[2], {efLValue})
     if isSpecial(result): return 
     for i in countup(0, sonsLen(result) - 1): addSon(a, result.sons[i])
-    result = emptyNode
+    result = a
   of mNDel: 
     result = evalAux(c, n.sons[1], {efLValue})
     if isSpecial(result): return 
diff --git a/compiler/lexer.nim b/compiler/lexer.nim
index 93649c888..6660ff65c 100644
--- a/compiler/lexer.nim
+++ b/compiler/lexer.nim
@@ -16,7 +16,7 @@
 # DOS or Macintosh text files, even when it is not the native format.
 
 import 
-  hashes, options, msgs, strutils, platform, idents, lexbase, llstream, 
+  hashes, options, msgs, strutils, platform, idents, nimlexbase, llstream,
   wordrecg
 
 const 
@@ -508,10 +508,10 @@ proc HandleCRLF(L: var TLexer, pos: int): int =
   case L.buf[pos]
   of CR:
     registerLine()
-    result = lexbase.HandleCR(L, pos)
+    result = nimlexbase.HandleCR(L, pos)
   of LF:
     registerLine()
-    result = lexbase.HandleLF(L, pos)
+    result = nimlexbase.HandleLF(L, pos)
   else: result = pos
   
 proc getString(L: var TLexer, tok: var TToken, rawMode: bool) = 
@@ -537,7 +537,7 @@ proc getString(L: var TLexer, tok: var TToken, rawMode: bool) =
         pos = HandleCRLF(L, pos)
         buf = L.buf
         add(tok.literal, tnl)
-      of lexbase.EndOfFile: 
+      of nimlexbase.EndOfFile: 
         var line2 = L.linenumber
         L.LineNumber = line
         lexMessagePos(L, errClosingTripleQuoteExpected, L.lineStart)
@@ -559,7 +559,7 @@ proc getString(L: var TLexer, tok: var TToken, rawMode: bool) =
         else:
           inc(pos) # skip '"'
           break
-      elif c in {CR, LF, lexbase.EndOfFile}: 
+      elif c in {CR, LF, nimlexbase.EndOfFile}: 
         lexMessage(L, errClosingQuoteExpected)
         break 
       elif (c == '\\') and not rawMode: 
@@ -640,7 +640,7 @@ proc scanComment(L: var TLexer, tok: var TToken) =
   var col = getColNumber(L, pos)
   while true:
     var lastBackslash = -1
-    while buf[pos] notin {CR, LF, lexbase.EndOfFile}:
+    while buf[pos] notin {CR, LF, nimlexbase.EndOfFile}:
       if buf[pos] == '\\': lastBackslash = pos+1
       add(tok.literal, buf[pos])
       inc(pos)
@@ -648,7 +648,7 @@ proc scanComment(L: var TLexer, tok: var TToken) =
       # a backslash is a continuation character if only followed by spaces
       # plus a newline:
       while buf[lastBackslash] == ' ': inc(lastBackslash)
-      if buf[lastBackslash] notin {CR, LF, lexbase.EndOfFile}:
+      if buf[lastBackslash] notin {CR, LF, nimlexbase.EndOfFile}:
         # false positive:
         lastBackslash = -1
 
@@ -795,7 +795,7 @@ proc rawGetTok(L: var TLexer, tok: var TToken) =
     else:
       if c in OpChars: 
         getOperator(L, tok)
-      elif c == lexbase.EndOfFile:
+      elif c == nimlexbase.EndOfFile:
         tok.toktype = tkEof
         tok.indent = 0
       else:
diff --git a/compiler/main.nim b/compiler/main.nim
index b5186ba6c..46ef65e81 100644
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -14,7 +14,7 @@ import
   llstream, strutils, ast, astalgo, lexer, syntaxes, renderer, options, msgs, 
   os, lists, condsyms, rodread, rodwrite, ropes, trees, times,
   wordrecg, sem, semdata, idents, passes, docgen, extccomp,
-  cgen, jsgen, cgendata,
+  cgen, jsgen, cgendata, json, nversion,
   platform, nimconf, importer, passaux, depends, evals, types, idgen,
   tables, docgen2, service, magicsys, parser, crc, ccgutils
 
@@ -392,6 +392,15 @@ proc wantMainModule =
 
   gProjectMainIdx = addFileExt(gProjectFull, nimExt).fileInfoIdx
 
+proc requireMainModuleOption =
+  if optMainModule.len == 0:
+    Fatal(gCmdLineInfo, errMainModuleMustBeSpecified)
+  else:
+    gProjectName = optMainModule
+    gProjectFull = gProjectPath / gProjectName
+
+  gProjectMainIdx = addFileExt(gProjectFull, nimExt).fileInfoIdx
+
 proc resetMemory =
   resetCompilationLists()
   ccgutils.resetCaches()
@@ -529,9 +538,30 @@ proc MainCommand =
     wantMainModule()
     CommandGenDepend()
   of "dump":
-    gCmd = cmdDump
-    condsyms.ListSymbols()
-    for it in iterSearchPath(searchPaths): MsgWriteln(it)
+    gcmd = cmdDump
+    if getconfigvar("dump.format") == "json":
+      requireMainModuleOption()
+
+      var definedSymbols = newJArray()
+      for s in definedSymbolNames(): definedSymbols.elems.add(%s)
+
+      var libpaths = newJArray()
+      for dir in itersearchpath(searchpaths): libpaths.elems.add(%dir)
+
+      var dumpdata = % [
+        (key: "version", val: %VersionAsString),
+        (key: "project_path", val: %gProjectFull),
+        (key: "defined_symbols", val: definedSymbols),
+        (key: "lib_paths", val: libpaths)
+      ]
+
+      outWriteLn($dumpdata)
+    else:
+      outWriteLn("-- list of currently defined symbols --")
+      for s in definedSymbolNames(): outWriteLn(s)
+      outWriteLn("-- end of list --")
+
+      for it in iterSearchPath(searchpaths): msgWriteLn(it)
   of "check":
     gCmd = cmdCheck
     wantMainModule()
@@ -568,7 +598,7 @@ proc MainCommand =
   else:
     rawMessage(errInvalidCommandX, command)
   
-  if msgs.gErrorCounter == 0 and gCmd notin {cmdInterpret, cmdRun}:
+  if msgs.gErrorCounter == 0 and gCmd notin {cmdInterpret, cmdRun, cmdDump}:
     rawMessage(hintSuccessX, [$gLinesCompiled,
                formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3),
                formatSize(getTotalMem())])
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 4099d7622..e11e47bac 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -83,7 +83,9 @@ type
     errInvalidCommandX, errXOnlyAtModuleScope, 
     errXNeedsParamObjectType,
     errTemplateInstantiationTooNested, errInstantiationFrom, 
-    errInvalidIndexValueForTuple, errCommandExpectsFilename, errXExpected, 
+    errInvalidIndexValueForTuple, errCommandExpectsFilename,
+    errMainModuleMustBeSpecified,
+    errXExpected, 
     errInvalidSectionStart, errGridTableNotImplemented, errGeneralParseError, 
     errNewSectionExpected, errWhitespaceExpected, errXisNoValidIndexFile, 
     errCannotRenderX, errVarVarTypeNotAllowed, errInstantiateXExplicitely,
@@ -301,6 +303,7 @@ const
     errInstantiationFrom: "instantiation from here", 
     errInvalidIndexValueForTuple: "invalid index value for tuple subscript", 
     errCommandExpectsFilename: "command expects a filename argument",
+    errMainModuleMustBeSpecified: "please, specify a main module in the project configuration file",
     errXExpected: "\'$1\' expected", 
     errInvalidSectionStart: "invalid section start",
     errGridTableNotImplemented: "grid table is not implemented", 
diff --git a/compiler/lexbase.nim b/compiler/nimlexbase.nim
index 6d45a825a..6d45a825a 100644
--- a/compiler/lexbase.nim
+++ b/compiler/nimlexbase.nim
diff --git a/compiler/nimsets.nim b/compiler/nimsets.nim
index 118046283..93bccae24 100644
--- a/compiler/nimsets.nim
+++ b/compiler/nimsets.nim
@@ -98,13 +98,13 @@ proc ToTreeSet(s: TBitSet, settype: PType, info: TLineInfo): PNode =
   result.typ = settype
   result.info = info
   e = 0
-  while e < high(s) * elemSize: 
+  while e < len(s) * elemSize: 
     if bitSetIn(s, e): 
       a = e
       b = e
       while true: 
         Inc(b)
-        if (b > high(s) * elemSize) or not bitSetIn(s, b): break 
+        if (b >= len(s) * elemSize) or not bitSetIn(s, b): break 
       Dec(b)
       if a == b: 
         addSon(result, newIntTypeNode(nkIntLit, a + first, elemType))
diff --git a/compiler/options.nim b/compiler/options.nim
index ca20d7c83..08a5ba010 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -100,14 +100,14 @@ var
   searchPaths*, lazyPaths*: TLinkedList
   outFile*: string = ""
   headerFile*: string = ""
-  gVerbosity*: int            # how verbose the compiler is
+  gVerbosity* = 1             # how verbose the compiler is
   gNumberOfProcessors*: int   # number of processors
   gWholeProject*: bool        # for 'doc2': output any dependency
   gEvalExpr* = ""             # expression for idetools --eval
   gLastCmdTime*: float        # when caas is enabled, we measure each command
   gListFullPaths*: bool
   isServing*: bool = false
-  
+
 proc importantComments*(): bool {.inline.} = gCmd in {cmdDoc, cmdIdeTools}
 proc usesNativeGC*(): bool {.inline.} = gSelectedGC >= gcRefc
 
diff --git a/compiler/parsecfg.nim b/compiler/parsecfg.nim
index 965160bd5..e0d1afff1 100644
--- a/compiler/parsecfg.nim
+++ b/compiler/parsecfg.nim
@@ -12,7 +12,7 @@
 # standard library.
 
 import 
-  llstream, nhashes, strutils, lexbase
+  llstream, nhashes, strutils, nimlexbase
 
 type 
   TCfgEventKind* = enum 
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim
index 31eb7a9d5..058964fc8 100644
--- a/compiler/semmagic.nim
+++ b/compiler/semmagic.nim
@@ -23,9 +23,10 @@ proc expectIntLit(c: PContext, n: PNode): int =
 proc semInstantiationInfo(c: PContext, n: PNode): PNode =
   result = newNodeIT(nkPar, n.info, n.typ)
   let idx = expectIntLit(c, n.sons[1])
+  let useFullPaths = expectIntLit(c, n.sons[2])
   let info = getInfoContext(idx)
   var filename = newNodeIT(nkStrLit, n.info, getSysType(tyString))
-  filename.strVal = ToFilename(info)
+  filename.strVal = if useFullPaths != 0: info.toFullPath else: info.ToFilename
   var line = newNodeIT(nkIntLit, n.info, getSysType(tyInt))
   line.intVal = ToLinenumber(info)
   result.add(filename)
diff --git a/compiler/service.nim b/compiler/service.nim
index e2de6e5a0..b3c7fbc83 100644
--- a/compiler/service.nim
+++ b/compiler/service.nim
@@ -73,6 +73,9 @@ proc serve*(action: proc (){.nimcall.}) =
       var line = stdin.readLine.string
       if line == "quit": quit()
       execute line
+      echo ""
+      FlushFile(stdout)
+
   of "tcp", "":
     var server = Socket()
     let p = getConfigVar("server.port")