From cc7e5865de3e68c1ec2a5a12d40a7925d7b95e2d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 31 Oct 2015 11:50:42 +0000 Subject: Implement divide and mod for Python backend --- .../couscous/backends/python/PrimitiveMethods.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/zwobble/couscous/backends/python/PrimitiveMethods.java') 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 methods, String methodName, -- cgit v1.2.3