Commit 363eb37c authored by Robert Bradshaw's avatar Robert Bradshaw

FloorDiv operation

parent dbb891df
...@@ -2421,6 +2421,7 @@ class NumBinopNode(BinopNode): ...@@ -2421,6 +2421,7 @@ class NumBinopNode(BinopNode):
"-": "PyNumber_Subtract", "-": "PyNumber_Subtract",
"*": "PyNumber_Multiply", "*": "PyNumber_Multiply",
"/": "PyNumber_Divide", "/": "PyNumber_Divide",
"//": "PyNumber_FloorDivide",
"%": "PyNumber_Remainder", "%": "PyNumber_Remainder",
"**": "PyNumber_Power" "**": "PyNumber_Power"
} }
...@@ -2479,6 +2480,16 @@ class MulNode(NumBinopNode): ...@@ -2479,6 +2480,16 @@ class MulNode(NumBinopNode):
return NumBinopNode.is_py_operation(self) 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): class ModNode(IntBinopNode):
# '%' operator. # '%' operator.
...@@ -2841,6 +2852,7 @@ binop_node_classes = { ...@@ -2841,6 +2852,7 @@ binop_node_classes = {
"-": SubNode, "-": SubNode,
"*": MulNode, "*": MulNode,
"/": NumBinopNode, "/": NumBinopNode,
"//": FloorDivNode,
"%": ModNode, "%": ModNode,
"**": PowNode "**": PowNode
} }
......
...@@ -66,7 +66,7 @@ def make_lexicon(): ...@@ -66,7 +66,7 @@ def make_lexicon():
bra = Any("([{") bra = Any("([{")
ket = Any(")]}") ket = Any(")]}")
punct = Any(":,;+-*/|&<>=.%`~^?") punct = Any(":,;+-*/|&<>=.%`~^?")
diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=") diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=", "//")
spaces = Rep1(Any(" \t\f")) spaces = Rep1(Any(" \t\f"))
comment = Str("#") + Rep(AnyBut("\n")) comment = Str("#") + Rep(AnyBut("\n"))
escaped_newline = Str("\\\n") escaped_newline = Str("\\\n")
......
...@@ -155,7 +155,7 @@ def p_arith_expr(s): ...@@ -155,7 +155,7 @@ def p_arith_expr(s):
#term: factor (('*'|'/'|'%') factor)* #term: factor (('*'|'/'|'%') factor)*
def p_term(s): def p_term(s):
return p_binop_expr(s, ('*', '/', '%'), p_factor) return p_binop_expr(s, ('*', '/', '%', '//'), p_factor)
#factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power #factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment