fixes for True/False in compile time expressions; make sure True/False pass as object...
authorStefan Behnel <scoder@users.berlios.de>
Sat, 16 Feb 2008 17:37:23 +0000 (18:37 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 16 Feb 2008 17:37:23 +0000 (18:37 +0100)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Parsing.py

index a2299a61291cb404e1f70ee81338f176022b6a1c..c613959b1a0bf7a117016b5118a6e7b3057f6815 100644 (file)
@@ -489,7 +489,7 @@ class ExprNode(Node):
             src = CoerceFromPyTypeNode(dst_type, src, env)
         else: # neither src nor dst are py types
             # Added the string comparison, since for c types that
-            # is enough, but SageX gets confused when the types are
+            # is enough, but Cython gets confused when the types are
             # in different files.
             if not (str(src.type) == str(dst_type) or dst_type.assignable_from(src_type)):
                 error(self.pos, "Cannot assign type '%s' to '%s'" %
@@ -588,7 +588,7 @@ class BoolNode(PyConstNode):
     def coerce_to(self, dst_type, env):
         value = self.value
         if dst_type.is_numeric:
-            return IntNode(self.pos, value=self.value).coerce_to(dst_type, env)
+            return IntNode(self.pos, value=int(self.value)).coerce_to(dst_type, env)
         else:
             return PyConstNode.coerce_to(self, dst_type, env)
 
index a430a0c9b157c57587aa30949f492de38f9547a3..7a9444c444dbc6903a854ab7d3313e46d1c0d0ae 100644 (file)
@@ -469,9 +469,9 @@ def p_atom(s):
         if name == "None":
             return ExprNodes.NoneNode(pos)
         elif name == "True":
-            return ExprNodes.BoolNode(pos, value=1)
+            return ExprNodes.BoolNode(pos, value=True)
         elif name == "False":
-            return ExprNodes.BoolNode(pos, value=0)
+            return ExprNodes.BoolNode(pos, value=False)
         else:
             return p_name(s, name)
     elif sy == 'NULL':
@@ -489,7 +489,9 @@ def p_name(s, name):
             pass
         else:
             rep = repr(value)
-            if isinstance(value, int):
+            if isinstance(value, bool):
+                return ExprNodes.BoolNode(pos, value = value)
+            elif isinstance(value, int):
                 return ExprNodes.IntNode(pos, value = rep)
             elif isinstance(value, long):
                 return ExprNodes.LongNode(pos, value = rep)