diff options
author | Araq <rumpf_a@web.de> | 2012-10-03 21:32:06 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-10-03 21:32:06 +0200 |
commit | cc5158193738dfc3f90cb5054c4f7abe1546e9fc (patch) | |
tree | f27e312e1b0bb4f3aa183b0a552959cfedc78bfe /compiler | |
parent | c2b8669e04560e486e5df21b1217e6b9684ba88e (diff) | |
download | Nim-cc5158193738dfc3f90cb5054c4f7abe1546e9fc.tar.gz |
next steps for 'compiler as a service'
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/evals.nim | 2 | ||||
-rwxr-xr-x | compiler/msgs.nim | 29 | ||||
-rw-r--r-- | compiler/service.nim | 6 | ||||
-rwxr-xr-x | compiler/suggest.nim | 9 |
4 files changed, 24 insertions, 22 deletions
diff --git a/compiler/evals.nim b/compiler/evals.nim index 226415815..e72231bf5 100755 --- a/compiler/evals.nim +++ b/compiler/evals.nim @@ -41,7 +41,7 @@ type callsite: PNode # for 'callsite' magic mode*: TEvalMode globals*: TIdNodeTable # state of global vars - getType*: proc(n: PNode): PNode + getType*: proc(n: PNode): PNode {.closure.} PEvalContext* = ref TEvalContext diff --git a/compiler/msgs.nim b/compiler/msgs.nim index c793c1c68..e29142e4f 100755 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -8,7 +8,7 @@ # import - options, strutils, os, tables + options, strutils, os, tables, sockets type TMsgKind* = enum @@ -466,6 +466,16 @@ var gWarnCounter*: int = 0 gErrorMax*: int = 1 # stop after gErrorMax errors gSilence*: int # == 0 if we produce any output at all + stdoutSocket*: TSocket + +proc SuggestWriteln*(s: string) = + if gSilence == 0: + if isNil(stdoutSocket): Writeln(stdout, s) + else: stdoutSocket.send(s & "\c\L") + +proc SuggestQuit*() = + if isNil(stdoutSocket): quit(0) + else: stdoutSocket.send("\c\L") # this format is understood by many text editors: it is the same that # Borland and Freepascal use @@ -575,22 +585,19 @@ proc inCheckpoint*(current: TLineInfo): TCheckPointResult = type TErrorHandling = enum doNothing, doAbort, doRaise -proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) = - template maybeTrace = - if defined(debug) or gVerbosity >= 3: - writeStackTrace() - - if msg == errInternal: - writeStackTrace() # we always want a stack trace here +proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) = + if msg == errInternal: + assert(false) # we want a stack trace here if msg >= fatalMin and msg <= fatalMax: - maybeTrace() + if gVerbosity >= 3: assert(false) quit(1) if msg >= errMin and msg <= errMax: - maybeTrace() + if gVerbosity >= 3: assert(false) inc(gErrorCounter) options.gExitcode = 1'i8 if gErrorCounter >= gErrorMax or eh == doAbort: - quit(1) # one error stops the compiler + if gVerbosity >= 3: assert(false) + quit(1) # one error stops the compiler elif eh == doRaise: raiseRecoverableError(s) diff --git a/compiler/service.nim b/compiler/service.nim index 95fb11022..f6c2720a7 100644 --- a/compiler/service.nim +++ b/compiler/service.nim @@ -64,8 +64,8 @@ proc serve*(action: proc (){.nimcall.}) = var inp = "".TaintedString server.listen() while true: - var client = InvalidSocket - accept(server, client) - discard client.recvLine(inp) + accept(server, stdoutSocket) + discard stdoutSocket.recvLine(inp) processCmdLine(passCmd2, inp.string) action() + stdoutSocket.send("\c\L") diff --git a/compiler/suggest.nim b/compiler/suggest.nim index d33f9a7bd..719d0aa42 100755 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -18,11 +18,6 @@ const sectionContext = "con" sectionUsage = "use" -proc SuggestWriteln(s: string) = - if gSilence == 0: - Writeln(stdout, s) - - proc SymToStr(s: PSym, isLocal: bool, section: string, li: TLineInfo): string = result = section result.add(sep) @@ -238,7 +233,7 @@ proc findUsages(node: PNode, s: PSym) = proc findDefinition(node: PNode, s: PSym) = if isTracked(node.info, s.name.s.len): SuggestWriteln(SymToStr(s, isLocal=false, sectionDef)) - quit(0) + SuggestQuit() proc suggestSym*(n: PNode, s: PSym) {.inline.} = ## misnamed: should be 'symDeclared' @@ -295,7 +290,7 @@ proc suggestExpr*(c: PContext, node: PNode) = suggestCall(c, a, n, outputs) dec(c.InCompilesContext) - if outputs > 0 and optUsages notin gGlobalOptions: quit(0) + if outputs > 0 and optUsages notin gGlobalOptions: SuggestQuit() proc suggestStmt*(c: PContext, n: PNode) = suggestExpr(c, n) |