Skip to content
Snippets Groups Projects
Commit 7c3a2e6c authored by Daniel Bauer's avatar Daniel Bauer :speech_balloon:
Browse files

add integer division

parent d4193f22
No related branches found
No related tags found
1 merge request!368Integer functions
...@@ -485,6 +485,12 @@ class PsDiv(PsBinOp): ...@@ -485,6 +485,12 @@ class PsDiv(PsBinOp):
pass pass
class PsIntDiv(PsBinOp):
@property
def python_operator(self) -> Callable[[Any, Any], Any] | None:
return operator.floordiv
class PsLeftShift(PsBinOp): class PsLeftShift(PsBinOp):
@property @property
def python_operator(self) -> Callable[[Any, Any], Any] | None: def python_operator(self) -> Callable[[Any, Any], Any] | None:
......
...@@ -24,6 +24,7 @@ from .ast.expressions import ( ...@@ -24,6 +24,7 @@ from .ast.expressions import (
PsSub, PsSub,
PsMul, PsMul,
PsDiv, PsDiv,
PsIntDiv,
PsNeg, PsNeg,
PsDeref, PsDeref,
PsAddressOf, PsAddressOf,
...@@ -321,7 +322,7 @@ class CAstPrinter: ...@@ -321,7 +322,7 @@ class CAstPrinter:
return ("-", Ops.Sub) return ("-", Ops.Sub)
case PsMul(): case PsMul():
return ("*", Ops.Mul) return ("*", Ops.Mul)
case PsDiv(): case PsDiv() | PsIntDiv():
return ("/", Ops.Div) return ("/", Ops.Div)
case PsLeftShift(): case PsLeftShift():
return ("<<", Ops.LeftShift) return ("<<", Ops.LeftShift)
......
...@@ -27,6 +27,7 @@ from ..ast.expressions import ( ...@@ -27,6 +27,7 @@ from ..ast.expressions import (
PsCall, PsCall,
PsCast, PsCast,
PsConstantExpr, PsConstantExpr,
PsIntDiv,
PsLeftShift, PsLeftShift,
PsLookup, PsLookup,
PsRightShift, PsRightShift,
...@@ -308,15 +309,17 @@ class FreezeExpressions: ...@@ -308,15 +309,17 @@ class FreezeExpressions:
match func: match func:
case sp.Abs(): case sp.Abs():
PsCall(PsMathFunction(MathFunctions.Abs), args) return PsCall(PsMathFunction(MathFunctions.Abs), args)
case sp.exp(): case sp.exp():
PsCall(PsMathFunction(MathFunctions.Exp), args) return PsCall(PsMathFunction(MathFunctions.Exp), args)
case sp.sin(): case sp.sin():
PsCall(PsMathFunction(MathFunctions.Sin), args) return PsCall(PsMathFunction(MathFunctions.Sin), args)
case sp.cos(): case sp.cos():
PsCall(PsMathFunction(MathFunctions.Cos), args) return PsCall(PsMathFunction(MathFunctions.Cos), args)
case sp.tan(): case sp.tan():
PsCall(PsMathFunction(MathFunctions.Tan), args) return PsCall(PsMathFunction(MathFunctions.Tan), args)
case integer_functions.int_div():
return PsIntDiv(*args)
case integer_functions.bit_shift_left(): case integer_functions.bit_shift_left():
return PsLeftShift(*args) return PsLeftShift(*args)
case integer_functions.bit_shift_right(): case integer_functions.bit_shift_right():
......
...@@ -31,6 +31,7 @@ from ..ast.expressions import ( ...@@ -31,6 +31,7 @@ from ..ast.expressions import (
PsCall, PsCall,
PsCast, PsCast,
PsConstantExpr, PsConstantExpr,
PsIntDiv,
PsLeftShift, PsLeftShift,
PsLookup, PsLookup,
PsRightShift, PsRightShift,
...@@ -265,7 +266,8 @@ class Typifier: ...@@ -265,7 +266,8 @@ class Typifier:
# integer operations # integer operations
case ( case (
PsLeftShift(op1, op2) PsIntDiv(op1, op2)
| PsLeftShift(op1, op2)
| PsRightShift(op1, op2) | PsRightShift(op1, op2)
| PsBitwiseAnd(op1, op2) | PsBitwiseAnd(op1, op2)
| PsBitwiseXor(op1, op2) | PsBitwiseXor(op1, op2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment