next steps for 'compiler as a service'

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

View File

@@ -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

View File

@@ -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)

View File

@@ -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")

View File

@@ -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)