From abe9791453b42879ec43d39499405cd8d512915f Mon Sep 17 00:00:00 2001 From: "Matthew A. West" Date: Mon, 20 Apr 2015 10:29:18 -0400 Subject: [PATCH 1/6] Make remainder return Integer if both arguments are integers Only extend the rem operation to use math.fmod if one or both of the two arguments is not an integer. --- pixie/vm/numbers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pixie/vm/numbers.py b/pixie/vm/numbers.py index fe06eafd..6f1d029e 100644 --- a/pixie/vm/numbers.py +++ b/pixie/vm/numbers.py @@ -135,7 +135,8 @@ def define_num_ops(): continue extend_num_op(op, c1, c2, conv1, sym, conv2) extend_num_op("_quot", c1, c2, conv1, "/", conv2, wrap_start = "rt.wrap(math.floor(", wrap_end = "))") - extend_num_op("_rem", c1, c2, conv1, ",", conv2, wrap_start = "rt.wrap(math.fmod(", wrap_end = "))") + if c1 != Integer or c2 != Integer: + extend_num_op("_rem", c1, c2, conv1, ",", conv2, wrap_start = "rt.wrap(math.fmod(", wrap_end = "))") for (op, sym) in [("_num_eq", "=="), ("_lt", "<"), ("_gt", ">"), ("_lte", "<="), ("_gte", ">=")]: extend_num_op(op, c1, c2, conv1, sym, conv2, wrap_start = "true if ", wrap_end = " else false") From e53412cf1b7c957ee1d896be5c15f4a7d96fce9a Mon Sep 17 00:00:00 2001 From: "Matthew A. West" Date: Mon, 20 Apr 2015 10:39:26 -0400 Subject: [PATCH 2/6] Add note for Mac OS X building --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 658d8c59..69a01bf9 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Some planned and implemented features: make build_with_jit ./pixie-vm +Note: Mac OS X does not come with the build tools required by default. Install the XCode Command Line tools ([Apple Developer Site](http://developer.apple.com)) or install them independently. + ## Running the tests From a07f9e310552658cc2dcfd9df624aa3c2b5e6f74 Mon Sep 17 00:00:00 2001 From: "Matthew A. West" Date: Mon, 20 Apr 2015 17:35:38 -0400 Subject: [PATCH 3/6] Wrap _quot in a check whether its arguments are not both ints --- pixie/vm/numbers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pixie/vm/numbers.py b/pixie/vm/numbers.py index 6f1d029e..ed54bd53 100644 --- a/pixie/vm/numbers.py +++ b/pixie/vm/numbers.py @@ -134,9 +134,9 @@ def define_num_ops(): if op == "_div" and c1 == Integer and c2 == Integer: continue extend_num_op(op, c1, c2, conv1, sym, conv2) - extend_num_op("_quot", c1, c2, conv1, "/", conv2, wrap_start = "rt.wrap(math.floor(", wrap_end = "))") if c1 != Integer or c2 != Integer: extend_num_op("_rem", c1, c2, conv1, ",", conv2, wrap_start = "rt.wrap(math.fmod(", wrap_end = "))") + extend_num_op("_quot", c1, c2, conv1, "/", conv2, wrap_start = "rt.wrap(math.floor(", wrap_end = "))") for (op, sym) in [("_num_eq", "=="), ("_lt", "<"), ("_gt", ">"), ("_lte", "<="), ("_gte", ">=")]: extend_num_op(op, c1, c2, conv1, sym, conv2, wrap_start = "true if ", wrap_end = " else false") From 74231847156eed08d9cfa0b54b6ee3dacfd32554 Mon Sep 17 00:00:00 2001 From: "Matthew A. West" Date: Mon, 20 Apr 2015 21:57:17 -0400 Subject: [PATCH 4/6] Added tests to confirm changes --- tests/pixie/tests/test-numbers.pxi | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/pixie/tests/test-numbers.pxi b/tests/pixie/tests/test-numbers.pxi index 1d88d9d0..092aff5d 100644 --- a/tests/pixie/tests/test-numbers.pxi +++ b/tests/pixie/tests/test-numbers.pxi @@ -49,3 +49,16 @@ (t/deftest test-float (doseq [[x f] [[1 1.0] [3 3.0] [3.333 3.333] [3/2 1.5] [1/7 (/ 1.0 7.0)]]] (t/assert= (float x) f))) + +(t/deftest rem-types + (t/assert= "" (str (type (rem 5 3)))) + (t/assert= "" (str (type (rem 5.0 3)))) + (t/assert= "" (str (type (rem 7/2 3)))) + (t/assert= "" (str (type (rem 7/2 3.0))))) + +(t/deftest quot-types + (t/assert= "" (str (type (quot 5 3)))) + (t/assert= "" (str (type (quot 5.0 3)))) + (t/assert= "" (str (type (quot 7/2 3/7)))) + (t/assert= "" (str (type (quot 7/2 3.0))))) + From 8871f30356d2668f2fe96a501a5195d8459c15ea Mon Sep 17 00:00:00 2001 From: "Matthew A. West" Date: Tue, 21 Apr 2015 12:05:55 -0400 Subject: [PATCH 5/6] Change test to remove stringification --- tests/pixie/tests/test-numbers.pxi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/pixie/tests/test-numbers.pxi b/tests/pixie/tests/test-numbers.pxi index 092aff5d..efe36e2a 100644 --- a/tests/pixie/tests/test-numbers.pxi +++ b/tests/pixie/tests/test-numbers.pxi @@ -57,8 +57,8 @@ (t/assert= "" (str (type (rem 7/2 3.0))))) (t/deftest quot-types - (t/assert= "" (str (type (quot 5 3)))) - (t/assert= "" (str (type (quot 5.0 3)))) - (t/assert= "" (str (type (quot 7/2 3/7)))) - (t/assert= "" (str (type (quot 7/2 3.0))))) + (t/assert= Integer (type (quot 5 3))) + (t/assert= Float (type (quot 5.0 3))) + (t/assert= Integer (type (quot 7/2 3/7))) + (t/assert= Float (type (quot 7/2 3.0)))) From 103d36732fa54af0d6f6965d1fd75249daa6a5fd Mon Sep 17 00:00:00 2001 From: "Matthew A. West" Date: Tue, 21 Apr 2015 23:26:00 -0400 Subject: [PATCH 6/6] Fix to not use stringification for rem tests --- tests/pixie/tests/test-numbers.pxi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/pixie/tests/test-numbers.pxi b/tests/pixie/tests/test-numbers.pxi index efe36e2a..3b5f0aeb 100644 --- a/tests/pixie/tests/test-numbers.pxi +++ b/tests/pixie/tests/test-numbers.pxi @@ -51,10 +51,10 @@ (t/assert= (float x) f))) (t/deftest rem-types - (t/assert= "" (str (type (rem 5 3)))) - (t/assert= "" (str (type (rem 5.0 3)))) - (t/assert= "" (str (type (rem 7/2 3)))) - (t/assert= "" (str (type (rem 7/2 3.0))))) + (t/assert= Integer (type (rem 5 3))) + (t/assert= Float (type (rem 5.0 3))) + (t/assert= Ratio (type (rem 7/2 3))) + (t/assert= Float (type (rem 7/2 3.0)))) (t/deftest quot-types (t/assert= Integer (type (quot 5 3)))