summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2017-08-08 13:58:50 +0200
committerArne Döring <arne.doering@gmx.net>2017-08-08 13:58:50 +0200
commit608cc18178ad8618767e50552fe51d1d179a6aae (patch)
tree49cb3a456e83e7988c5f92568707e885b73f76ec /compiler
parent54808ab12fcbf8cc253129ed03f560fc6dd2648e (diff)
downloadNim-608cc18178ad8618767e50552fe51d1d179a6aae.tar.gz
reverted genEcho
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgexprs.nim31
1 files changed, 7 insertions, 24 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index d971c0bc2..de784acf9 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -953,40 +953,23 @@ proc genEcho(p: BProc, n: PNode) =
   # this unusal way of implementing it ensures that e.g. ``echo("hallo", 45)``
   # is threadsafe.
   internalAssert n.kind == nkBracket
-  var args = newSeq[tuple[hasvalue,len,str: string]](0)
+  var args: Rope = nil
   var a: TLoc
   for i in countup(0, n.len-1):
     if n.sons[i].skipConv.kind == nkNilLit:
-      args.add((hasvalue:"0", len: "0", str: "\"\""))
+      add(args, ", \"nil\"")
     else:
       initLocExpr(p, n.sons[i], a)
-      let ptrexpr: string = $rdLoc(a)
-      let len = format("($1)->Sup.len", ptrexpr)
-      let str = format("($1)->data", ptrexpr)
-      args.add((hasvalue: ptrexpr, len: len, str: str))
+      addf(args, ", $1? ($1)->data:\"nil\"", [rdLoc(a)])
   if platform.targetOS == osGenode:
     # bypass libc and print directly to the Genode LOG session
     p.module.includeHeader("<base/log.h>")
-    # separated args
-    var rope: Rope
-    for arg in args:
-      rope.add ", "
-      rope.add arg.str
-    # TODO this is wrong, it does not properly handle '\0' characters, and locking is not done.
-    linefmt(p, cpsStmts, """Genode::log(""$1);$n""", rope)
-    for arg in args:
-      if arg.hasvalue != "0": # if we know statically that there is no string, it can be skipped
-        linefmt(p, cpsStmts, "if($1) Genode::log($2);$n", rope(arg.hasvalue), rope(arg.str))
+    linefmt(p, cpsStmts, """Genode::log(""$1);$n""", args)
   else:
     p.module.includeHeader("<stdio.h>")
-    #linefmt(p, cpsStmts, "printf($1$2);$n",
-    #        makeCString(repeat("%s", n.len) & tnl), args)
-    linefmt(p, cpsStmts, "flockfile(stdout);$n")
-    for arg in args:
-      if arg.hasvalue != "0": # if we know statically that there is no string, it can be skipped
-        linefmt(p, cpsStmts, "if($1) fwrite($2, 1, $3, stdout);$n", rope(arg.hasvalue), rope(arg.str), rope(arg.len));
-    linefmt(p, cpsStmts, "putchar('\\n'); fflush(stdout);$n")
-    linefmt(p, cpsStmts, "funlockfile(stdout);$n")
+    linefmt(p, cpsStmts, "printf($1$2);$n",
+            makeCString(repeat("%s", n.len) & tnl), args)
+    linefmt(p, cpsStmts, "fflush(stdout);$n")
 
 proc gcUsage(n: PNode) =
   if gSelectedGC == gcNone: message(n.info, warnGcMem, n.renderTree)