diff options
author | Adam Strzelecki <ono@java.pl> | 2015-10-22 22:07:56 +0200 |
---|---|---|
committer | Adam Strzelecki <ono@java.pl> | 2015-10-22 22:09:15 +0200 |
commit | acb6a36656e0dc2d566c0d37b70c0188c7bad28b (patch) | |
tree | 5be8575cb3802baf9cc7ab84735b45f8b1875fd6 | |
parent | a90e23a4ddbef38cdf48c59e68630999c6e90374 (diff) | |
download | Nim-acb6a36656e0dc2d566c0d37b70c0188c7bad28b.tar.gz |
msgs: One msgWriteln with optional flags
Instead of msgWriteln, outWriteln and stdoutWriteln doing essentially the same.
-rw-r--r-- | compiler/main.nim | 9 | ||||
-rw-r--r-- | compiler/msgs.nim | 30 | ||||
-rw-r--r-- | compiler/vm.nim | 4 |
3 files changed, 19 insertions, 24 deletions
diff --git a/compiler/main.nim b/compiler/main.nim index 2ee07a443..3d04cc61c 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -317,11 +317,12 @@ proc mainCommand* = (key: "lib_paths", val: libpaths) ] - outWriteln($dumpdata) + msgWriteln($dumpdata, {msgStdout, msgSkipHook}) else: - outWriteln("-- list of currently defined symbols --") - for s in definedSymbolNames(): outWriteln(s) - outWriteln("-- end of list --") + msgWriteln("-- list of currently defined symbols --", + {msgStdout, msgSkipHook}) + for s in definedSymbolNames(): msgWriteln(s, {msgStdout, msgSkipHook}) + msgWriteln("-- end of list --", {msgStdout, msgSkipHook}) for it in iterSearchPath(searchPaths): msgWriteln(it) of "check": diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 442d9efc2..7b44b4349 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -727,20 +727,23 @@ proc `??`* (info: TLineInfo, filename: string): bool = var gTrackPos*: TLineInfo -proc outWriteln*(s: string) = - ## Writes to stdout. Always. - if eStdOut in errorOutputs: - writeLine(stdout, s) - flushFile(stdout) +type + MsgFlag* = enum ## flags altering msgWriteln behavior + msgStdout, ## force writing to stdout, even stderr is default + msgSkipHook ## skip message hook even if it is present + MsgFlags* = set[MsgFlag] -proc msgWriteln*(s: string) = - ## Writes to stderr. If --stdout option is given, writes to stdout instead. +proc msgWriteln*(s: string, flags: MsgFlags = {}) = + ## Writes given message string to stderr by default. + ## If ``--stdout`` option is given, writes to stdout instead. If message hook + ## is present, then it is used to output message rather than stderr/stdout. + ## This behavior can be altered by given optional flags. #if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return - if not isNil(writelnHook): + if not isNil(writelnHook) and msgSkipHook notin flags: writelnHook(s) - elif optStdout in gGlobalOptions: + elif optStdout in gGlobalOptions or msgStdout in flags: if eStdOut in errorOutputs: writeLine(stdout, s) flushFile(stdout) @@ -751,15 +754,6 @@ proc msgWriteln*(s: string) = when defined(windows): flushFile(stderr) -proc stdoutWriteln*(s: string) = - ## Writes to stdout. - ## Should be used only for VM time equivalents to procs outputting to stdout. - if not isNil(writelnHook): - writelnHook(s) - else: - writeLine(stdout, s) - flushFile(stdout) - macro callIgnoringStyle(theProc: typed, first: typed, args: varargs[expr]): stmt = let typForegroundColor = bindSym"ForegroundColor".getType diff --git a/compiler/vm.nim b/compiler/vm.nim index 6d0c63f14..495b0c747 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -811,13 +811,13 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = of opcEcho: let rb = instr.regB if rb == 1: - stdoutWriteln(regs[ra].node.strVal) + msgWriteln(regs[ra].node.strVal, {msgStdout}) else: var outp = "" for i in ra..ra+rb-1: #if regs[i].kind != rkNode: debug regs[i] outp.add(regs[i].node.strVal) - stdoutWriteln(outp) + msgWriteln(outp, {msgStdout}) of opcContainsSet: decodeBC(rkInt) regs[ra].intVal = ord(inSet(regs[rb].node, regs[rc].regToNode)) |