summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJacek Sieka <arnetheduck@gmail.com>2017-05-29 15:42:26 +0800
committerAndreas Rumpf <rumpf_a@web.de>2017-05-29 09:42:26 +0200
commitba4cc4bf35e1309f404dfc7a99a351c63f48d35b (patch)
tree096d92275cc926bd8759dd4d395fbc5e19429caf
parentaef5b2eb54868e549082c9fd1f9a89e8edc83ee0 (diff)
downloadNim-ba4cc4bf35e1309f404dfc7a99a351c63f48d35b.tar.gz
a few tiny cleanups (#5712)
exposes emitLazily (for nlvm) and simplifies some conditionals
-rw-r--r--compiler/ccgexprs.nim3
-rw-r--r--compiler/ccgstmts.nim15
-rw-r--r--compiler/ccgutils.nim20
-rw-r--r--compiler/cgen.nim4
4 files changed, 12 insertions, 30 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index f5b99c405..2e6656028 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2148,8 +2148,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
       # are not transformed correctly. We work around this issue (#411) here
       # by ensuring it's no inner proc (owner is a module):
       if prc.skipGenericOwner.kind == skModule and sfCompileTime notin prc.flags:
-        if (optDeadCodeElim notin gGlobalOptions and
-            sfDeadCodeElim notin getModule(prc).flags) or
+        if (not emitLazily(prc)) or
             ({sfExportc, sfCompilerProc} * prc.flags == {sfExportc}) or
             (sfExportc in prc.flags and lfExportLib in prc.loc.flags) or
             (prc.kind == skMethod):
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index a094da783..378951d9d 100644
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -39,13 +39,11 @@ proc genVarTuple(p: BProc, n: PNode) =
   var L = sonsLen(n)
 
   # if we have a something that's been captured, use the lowering instead:
-  var useLowering = false
   for i in countup(0, L-3):
     if n[i].kind != nkSym:
-      useLowering = true; break
-  if useLowering:
-    genStmts(p, lowerTupleUnpacking(n, p.prc))
-    return
+      genStmts(p, lowerTupleUnpacking(n, p.prc))
+      return
+
   genLineDir(p, n)
   initLocExpr(p, n.sons[L-1], tup)
   var t = tup.t.skipTypes(abstractInst)
@@ -182,10 +180,11 @@ proc genGotoVar(p: BProc; value: PNode) =
     lineF(p, cpsStmts, "goto NIMSTATE_$#;$n", [value.intVal.rope])
 
 proc genSingleVar(p: BProc, a: PNode) =
-  var v = a.sons[0].sym
-  if {sfCompileTime, sfGoto} * v.flags != {}:
+  let v = a.sons[0].sym
+  if sfCompileTime in v.flags: return
+  if sfGoto in v.flags:
     # translate 'var state {.goto.} = X' into 'goto LX':
-    if sfGoto in v.flags: genGotoVar(p, a.sons[2])
+    genGotoVar(p, a.sons[2])
     return
   var targetProc = p
   if sfGlobal in v.flags:
diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim
index c8e742de3..6a7aa8951 100644
--- a/compiler/ccgutils.nim
+++ b/compiler/ccgutils.nim
@@ -11,7 +11,7 @@
 
 import
   ast, astalgo, ropes, hashes, strutils, types, msgs, wordrecg,
-  platform, trees
+  platform, trees, options
 
 proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode =
   case n.kind
@@ -211,20 +211,8 @@ proc mangle*(name: string): string =
   if requiresUnderscore:
     result.add "_"
 
-proc makeLLVMString*(s: string): Rope =
-  const MaxLineLength = 64
-  result = nil
-  var res = "c\""
-  for i in countup(0, len(s) - 1):
-    if (i + 1) mod MaxLineLength == 0:
-      add(result, rope(res))
-      setLen(res, 0)
-    case s[i]
-    of '\0'..'\x1F', '\x7F'..'\xFF', '\"', '\\':
-      add(res, '\\')
-      add(res, toHex(ord(s[i]), 2))
-    else: add(res, s[i])
-  add(res, "\\00\"")
-  add(result, rope(res))
+proc emitLazily*(s: PSym): bool {.inline.} =
+  result = optDeadCodeElim in gGlobalOptions or
+           sfDeadCodeElim in getModule(s).flags
 
 initTypeTables()
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index fab35c584..89d293989 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -47,10 +47,6 @@ proc findPendingModule(m: BModule, s: PSym): BModule =
   var ms = getModule(s)
   result = m.g.modules[ms.position]
 
-proc emitLazily(s: PSym): bool {.inline.} =
-  result = optDeadCodeElim in gGlobalOptions or
-           sfDeadCodeElim in getModule(s).flags
-
 proc initLoc(result: var TLoc, k: TLocKind, typ: PType, s: TStorageLoc) =
   result.k = k
   result.s = s