summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-02-27 16:44:43 +0100
committerAraq <rumpf_a@web.de>2015-02-27 16:44:55 +0100
commit3bfcfeb0cffa266b45f0803009787d7761881326 (patch)
tree13740cd238c5c72772baed5c6241c3dd6aa18eaa
parent05233de66cbe4a1878e8d83b7bc8fb9df20d8ff1 (diff)
downloadNim-3bfcfeb0cffa266b45f0803009787d7761881326.tar.gz
don't use stdout for nimsuggest server mode
-rw-r--r--compiler/ast.nim2
-rw-r--r--compiler/astalgo.nim10
-rw-r--r--compiler/commands.nim2
-rw-r--r--compiler/lexer.nim6
-rw-r--r--compiler/msgs.nim14
-rw-r--r--compiler/options.nim8
-rw-r--r--compiler/vm.nim12
-rw-r--r--lib/core/macros.nim9
8 files changed, 34 insertions, 29 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 6afc1db26..1462d58d5 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -1413,7 +1413,7 @@ proc copyTree*(src: PNode): PNode =
     for i in countup(0, sonsLen(src) - 1): 
       result.sons[i] = copyTree(src.sons[i])
 
-proc hasSonWith(n: PNode, kind: TNodeKind): bool = 
+proc hasSonWith*(n: PNode, kind: TNodeKind): bool = 
   for i in countup(0, sonsLen(n) - 1): 
     if n.sons[i].kind == kind: 
       return true
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim
index e9b82d74b..ea9534b1f 100644
--- a/compiler/astalgo.nim
+++ b/compiler/astalgo.nim
@@ -445,21 +445,21 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
 
 proc debug(n: PSym) =
   if n == nil:
-    writeln(stdout, "null")
+    msgWriteln("null")
   elif n.kind == skUnknown:
-    writeln(stdout, "skUnknown")
+    msgWriteln("skUnknown")
   else:
     #writeln(stdout, ropeToStr(symToYaml(n, 0, 1)))
