summaryrefslogtreecommitdiffstatshomepage
path: root/py/parse.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-01 19:50:50 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-01 19:50:50 +0000
commit06201ff3d6d9485b2657fc9ac4aa8a306884322f (patch)
treeade288601c3afccafa403ee8e7e569b83c1d8443 /py/parse.c
parent793838a919c9cb848cb8c3f2d88d8b347bfd6083 (diff)
downloadmicropython-06201ff3d6d9485b2657fc9ac4aa8a306884322f.tar.gz
micropython-06201ff3d6d9485b2657fc9ac4aa8a306884322f.zip
py: Implement bit-shift and not operations for mpz.
Implement not, shl and shr in mpz library. Add function to create mpzs on the stack, used for memory efficiency when rhs is a small int. Factor out code to parse base-prefix of number into a dedicated function.
Diffstat (limited to 'py/parse.c')
-rw-r--r--py/parse.c20
1 files changed, 3 insertions, 17 deletions
diff --git a/py/parse.c b/py/parse.c
index e70456e814..a7b73a5673 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -10,6 +10,7 @@
#include "mpconfig.h"
#include "qstr.h"
#include "lexer.h"
+#include "parsenumbase.h"
#include "parse.h"
#define RULE_ACT_KIND_MASK (0xf0)
@@ -241,23 +242,8 @@ STATIC void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
machine_int_t int_val = 0;
int len = tok->len;
const char *str = tok->str;
- int base = 10;
- int i = 0;
- if (len >= 3 && str[0] == '0') {
- if (str[1] == 'o' || str[1] == 'O') {
- // octal
- base = 8;
- i = 2;
- } else if (str[1] == 'x' || str[1] == 'X') {
- // hexadecimal
- base = 16;
- i = 2;
- } else if (str[1] == 'b' || str[1] == 'B') {
- // binary
- base = 2;
- i = 2;
- }
- }
+ int base = 0;
+ int i = mp_parse_num_base(str, len, &base);
bool overflow = false;
for (; i < len; i++) {
machine_int_t old_val = int_val;