py: Convert [u]int to mp_[u]int_t where appropriate.

Addressing issue #50.
pull/889/head
Damien George 2014-10-03 17:44:14 +00:00
rodzic 877dba3e1a
commit 42f3de924b
25 zmienionych plików z 58 dodań i 80 usunięć

Wyświetl plik

@ -75,9 +75,9 @@ STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, mp_uint_t expecte
}
#if DEBUG_PRINT
STATIC void dump_args(const mp_obj_t *a, int sz) {
STATIC void dump_args(const mp_obj_t *a, mp_uint_t sz) {
DEBUG_printf("%p: ", a);
for (int i = 0; i < sz; i++) {
for (mp_uint_t i = 0; i < sz; i++) {
DEBUG_printf("%p ", a[i]);
}
DEBUG_printf("\n");
@ -179,7 +179,7 @@ continue2:;
// fill in defaults for positional args
mp_obj_t *d = &code_state->state[n_state - self->n_pos_args];
mp_obj_t *s = &self->extra_args[self->n_def_args - 1];
for (int i = self->n_def_args; i > 0; i--, d++, s--) {
for (mp_uint_t i = self->n_def_args; i > 0; i--, d++, s--) {
if (*d == MP_OBJ_NULL) {
*d = *s;
}

Wyświetl plik

@ -53,8 +53,8 @@ mp_uint_t mp_decode_uint(const byte **ptr);
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_obj_t inject_exc);
void mp_setup_code_state(mp_code_state *code_state, mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
void mp_bytecode_print(const void *descr, const byte *code, int len);
void mp_bytecode_print2(const byte *code, int len);
void mp_bytecode_print(const void *descr, const byte *code, mp_uint_t len);
void mp_bytecode_print2(const byte *code, mp_uint_t len);
// Helper macros to access pointer with least significant bit holding a flag
#define MP_TAGPTR_PTR(x) ((void*)((mp_uint_t)(x) & ~((mp_uint_t)1)))

Wyświetl plik

@ -99,7 +99,7 @@ int mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
return size;
}
mp_obj_t mp_binary_get_val_array(char typecode, void *p, int index) {
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
mp_int_t val = 0;
switch (typecode) {
case 'b':
@ -250,7 +250,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
mp_binary_set_int(MIN(size, sizeof(val)), struct_type == '>', p, in);
}
void mp_binary_set_val_array(char typecode, void *p, int index, mp_obj_t val_in) {
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in) {
switch (typecode) {
#if MICROPY_PY_BUILTINS_FLOAT
case 'f':
@ -265,7 +265,7 @@ void mp_binary_set_val_array(char typecode, void *p, int index, mp_obj_t val_in)
}
}
void mp_binary_set_val_array_from_int(char typecode, void *p, int index, mp_int_t val) {
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val) {
switch (typecode) {
case 'b':
((int8_t*)p)[index] = val;

Wyświetl plik

@ -29,9 +29,9 @@
#define BYTEARRAY_TYPECODE 0
int mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
mp_obj_t mp_binary_get_val_array(char typecode, void *p, int index);
void mp_binary_set_val_array(char typecode, void *p, int index, mp_obj_t val_in);
void mp_binary_set_val_array_from_int(char typecode, void *p, int index, mp_int_t val);
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index);
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in);
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val);
mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr);
void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **ptr);
long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, byte *p);

Wyświetl plik

@ -415,9 +415,9 @@ STATIC mp_obj_t mp_builtin_print(mp_uint_t n_args, const mp_obj_t *args, mp_map_
pfenv_t pfenv;
pfenv.data = stream_obj;
pfenv.print_strn = (void (*)(void *, const char *, unsigned int))mp_stream_write;
pfenv.print_strn = (void (*)(void *, const char *, mp_uint_t))mp_stream_write;
#endif
for (int i = 0; i < n_args; i++) {
for (mp_uint_t i = 0; i < n_args; i++) {
if (i > 0) {
#if MICROPY_PY_IO
mp_stream_write(stream_obj, sep_data, sep_len);

Wyświetl plik

@ -82,7 +82,7 @@ STATIC mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *d
return stat_dir_or_file(dest);
} else {
// go through each path looking for a directory or file
for (int i = 0; i < path_num; i++) {
for (mp_uint_t i = 0; i < path_num; i++) {
vstr_reset(dest);
mp_uint_t p_len;
const char *p = mp_obj_str_get_data(path_items[i], &p_len);
@ -167,7 +167,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
mp_obj_t mp_builtin___import__(mp_uint_t n_args, mp_obj_t *args) {
#if DEBUG_PRINT
DEBUG_printf("__import__:\n");
for (int i = 0; i < n_args; i++) {
for (mp_uint_t i = 0; i < n_args; i++) {
DEBUG_printf(" ");
mp_obj_print(args[i], PRINT_REPR);
DEBUG_printf("\n");
@ -176,7 +176,7 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, mp_obj_t *args) {
mp_obj_t module_name = args[0];
mp_obj_t fromtuple = mp_const_none;
int level = 0;
mp_int_t level = 0;
if (n_args >= 4) {
fromtuple = args[3];
if (n_args >= 5) {

Wyświetl plik

@ -493,7 +493,7 @@ STATIC void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vst
return;
}
int arg = MP_PARSE_NODE_LEAF_ARG(pn);
mp_uint_t arg = MP_PARSE_NODE_LEAF_ARG(pn);
switch (MP_PARSE_NODE_LEAF_KIND(pn)) {
case MP_PARSE_NODE_ID: assert(0);
case MP_PARSE_NODE_INTEGER: vstr_printf(vstr, "%s", qstr_str(arg)); break;
@ -853,7 +853,7 @@ STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_
assert(0);
} else if (MP_PARSE_NODE_IS_LEAF(pn)) {
if (MP_PARSE_NODE_IS_ID(pn)) {
int arg = MP_PARSE_NODE_LEAF_ARG(pn);
qstr arg = MP_PARSE_NODE_LEAF_ARG(pn);
switch (assign_kind) {
case ASSIGN_STORE:
case ASSIGN_AUG_STORE:

Wyświetl plik

@ -164,7 +164,7 @@ STATIC mp_obj_t struct_pack(uint n_args, mp_obj_t *args) {
// TODO: "The arguments must match the values required by the format exactly."
const char *fmt = mp_obj_str_get_str(args[0]);
char fmt_type = get_fmt_type(&fmt);
int size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
byte *p;
mp_obj_t res = mp_obj_str_builder_start(&mp_type_bytes, size, &p);
memset(p, 0, size);

Wyświetl plik

@ -58,7 +58,7 @@
returns sign(i - j)
assumes i, j are normalised
*/
STATIC mp_int_t mpn_cmp(const mpz_dig_t *idig, mp_uint_t ilen, const mpz_dig_t *jdig, mp_uint_t jlen) {
STATIC int mpn_cmp(const mpz_dig_t *idig, mp_uint_t ilen, const mpz_dig_t *jdig, mp_uint_t jlen) {
if (ilen < jlen) { return -1; }
if (ilen > jlen) { return 1; }
@ -361,7 +361,7 @@ STATIC void mpn_div(mpz_dig_t *num_dig, mp_uint_t *num_len, mpz_dig_t *den_dig,
// handle simple cases
{
mp_int_t cmp = mpn_cmp(num_dig, *num_len, den_dig, den_len);
int cmp = mpn_cmp(num_dig, *num_len, den_dig, den_len);
if (cmp == 0) {
*num_len = 0;
quo_dig[0] = 1;
@ -744,8 +744,8 @@ bool mpz_is_even(const mpz_t *z) {
return z->len == 0 || (z->dig[0] & 1) == 0;
}
mp_int_t mpz_cmp(const mpz_t *z1, const mpz_t *z2) {
mp_int_t cmp = z2->neg - z1->neg;
int mpz_cmp(const mpz_t *z1, const mpz_t *z2) {
int cmp = (int)z2->neg - (int)z1->neg;
if (cmp != 0) {
return cmp;
}

Wyświetl plik

@ -88,7 +88,7 @@ bool mpz_is_neg(const mpz_t *z);
bool mpz_is_odd(const mpz_t *z);
bool mpz_is_even(const mpz_t *z);
mp_int_t mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
mpz_t *mpz_abs(const mpz_t *z);
mpz_t *mpz_neg(const mpz_t *z);

Wyświetl plik

@ -212,9 +212,9 @@ typedef struct _mp_buffer_info_t {
// them with ver = sizeof(struct). Cons: overkill for *micro*?
//int ver; // ?
void *buf; // can be NULL if len == 0
mp_int_t len; // in bytes; TODO should it be mp_uint_t?
int typecode; // as per binary.h; TODO what is the correct type to use?
void *buf; // can be NULL if len == 0
mp_uint_t len; // in bytes
int typecode; // as per binary.h
// Rationale: to load arbitrary-sized sprites directly to LCD
// Cons: a bit adhoc usecase

Wyświetl plik

@ -66,7 +66,7 @@ STATIC void array_print(void (*print)(void *env, const char *fmt, ...), void *en
print(env, "array('%c'", o->typecode);
if (o->len > 0) {
print(env, ", [");
for (int i = 0; i < o->len; i++) {
for (mp_uint_t i = 0; i < o->len; i++) {
if (i > 0) {
print(env, ", ");
}
@ -92,7 +92,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
mp_obj_t iterable = mp_getiter(initializer);
mp_obj_t item;
int i = 0;
mp_uint_t i = 0;
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
if (len == 0) {
array_append(array, item);
@ -210,7 +210,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
return res;
#endif
} else {
uint index = mp_get_index(o->base.type, o->len, index_in, false);
mp_uint_t index = mp_get_index(o->base.type, o->len, index_in, false);
if (value == MP_OBJ_SENTINEL) {
// load
return mp_binary_get_val_array(o->typecode, o->items, index);

Wyświetl plik

@ -88,8 +88,8 @@ void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env,
// enough, a dynamic one will be allocated.
char stack_buf[sizeof(mp_int_t) * 4];
char *buf = stack_buf;
int buf_size = sizeof(stack_buf);
int fmt_size;
mp_uint_t buf_size = sizeof(stack_buf);
mp_uint_t fmt_size;
char *str = mp_obj_int_formatted(&buf, &buf_size, &fmt_size, self_in, 10, NULL, '\0', '\0');
print(env, "%s", str);
@ -135,7 +135,7 @@ STATIC uint int_as_str_size_formatted(uint base, const char *prefix, char comma)
//
// The resulting formatted string will be returned from this function and the
// formatted size will be in *fmt_size.
char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in,
char *mp_obj_int_formatted(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
int base, const char *prefix, char base_char, char comma) {
fmt_int_t num;
if (MP_OBJ_IS_SMALL_INT(self_in)) {

Wyświetl plik

@ -36,9 +36,9 @@ typedef struct _mp_obj_int_t {
extern const mp_obj_int_t mp_maxsize_obj;
void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind);
char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in,
char *mp_obj_int_formatted(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
int base, const char *prefix, char base_char, char comma);
char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in,
char *mp_obj_int_formatted_impl(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
int base, const char *prefix, char base_char, char comma);
mp_int_t mp_obj_int_hash(mp_obj_t self_in);
bool mp_obj_int_is_positive(mp_obj_t self_in);

Wyświetl plik

@ -81,12 +81,12 @@ STATIC mp_obj_int_t *mp_obj_int_new_mpz(void) {
// formatted size will be in *fmt_size.
//
// This particular routine should only be called for the mpz representation of the int.
char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in,
char *mp_obj_int_formatted_impl(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
int base, const char *prefix, char base_char, char comma) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
const mp_obj_int_t *self = self_in;
uint needed_size = mpz_as_str_size(&self->mpz, base, prefix, comma);
mp_uint_t needed_size = mpz_as_str_size(&self->mpz, base, prefix, comma);
if (needed_size > *buf_size) {
*buf = m_new(char, needed_size);
*buf_size = needed_size;

Wyświetl plik

@ -164,7 +164,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
assert(0);
}
int len_adj = slice.start - slice.stop;
mp_int_t len_adj = slice.start - slice.stop;
//printf("Len adj: %d\n", len_adj);
assert(len_adj <= 0);
mp_seq_replace_slice_no_grow(self->items, self->len, slice.start, slice.stop, self->items/*NULL*/, 0, mp_obj_t);
@ -203,7 +203,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) {
assert(0);
}
int len_adj = slice->len - (slice_out.stop - slice_out.start);
mp_int_t len_adj = slice->len - (slice_out.stop - slice_out.start);
//printf("Len adj: %d\n", len_adj);
if (len_adj > 0) {
if (self->len + len_adj > self->alloc) {

Wyświetl plik

@ -81,7 +81,7 @@ STATIC uint namedtuple_count_fields(const char *namedef) {
STATIC int namedtuple_find_field(const char *name, const char *namedef) {
int id = 0;
int len = strlen(name);
size_t len = strlen(name);
while (namedef) {
if (memcmp(name, namedef, len) == 0) {
namedef += len;
@ -101,9 +101,9 @@ STATIC void namedtuple_print(void (*print)(void *env, const char *fmt, ...), voi
print(env, "%s(", qstr_str(o->tuple.base.type->name));
const char *fields = ((mp_obj_namedtuple_type_t*)o->tuple.base.type)->fields;
for (int i = 0; i < o->tuple.len; i++) {
for (mp_uint_t i = 0; i < o->tuple.len; i++) {
if (i > 0) {
print(env, ", ");
print(env, ", ");
}
const char *next = fields;

Wyświetl plik

@ -63,7 +63,7 @@ STATIC const mp_obj_type_t range_it_type = {
.iternext = range_it_iternext,
};
mp_obj_t mp_obj_new_range_iterator(int cur, int stop, int step) {
STATIC mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step) {
mp_obj_range_it_t *o = m_new_obj(mp_obj_range_it_t);
o->base.type = &range_it_type;
o->cur = cur;

Wyświetl plik

@ -68,7 +68,6 @@ typedef struct _mp_parse_node_struct_t {
#define MP_PARSE_NODE_IS_TOKEN_KIND(pn, k) ((pn) == (MP_PARSE_NODE_TOKEN | ((k) << 5)))
#define MP_PARSE_NODE_LEAF_KIND(pn) ((pn) & 0x1f)
// TODO should probably have int and uint versions of this macro
#define MP_PARSE_NODE_LEAF_ARG(pn) (((mp_uint_t)(pn)) >> 5)
#define MP_PARSE_NODE_LEAF_SMALL_INT(pn) (((mp_int_t)(pn)) >> 1)
#define MP_PARSE_NODE_STRUCT_KIND(pns) ((pns)->kind_num_nodes & 0xff)

Wyświetl plik

@ -46,11 +46,11 @@
static const char pad_spaces[] = " ";
static const char pad_zeroes[] = "0000000000000000";
void pfenv_vstr_add_strn(void *data, const char *str, unsigned int len){
void pfenv_vstr_add_strn(void *data, const char *str, mp_uint_t len){
vstr_add_strn(data, str, len);
}
int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, int flags, char fill, int width) {
int pfenv_print_strn(const pfenv_t *pfenv, const char *str, mp_uint_t len, int flags, char fill, int width) {
int left_pad = 0;
int right_pad = 0;
int pad = width - len;
@ -234,8 +234,8 @@ int pfenv_print_mp_int(const pfenv_t *pfenv, mp_obj_t x, int sgn, int base, int
// enough, a dynamic one will be allocated.
char stack_buf[sizeof(mp_int_t) * 4];
char *buf = stack_buf;
int buf_size = sizeof(stack_buf);
int fmt_size = 0;
mp_uint_t buf_size = sizeof(stack_buf);
mp_uint_t fmt_size = 0;
char *str;
if (prec > 1) {

Wyświetl plik

@ -38,12 +38,12 @@
typedef struct _pfenv_t {
void *data;
void (*print_strn)(void *, const char *str, unsigned int len);
void (*print_strn)(void *, const char *str, mp_uint_t len);
} pfenv_t;
void pfenv_vstr_add_strn(void *data, const char *str, unsigned int len);
void pfenv_vstr_add_strn(void *data, const char *str, mp_uint_t len);
int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, int flags, char fill, int width);
int pfenv_print_strn(const pfenv_t *pfenv, const char *str, mp_uint_t len, int flags, char fill, int width);
int pfenv_print_int(const pfenv_t *pfenv, mp_uint_t x, int sgn, int base, int base_char, int flags, char fill, int width);
int pfenv_print_mp_int(const pfenv_t *pfenv, mp_obj_t x, int sgn, int base, int base_char, int flags, char fill, int width, int prec);
#if MICROPY_PY_BUILTINS_FLOAT

Wyświetl plik

@ -31,7 +31,7 @@
#if MICROPY_HELPER_REPL
bool str_startswith_word(const char *str, const char *head) {
int i;
mp_uint_t i;
for (i = 0; str[i] && head[i]; i++) {
if (str[i] != head[i]) {
return false;

Wyświetl plik

@ -44,7 +44,7 @@
// Implements backend of sequence * integer operation. Assumes elements are
// memory-adjacent in sequence.
void mp_seq_multiply(const void *items, mp_uint_t item_sz, mp_uint_t len, mp_uint_t times, void *dest) {
for (int i = 0; i < times; i++) {
for (mp_uint_t i = 0; i < times; i++) {
uint copy_sz = item_sz * len;
memcpy(dest, items, copy_sz);
dest = (char*)dest + copy_sz;
@ -185,8 +185,8 @@ bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, mp_uint_t len1, const
}
}
int len = len1 < len2 ? len1 : len2;
for (int i = 0; i < len; i++) {
mp_uint_t len = len1 < len2 ? len1 : len2;
for (mp_uint_t i = 0; i < len; i++) {
// If current elements equal, can't decide anything - go on
if (mp_obj_equal(items1[i], items2[i])) {
continue;

Wyświetl plik

@ -57,9 +57,7 @@
ip += sizeof(mp_uint_t); \
} while (0)
void mp_bytecode_print2(const byte *ip, int len);
void mp_bytecode_print(const void *descr, const byte *ip, int len) {
void mp_bytecode_print(const void *descr, const byte *ip, mp_uint_t len) {
const byte *ip_start = ip;
// get code info size
@ -115,14 +113,13 @@ void mp_bytecode_print(const void *descr, const byte *ip, int len) {
mp_bytecode_print2(ip, len - 0);
}
void mp_bytecode_print2(const byte *ip, int len) {
void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
const byte *ip_start = ip;
mp_uint_t unum;
qstr qstr;
while (ip - ip_start < len) {
printf("%02u ", (uint)(ip - ip_start));
int op = *ip++;
switch (op) {
switch (*ip++) {
case MP_BC_LOAD_CONST_FALSE:
printf("LOAD_CONST_FALSE");
break;
@ -520,7 +517,7 @@ void mp_bytecode_print2(const byte *ip, int len) {
break;
default:
printf("code %p, byte code 0x%02x not implemented\n", ip, op);
printf("code %p, byte code 0x%02x not implemented\n", ip, ip[-1]);
assert(0);
return;
}

Wyświetl plik

@ -263,24 +263,6 @@ copy:
vstr->buf[vstr->len] = 0;
}
/*
void vstr_add_le16(vstr_t *vstr, unsigned short v) {
byte *buf = (byte*)vstr_add_len(vstr, 2);
if (buf == NULL) {
return;
}
encode_le16(buf, v);
}
void vstr_add_le32(vstr_t *vstr, unsigned int v) {
byte *buf = (byte*)vstr_add_len(vstr, 4);
if (buf == NULL) {
return;
}
encode_le32(buf, v);
}
*/
char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) {
if (vstr->had_error) {
return NULL;