diff options
Diffstat (limited to 'src/main/java/org/zwobble/couscous/backends/python/PrimitiveMethods.java')
| -rw-r--r-- | src/main/java/org/zwobble/couscous/backends/python/PrimitiveMethods.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/main/java/org/zwobble/couscous/backends/python/PrimitiveMethods.java b/src/main/java/org/zwobble/couscous/backends/python/PrimitiveMethods.java index 1da18f9..5208ff1 100644 --- a/src/main/java/org/zwobble/couscous/backends/python/PrimitiveMethods.java +++ b/src/main/java/org/zwobble/couscous/backends/python/PrimitiveMethods.java @@ -40,8 +40,15 @@ public class PrimitiveMethods { addMethod(methods, "add", "__add__"); addMethod(methods, "subtract", "__sub__"); addMethod(methods, "multiply", "__mul__"); - addMethod(methods, "divide", "__floordiv__"); - addMethod(methods, "mod", "__mod__"); + + methods.put("divide", (receiver, arguments) -> + pythonCall( + internalReference("_div_round_to_zero"), + asList(receiver, arguments.get(0)))); + methods.put("mod", (receiver, arguments) -> + pythonCall( + internalReference("_mod_round_to_zero"), + asList(receiver, arguments.get(0)))); addMethod(methods, "greaterThan", "__gt__"); addMethod(methods, "greaterThanOrEqual", "__ge__"); @@ -51,6 +58,10 @@ public class PrimitiveMethods { INT_METHODS = methods.build(); } + private static PythonExpressionNode internalReference(String name) { + return pythonAttributeAccess(pythonVariableReference("_couscous"), name); + } + private static void addMethod( Builder<String, PrimitiveMethodGenerator> methods, String methodName, |
