diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-22 20:25:55 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-22 20:25:55 +0000 |
commit | 365274da13cc701e3e8f6c72a24dd4eb4083a88d (patch) | |
tree | 110170545eae9de4a584f08dd34d259cef0b70a0 /py/compile.c | |
parent | 0119fc7532c573bd596fb6173b4d36ef5260027a (diff) | |
parent | a6d53188b7db85af9dc93186e4f36b7009084ea6 (diff) | |
download | micropython-365274da13cc701e3e8f6c72a24dd4eb4083a88d.tar.gz micropython-365274da13cc701e3e8f6c72a24dd4eb4083a88d.zip |
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/py/compile.c b/py/compile.c index bb688d5d8e..0a10b81768 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <string.h> #include <assert.h> +#include <math.h> #include "misc.h" #include "mpconfig.h" @@ -15,6 +16,7 @@ #include "obj.h" #include "compile.h" #include "runtime.h" +#include "intdivmod.h" // TODO need to mangle __attr names @@ -140,11 +142,13 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) { } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_SLASH)) { ; // pass } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_PERCENT)) { - // XXX implement this properly as Python's % operator acts differently to C's - pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 % arg1); + pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, python_modulo(arg0, arg1)); } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_DBL_SLASH)) { - // XXX implement this properly as Python's // operator acts differently to C's - pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 / arg1); + //pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, + // floor((mp_float_t)arg0 / arg1)); + pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, + python_floor_divide(arg0, arg1)); + } else { // shouldn't happen assert(0); |