next steps for 'compiler as a service'

This commit is contained in:
Araq 2012-10-03 21:32:06 +02:00
commit cc51581937
4 changed files with 24 additions and 22 deletions

View file

@ -41,7 +41,7 @@ type
callsite: PNode # for 'callsite' magic callsite: PNode # for 'callsite' magic
mode*: TEvalMode mode*: TEvalMode
globals*: TIdNodeTable # state of global vars globals*: TIdNodeTable # state of global vars
getType*: proc(n: PNode): PNode getType*: proc(n: PNode): PNode {.closure.}
PEvalContext* = ref TEvalContext PEvalContext* = ref TEvalContext

View file

@ -8,7 +8,7 @@
# #
import import
options, strutils, os, tables options, strutils, os, tables, sockets
type type
TMsgKind* = enum TMsgKind* = enum
@ -466,6 +466,16 @@ var
gWarnCounter*: int = 0 gWarnCounter*: int = 0
gErrorMax*: int = 1 # stop after gErrorMax errors gErrorMax*: int = 1 # stop after gErrorMax errors
gSilence*: int # == 0 if we produce any output at all 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 # this format is understood by many text editors: it is the same that
# Borland and Freepascal use # Borland and Freepascal use
@ -575,22 +585,19 @@ proc inCheckpoint*(current: TLineInfo): TCheckPointResult =
type type
TErrorHandling = enum doNothing, doAbort, doRaise TErrorHandling = enum doNothing, doAbort, doRaise
proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) = proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) =
template maybeTrace = if msg == errInternal:
if defined(debug) or gVerbosity >= 3: assert(false) # we want a stack trace here
writeStackTrace()
if msg == errInternal:
writeStackTrace() # we always want a stack trace here
if msg >= fatalMin and msg <= fatalMax: if msg >= fatalMin and msg <= fatalMax:
maybeTrace() if gVerbosity >= 3: assert(false)
quit(1) quit(1)
if msg >= errMin and msg <= errMax: if msg >= errMin and msg <= errMax:
maybeTrace() if gVerbosity >= 3: assert(false)
inc(gErrorCounter) inc(gErrorCounter)
options.gExitcode = 1'i8 options.gExitcode = 1'i8
if gErrorCounter >= gErrorMax or eh == doAbort: 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: elif eh == doRaise:
raiseRecoverableError(s) raiseRecoverableError(s)

View file

@ -64,8 +64,8 @@ proc serve*(action: proc (){.nimcall.}) =
var inp = "".TaintedString var inp = "".TaintedString
server.listen() server.listen()
while true: while true:
var client = InvalidSocket accept(server, stdoutSocket)
accept(server, client) discard stdoutSocket.recvLine(inp)
discard client.recvLine(inp)
processCmdLine(passCmd2, inp.string) processCmdLine(passCmd2, inp.string)
action() action()
stdoutSocket.send("\c\L")

View file

@ -18,11 +18,6 @@ const
sectionContext = "con" sectionContext = "con"
sectionUsage = "use" sectionUsage = "use"
proc SuggestWriteln(s: string) =
if gSilence == 0:
Writeln(stdout, s)
proc SymToStr(s: PSym, isLocal: bool, section: string, li: TLineInfo): string = proc SymToStr(s: PSym, isLocal: bool, section: string, li: TLineInfo): string =
result = section result = section
result.add(sep) result.add(sep)
@ -238,7 +233,7 @@ proc findUsages(node: PNode, s: PSym) =
proc findDefinition(node: PNode, s: PSym) = proc findDefinition(node: PNode, s: PSym) =
if isTracked(node.info, s.name.s.len): if isTracked(node.info, s.name.s.len):
SuggestWriteln(SymToStr(s, isLocal=false, sectionDef)) SuggestWriteln(SymToStr(s, isLocal=false, sectionDef))
quit(0) SuggestQuit()
proc suggestSym*(n: PNode, s: PSym) {.inline.} = proc suggestSym*(n: PNode, s: PSym) {.inline.} =
## misnamed: should be 'symDeclared' ## misnamed: should be 'symDeclared'
@ -295,7 +290,7 @@ proc suggestExpr*(c: PContext, node: PNode) =
suggestCall(c, a, n, outputs) suggestCall(c, a, n, outputs)
dec(c.InCompilesContext) 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) = proc suggestStmt*(c: PContext, n: PNode) =
suggestExpr(c, n) suggestExpr(c, n)