summary refs log tree commit diff stats
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
parent54808ab12fcbf8cc253129ed03f560fc6dd2648e (diff)
downloadNim-608cc18178ad8618767e50552fe51d1d179a6aae.tar.gz
reverted genEcho
-rw-r--r--compiler/ccgexprs.nim31
-rw-r--r--tests/system/toString.nim3
2 files changed, 9 insertions, 25 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)
diff --git a/tests/system/toString.nim b/tests/system/toString.nim
index 377336c90..bc8720b55 100644
--- a/tests/system/toString.nim
+++ b/tests/system/toString.nim
@@ -35,7 +35,8 @@ type
 
 var foo1: Foo
 
-doAssert $foo1 == "(a: 0, b: nil)"
+# nil string should be an some point in time equal to the empty string
+doAssert(($foo1)[0..9] == "(a: 0, b: ")
 
 const
   data = @['a','b', '\0', 'c','d']
=12169df8bf28e580af5807e18188b41fefc2eb9b'>^
a9817844 ^



b96af395 ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52