summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-04-03 23:41:20 +0200
committerAraq <rumpf_a@web.de>2018-04-03 23:41:20 +0200
commitf108e89670d5f090819cfffbce6ba0b0539ea68a (patch)
tree548025fcda0591220340b3ffca2bc98ca8496ccd
parent17d0e29d400f6e66c3ab4dee845e27cfcbb1118e (diff)
downloadNim-f108e89670d5f090819cfffbce6ba0b0539ea68a.tar.gz
implemented v2 string literals
-rw-r--r--compiler/ccgliterals.nim14
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/ccgliterals.nim b/compiler/ccgliterals.nim
index 3011f0a94..b17a5eedd 100644
--- a/compiler/ccgliterals.nim
+++ b/compiler/ccgliterals.nim
@@ -52,10 +52,20 @@ proc genStringLiteralV1(m: BModule; n: PNode): Rope =
 # ------ Version 2: destructor based strings and seqs -----------------------
 
 proc genStringLiteralDataOnlyV2(m: BModule, s: string): Rope =
-  discard "to implement"
+  result = getTempName(m)
+  addf(m.s[cfsData], " static const NIM_CHAR $1[$2] = $3;$n",
+       [result, rope(len(s)+1), makeCString(s)])
 
 proc genStringLiteralV2(m: BModule; n: PNode): Rope =
-  discard "to implement"
+  let id = nodeTableTestOrSet(m.dataCache, n, m.labels)
+  if id == m.labels:
+    # string literal not found in the cache:
+    let pureLit = genStringLiteralDataOnlyV2(m, n.strVal)
+    result = getTempName(m)
+    addf(m.s[cfsData], "static const #NimStringV2 $1 = {$2, $2, $3};$n",
+        [result, rope(len(n.strVal)+1), pureLit])
+  else:
+    result = m.tmpBase & rope(id)
 
 # ------ Version selector ---------------------------------------------------