-    writeln(stdout, "$1_$2: $3, $4, $5, $6" % [
+    msgWriteln("$1_$2: $3, $4, $5, $6" % [
       n.name.s, $n.id, flagsToStr(n.flags).ropeToStr, 
       flagsToStr(n.loc.flags).ropeToStr, lineInfoToStr(n.info).ropeToStr,
       $n.kind])
 
 proc debug(n: PType) = 
-  writeln(stdout, ropeToStr(debugType(n)))
+  msgWriteln(ropeToStr(debugType(n)))
 
 proc debug(n: PNode) = 
-  writeln(stdout, ropeToStr(debugTree(n, 0, 100)))
+  msgWriteln(ropeToStr(debugTree(n, 0, 100)))
 
 const 
   EmptySeq = @[]
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 6e594375f..a2d02e469 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -382,7 +382,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
     of "off":
       gOptions.excl optEndb
       undefSymbol("endb")
-    of "native":
+    of "native", "gdb":
       incl(gGlobalOptions, optCDebug)
       gOptions = gOptions + {optLineDir} - {optEndb}
       undefSymbol("endb")
diff --git a/compiler/lexer.nim b/compiler/lexer.nim
index fc40192b8..c86762121 100644
--- a/compiler/lexer.nim
+++ b/compiler/lexer.nim
@@ -181,10 +181,8 @@ proc prettyTok*(tok: TToken): string =
   else: result = tokToStr(tok)
   
 proc printTok*(tok: TToken) = 
-  write(stdout, tok.line, ":", tok.col, "\t")
-  write(stdout, TokTypeToStr[tok.tokType])
-  write(stdout, " ")
-  writeln(stdout, tokToStr(tok))
+  msgWriteln($tok.line & ":" & $tok.col & "\t" &
+      TokTypeToStr[tok.tokType] & " " & tokToStr(tok))
 
 var dummyIdent: PIdent
 
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index ed28fea69..a72dedf57 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -330,7 +330,7 @@ const
     errUsingNoSymbol: "'$1' is not a variable, constant or a proc name",
     errMacroBodyDependsOnGenericTypes: "the macro body cannot be compiled, " &
                                        "because the parameter '$1' has a generic type",
-    errDestructorNotGenericEnough: "Destructor signarue is too specific. " &
+    errDestructorNotGenericEnough: "Destructor signature is too specific. " &
                                    "A destructor must be associated will all instantiations of a generic type",
     errInlineIteratorsAsProcParams: "inline iterators can be used as parameters only for " &
                                     "templates, macros and other inline iterators",
@@ -443,7 +443,7 @@ type
   TNoteKind* = range[warnMin..hintMax] # "notes" are warnings or hints
   TNoteKinds* = set[TNoteKind]
 
-  TFileInfo*{.final.} = object 
+  TFileInfo* = object 
     fullPath: string           # This is a canonical full filesystem path
     projPath*: string          # This is relative to the project's root
     shortName*: string         # short name of the module
@@ -458,7 +458,7 @@ type
                                # and parsed; usually 'nil' but is used
                                # for 'nimsuggest'
 
-  TLineInfo*{.final.} = object # This is designed to be as small as possible,
+  TLineInfo* = object          # This is designed to be as small as possible,
                                # because it is used
                                # in syntax nodes. We save space here by using 
                                # two int16 and an int32.
@@ -493,7 +493,7 @@ proc toCChar*(c: char): string =
 
 proc makeCString*(s: string): PRope =
   # BUGFIX: We have to split long strings into many ropes. Otherwise
-  # this could trigger an InternalError(). See the ropes module for
+  # this could trigger an internalError(). See the ropes module for
   # further information.
   const 
     MaxLineLength = 64
@@ -696,7 +696,9 @@ proc msgWriteln*(s: string) =
 
   #if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
 
-  if optStdout in gGlobalOptions:
+  if not isNil(writelnHook):
+    writelnHook(s)
+  elif optStdout in gGlobalOptions:
     if eStdErr in errorOutputs: writeln(stderr, s)
   else:
     if eStdOut in errorOutputs: writeln(stdout, s)
@@ -720,7 +722,7 @@ type
 proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) =
   template quit =
     if defined(debug) or gVerbosity >= 3 or msg == errInternal:
-      if stackTraceAvailable():
+      if stackTraceAvailable() and isNil(writelnHook):
         writeStackTrace()
       else:
         msgWriteln("No stack traceback available\nTo create a stacktrace, rerun compilation with ./koch temp " & options.command & " <file>")
diff --git a/compiler/options.nim b/compiler/options.nim
index d6d9389f5..1b4a624ab 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -283,19 +283,19 @@ when noTimeMachine:
       var p = startProcess("/usr/bin/tmutil", args = ["addexclusion", dir])
       discard p.waitForExit
       p.close
-    except E_Base, EOS:
+    except Exception:
       discard
 
-proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string = 
+proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
   var (head, tail) = splitPath(f)
   #if len(head) > 0: head = removeTrailingDirSep(shortenDir(head & dirSep))
   var subdir = getGeneratedPath() # / head
   if createSubDir:
-    try: 
+    try:
       createDir(subdir)
       when noTimeMachine:
        excludeDirFromTimeMachine(subdir)
-    except OSError: 
+    except OSError:
       writeln(stdout, "cannot create directory: " & subdir)
       quit(1)
   result = joinPath(subdir, tail)
diff --git a/compiler/vm.nim b/compiler/vm.nim
index e96b89f49..a36de1c20 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -776,10 +776,14 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
         stackTrace(c, tos, pc, errNilAccess)
     of opcEcho:
       let rb = instr.regB
-      for i in ra..ra+rb-1:
-        #if regs[i].kind != rkNode: debug regs[i]
-        write(stdout, regs[i].node.strVal)
-      writeln(stdout, "")
+      if rb == 1:
+        msgWriteln(regs[ra].node.strVal)
+      else:
+        var outp = ""
+        for i in ra..ra+rb-1:
+          #if regs[i].kind != rkNode: debug regs[i]
+          outp.add(regs[i].node.strVal)
+        msgWriteln(outp)
     of opcContainsSet:
       decodeBC(rkInt)
       regs[ra].intVal = ord(inSet(regs[rb].node, regs[rc].regToNode))
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index dbfb2ceb3..4758dc0c1 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -456,10 +456,11 @@ proc lispRepr*(n: PNimrodNode): string {.compileTime, benign.} =
   of nnkSym: add(result, $n.symbol)
   of nnkNone: assert false
   else:
-    add(result, lispRepr(n[0]))
-    for j in 1..n.len-1:
-      add(result, ", ")
-      add(result, lispRepr(n[j]))
+    if n.len > 0:
+      add(result, lispRepr(n[0]))
+      for j in 1..n.len-1:
+        add(result, ", ")
+        add(result, lispRepr(n[j]))
 
   add(result, ")")