parser: Convert (u)int to mp_(u)int_t.

This commit is contained in:
Damien George
2014-07-03 14:13:33 +01:00
parent 54eb4e723e
commit 381618269a
6 changed files with 55 additions and 54 deletions

View File

@@ -41,7 +41,7 @@
#include <math.h>
#endif
mp_obj_t mp_parse_num_integer(const char *restrict str_, uint len, int base) {
mp_obj_t mp_parse_num_integer(const char *restrict str_, mp_uint_t len, mp_uint_t base) {
const byte *restrict str = (const byte *)str_;
const byte *restrict top = str + len;
bool neg = false;
@@ -74,7 +74,7 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, uint len, int base) {
const byte *restrict str_val_start = str;
for (; str < top; str++) {
// get next digit as a value
int dig = *str;
mp_uint_t dig = *str;
if (unichar_isdigit(dig) && dig - '0' < base) {
// 0-9 digit
dig = dig - '0';
@@ -141,11 +141,13 @@ value_error:
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid syntax for integer with base %d: '%s'", base, str));
}
#define PARSE_DEC_IN_INTG (1)
#define PARSE_DEC_IN_FRAC (2)
#define PARSE_DEC_IN_EXP (3)
typedef enum {
PARSE_DEC_IN_INTG,
PARSE_DEC_IN_FRAC,
PARSE_DEC_IN_EXP,
} parse_dec_in_t;
mp_obj_t mp_parse_num_decimal(const char *str, uint len, bool allow_imag, bool force_complex) {
mp_obj_t mp_parse_num_decimal(const char *str, mp_uint_t len, bool allow_imag, bool force_complex) {
#if MICROPY_PY_BUILTINS_FLOAT
const char *top = str + len;
mp_float_t dec_val = 0;
@@ -187,12 +189,12 @@ mp_obj_t mp_parse_num_decimal(const char *str, uint len, bool allow_imag, bool f
}
} else {
// string should be a decimal number
int in = PARSE_DEC_IN_INTG;
parse_dec_in_t in = PARSE_DEC_IN_INTG;
bool exp_neg = false;
int exp_val = 0;
int exp_extra = 0;
mp_int_t exp_val = 0;
mp_int_t exp_extra = 0;
for (; str < top; str++) {
int dig = *str;
mp_uint_t dig = *str;
if ('0' <= dig && dig <= '9') {
dig -= '0';
if (in == PARSE_DEC_IN_EXP) {