summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-07-25 00:12:56 +0200
committerAraq <rumpf_a@web.de>2012-07-25 00:12:56 +0200
commit1e4fc02e5eb1a160ba00540ca77210d5405adc5b (patch)
treea5db120499ce8e8aefbe1142dfd58895a9d652dd
parent033dc50c691f37808e021856bcd0d385cf427ec2 (diff)
downloadNim-1e4fc02e5eb1a160ba00540ca77210d5405adc5b.tar.gz
small bugfix: code generation for nil closures
-rwxr-xr-xcompiler/ccgexprs.nim45
-rwxr-xr-xtodo.txt6
2 files changed, 31 insertions, 20 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index ee2b5159a..42f19b069 100755
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -44,45 +44,56 @@ proc getStrLit(m: BModule, s: string): PRope =
   appf(m.s[cfsData], "STRING_LITERAL($1, $2, $3);$n",
        [result, makeCString(s), ToRope(len(s))])
 
-proc genLiteral(p: BProc, v: PNode, ty: PType): PRope =
-  if ty == nil: internalError(v.info, "genLiteral: ty is nil")
-  case v.kind
+proc genLiteral(p: BProc, n: PNode, ty: PType): PRope =
+  if ty == nil: internalError(n.info, "genLiteral: ty is nil")
+  case n.kind
   of nkCharLit..nkUInt64Lit:
     case skipTypes(ty, abstractVarRange).kind
     of tyChar, tyInt64, tyNil:
-      result = intLiteral(v.intVal)
+      result = intLiteral(n.intVal)
     of tyInt:
-      if (v.intVal >= low(int32)) and (v.intVal <= high(int32)):
-        result = int32Literal(int32(v.intVal))
+      if (n.intVal >= low(int32)) and (n.intVal <= high(int32)):
+        result = int32Literal(int32(n.intVal))
       else:
-        result = intLiteral(v.intVal)
+        result = intLiteral(n.intVal)
     of tyBool:
-      if v.intVal != 0: result = toRope("NIM_TRUE")
+      if n.intVal != 0: result = toRope("NIM_TRUE")
       else: result = toRope("NIM_FALSE")
     else:
       result = ropef("(($1) $2)", [getTypeDesc(p.module,
-          skipTypes(ty, abstractVarRange)), intLiteral(v.intVal)])
+          skipTypes(ty, abstractVarRange)), intLiteral(n.intVal)])
   of nkNilLit:
-    result = toRope("NIM_NIL")
+    let t = skipTypes(ty, abstractVarRange)
+    if t.kind == tyProc and t.callConv == ccClosure:
+      var id = NodeTableTestOrSet(p.module.dataCache, n, gBackendId)
+      result = con("TMP", toRope(id))
+      if id == gBackendId:
+        # not found in cache:
+        inc(gBackendId)
+        appf(p.module.s[cfsData],
+             "static NIM_CONST $1 $2 = {NIM_NIL,NIM_NIL};$n",
+             [getTypeDesc(p.module, t), result])
+    else:
+      result = toRope("NIM_NIL")
   of nkStrLit..nkTripleStrLit:
     if skipTypes(ty, abstractVarRange).kind == tyString:
-      var id = NodeTableTestOrSet(p.module.dataCache, v, gBackendId)
+      var id = NodeTableTestOrSet(p.module.dataCache, n, gBackendId)
       if id == gBackendId:
         # string literal not found in the cache:
         result = ropecg(p.module, "((#NimStringDesc*) &$1)", 
-                        [getStrLit(p.module, v.strVal)])
+                        [getStrLit(p.module, n.strVal)])
       else:
         result = ropecg(p.module, "((#NimStringDesc*) &TMP$1)", [toRope(id)])
     else:
-      result = makeCString(v.strVal)
+      result = makeCString(n.strVal)
   of nkFloatLit..nkFloat64Lit:
-    result = toRope(v.floatVal.ToStrMaxPrecision)
+    result = toRope(n.floatVal.ToStrMaxPrecision)
   else:
-    InternalError(v.info, "genLiteral(" & $v.kind & ')')
+    InternalError(n.info, "genLiteral(" & $n.kind & ')')
     result = nil
 
-proc genLiteral(p: BProc, v: PNode): PRope =
-  result = genLiteral(p, v, v.typ)
+proc genLiteral(p: BProc, n: PNode): PRope =
+  result = genLiteral(p, n, n.typ)
 
 proc bitSetToWord(s: TBitSet, size: int): BiggestInt =
   result = 0
diff --git a/todo.txt b/todo.txt
index 62ec2ad35..1ac9fb15a 100755
--- a/todo.txt
+++ b/todo.txt
@@ -9,15 +9,12 @@ New pragmas:
 - document destructors
 
 - ``borrow`` needs to take type classes into account
-- make use of ``tyIter`` to fix the implicit items/pairs issue
 - ``=`` should be overloadable; requires specialization for ``=``
 - optimize genericAssign in the code generator
 - fix remaining closure bugs:
   - make toplevel but in a scope vars local; make procs there inner procs
   - fix evals.nim with closures
   - implement "closure tuple consists of a single 'ref'" optimization
-  - make 'raiseHook' take a closure and provide push and pop for this
-    --> Lisp-style exception system
 
 - document 'do' notation
 - rethink the syntax: distinction between expr and stmt is unfortunate; 
@@ -43,6 +40,7 @@ version 0.9.XX
   - document it
   - fix exception handling
 
+- make use of ``tyIter`` to fix the implicit items/pairs issue
 - make templates hygienic by default: try to gensym() everything in the 'block'
   of a template; find a better solution for gensym instead of `*ident`
 - introduce 'callsite' magic and make macros and templates the same
@@ -94,6 +92,8 @@ Library
 Low priority
 ------------
 
+- make 'raiseHook' take a closure and provide push and pop for this
+  --> Lisp-style condition system
 - change how comments are part of the AST
 - fix & document ``byCopy`` pragma
 - ``with proc `+`(x, y: T): T`` for generic code