From: Robert Bradshaw Date: Tue, 16 Jan 2007 02:21:26 +0000 (-0800) Subject: FloorDiv operation X-Git-Tag: 0.9.6.14~29^2~201 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=363eb37c521ef9aa6778d7b7cdf6a0756dd7b074;p=cython.git FloorDiv operation --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 66c00c82..ac09bcf9 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2421,6 +2421,7 @@ class NumBinopNode(BinopNode): "-": "PyNumber_Subtract", "*": "PyNumber_Multiply", "/": "PyNumber_Divide", + "//": "PyNumber_FloorDivide", "%": "PyNumber_Remainder", "**": "PyNumber_Power" } @@ -2479,6 +2480,16 @@ class MulNode(NumBinopNode): return NumBinopNode.is_py_operation(self) +class FloorDivNode(NumBinopNode): + # '//' operator. + + def calculate_result_code(self): + return "(%s %s %s)" % ( + self.operand1.result_code, + "/", # c division is by default floor-div + self.operand2.result_code) + + class ModNode(IntBinopNode): # '%' operator. @@ -2841,6 +2852,7 @@ binop_node_classes = { "-": SubNode, "*": MulNode, "/": NumBinopNode, + "//": FloorDivNode, "%": ModNode, "**": PowNode } diff --git a/Cython/Compiler/Lexicon.py b/Cython/Compiler/Lexicon.py index 479b6cdf..2e241c68 100644 --- a/Cython/Compiler/Lexicon.py +++ b/Cython/Compiler/Lexicon.py @@ -66,7 +66,7 @@ def make_lexicon(): bra = Any("([{") ket = Any(")]}") punct = Any(":,;+-*/|&<>=.%`~^?") - diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=") + diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=", "//") spaces = Rep1(Any(" \t\f")) comment = Str("#") + Rep(AnyBut("\n")) escaped_newline = Str("\\\n") diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index ab1ee178..fa6bb204 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -155,7 +155,7 @@ def p_arith_expr(s): #term: factor (('*'|'/'|'%') factor)* def p_term(s): - return p_binop_expr(s, ('*', '/', '%'), p_factor) + return p_binop_expr(s, ('*', '/', '%', '//'), p_factor) #factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power