cython-devel
changeset 1229:c2374c45d350
Optimize conditions when one side of binop is pure C.
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Thu Oct 09 12:54:36 2008 -0700 (3 years ago) |
| parents | ed6c1b3311af |
| children | 2fecdc45a284 |
| files | Cython/Compiler/ExprNodes.py |
line diff
1.1 --- a/Cython/Compiler/ExprNodes.py Wed Oct 08 16:08:15 2008 -0700
1.2 +++ b/Cython/Compiler/ExprNodes.py Thu Oct 09 12:54:36 2008 -0700
1.3 @@ -746,6 +746,10 @@
1.4 # result, because we might be coercing to an extension type,
1.5 # in which case a type test node will be needed.
1.6 return ConstNode.coerce_to(self, dst_type, env)
1.7 +
1.8 + def coerce_to_boolean(self, env):
1.9 + self.type = PyrexTypes.c_bint_type
1.10 + return self
1.11
1.12 def calculate_result_code(self):
1.13 if self.type.is_pyobject:
1.14 @@ -3780,6 +3784,12 @@
1.15 else:
1.16 return self.operand1.compile_time_value(denv) \
1.17 or self.operand2.compile_time_value(denv)
1.18 +
1.19 + def coerce_to_boolean(self, env):
1.20 + self.operand1 = self.operand1.coerce_to_boolean(env)
1.21 + self.operand2 = self.operand2.coerce_to_boolean(env)
1.22 + self.type = PyrexTypes.c_bint_type
1.23 + return self
1.24
1.25 def analyse_types(self, env):
1.26 self.operand1.analyse_types(env)
1.27 @@ -4397,6 +4407,9 @@
1.28 "Cannot convert '%s' to Python object" % arg.type)
1.29
1.30 gil_message = "Converting to Python object"
1.31 +
1.32 + def coerce_to_boolean(self, env):
1.33 + return self.arg.coerce_to_boolean(env)
1.34
1.35 def analyse_types(self, env):
1.36 # The arg is always already analysed
1.37 @@ -4491,6 +4504,12 @@
1.38 def analyse_types(self, env):
1.39 # The arg is always already analysed
1.40 pass
1.41 +
1.42 + def coerce_to_boolean(self, env):
1.43 + self.arg = self.arg.coerce_to_boolean(env)
1.44 + self.type = self.arg.type
1.45 + self.result_ctype = self.type
1.46 + return self
1.47
1.48 def generate_result_code(self, code):
1.49 #self.arg.generate_evaluation_code(code) # Already done
