From 40f3c026823f8951a2fa04e9c7fc93c75bc27bec Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 3 Jul 2014 13:25:24 +0100 Subject: [PATCH] Rename machine_(u)int_t to mp_(u)int_t. See discussion in issue #50. --- bare-arm/mpconfigport.h | 4 +- py/asmthumb.c | 6 +- py/asmthumb.h | 2 +- py/bc.h | 6 +- py/binary.c | 16 ++--- py/binary.h | 4 +- py/builtin.c | 18 +++--- py/compile.c | 46 ++++++------- py/emit.h | 2 +- py/emitbc.c | 14 ++-- py/emitcpy.c | 2 +- py/emitglue.c | 2 +- py/emitnative.c | 54 ++++++++-------- py/gc.c | 140 ++++++++++++++++++++-------------------- py/gc.h | 20 +++--- py/map.c | 4 +- py/misc.h | 2 +- py/modgc.c | 6 +- py/modmath.c | 2 +- py/modmicropython.c | 6 +- py/modstruct.c | 20 +++--- py/mpconfig.h | 10 +-- py/mpz.c | 30 ++++----- py/mpz.h | 26 ++++---- py/obj.c | 22 +++---- py/obj.h | 83 +++++++++++------------- py/objarray.c | 10 +-- py/objbool.c | 4 +- py/objclosure.c | 2 +- py/objdict.c | 14 ++-- py/objenumerate.c | 2 +- py/objexcept.c | 10 +-- py/objfun.c | 36 +++++------ py/objfun.h | 18 +++--- py/objgenerator.c | 6 +- py/objint.c | 22 +++---- py/objint_longlong.c | 8 +-- py/objint_mpz.c | 12 ++-- py/objlist.c | 4 +- py/objlist.h | 4 +- py/objmap.c | 2 +- py/objrange.c | 12 ++-- py/objset.c | 8 +-- py/objstr.c | 50 +++++++------- py/objstr.h | 6 +- py/objstringio.c | 10 +-- py/objstrunicode.c | 8 +-- py/objtuple.c | 6 +- py/objtuple.h | 2 +- py/objtype.c | 2 +- py/parse.c | 10 +-- py/parse.h | 8 +-- py/parsenum.c | 2 +- py/pfenv.c | 8 +-- py/pfenv.h | 2 +- py/qstr.c | 14 ++-- py/qstr.h | 6 +- py/runtime.c | 20 +++--- py/runtime.h | 4 +- py/sequence.c | 12 ++-- py/showbc.c | 20 +++--- py/smallint.c | 17 +++-- py/smallint.h | 10 +-- py/stream.c | 12 ++-- py/unicode.c | 8 +-- py/unicode.h | 2 +- py/vm.c | 26 ++++---- qemu-arm/mpconfigport.h | 4 +- stmhal/dac.c | 4 +- stmhal/extint.c | 10 +-- stmhal/file.c | 10 +-- stmhal/gccollect.c | 8 +-- stmhal/i2c.c | 16 ++--- stmhal/led.c | 8 +-- stmhal/modos.c | 2 +- stmhal/modpyb.c | 4 +- stmhal/mpconfigport.h | 4 +- stmhal/pin.c | 4 +- stmhal/pybstdio.c | 4 +- stmhal/rtc.c | 6 +- stmhal/servo.c | 2 +- stmhal/spi.c | 2 +- stmhal/timer.c | 2 +- stmhal/uart.c | 2 +- teensy/led.c | 4 +- teensy/main.c | 2 +- teensy/modpyb.c | 4 +- teensy/mpconfigport.h | 4 +- teensy/uart.c | 2 +- unix-cpy/mpconfigport.h | 10 +-- unix/file.c | 12 ++-- unix/gccollect.c | 10 +-- unix/main.c | 2 +- unix/modffi.c | 6 +- unix/modos.c | 14 ++-- unix/modsocket.c | 26 ++++---- unix/modtime.c | 4 +- unix/mpconfigport.h | 10 +-- windows/mpconfigport.h | 14 ++-- 99 files changed, 598 insertions(+), 604 deletions(-) diff --git a/bare-arm/mpconfigport.h b/bare-arm/mpconfigport.h index 85987354801f..bc427395b677 100644 --- a/bare-arm/mpconfigport.h +++ b/bare-arm/mpconfigport.h @@ -37,8 +37,8 @@ #define UINT_FMT "%lu" #define INT_FMT "%ld" -typedef int32_t machine_int_t; // must be pointer size -typedef uint32_t machine_uint_t; // must be pointer size +typedef int32_t mp_int_t; // must be pointer size +typedef uint32_t mp_uint_t; // must be pointer size typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size diff --git a/py/asmthumb.c b/py/asmthumb.c index 03752ed93813..a01599454483 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -133,7 +133,7 @@ uint asm_thumb_get_code_size(asm_thumb_t *as) { void *asm_thumb_get_code(asm_thumb_t *as) { // need to set low bit to indicate that it's thumb code - return (void *)(((machine_uint_t)as->code_base) | 1); + return (void *)(((mp_uint_t)as->code_base) | 1); } /* @@ -378,7 +378,7 @@ void asm_thumb_bcc_n(asm_thumb_t *as, int cond, uint label) { } } -void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, machine_uint_t i32) { +void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, mp_uint_t i32) { // movw, movt does it in 8 bytes // ldr [pc, #], dw does it in 6 bytes, but we might not reach to end of code for dw @@ -499,7 +499,7 @@ void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp if (0) { // load ptr to function into register using immediate, then branch // not relocatable - asm_thumb_mov_reg_i32(as, reg_temp, (machine_uint_t)fun_ptr); + asm_thumb_mov_reg_i32(as, reg_temp, (mp_uint_t)fun_ptr); asm_thumb_op16(as, OP_BLX(reg_temp)); } else if (1) { asm_thumb_op16(as, OP_FORMAT_9_10(ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_WORD_TRANSFER, reg_temp, REG_R7, fun_id)); diff --git a/py/asmthumb.h b/py/asmthumb.h index 1046b0353b2e..c650702647d8 100644 --- a/py/asmthumb.h +++ b/py/asmthumb.h @@ -185,7 +185,7 @@ void asm_thumb_ite_ge(asm_thumb_t *as); void asm_thumb_b_n(asm_thumb_t *as, uint label); void asm_thumb_bcc_n(asm_thumb_t *as, int cond, uint label); -void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, machine_uint_t i32_src); // convenience +void asm_thumb_mov_reg_i32(asm_thumb_t *as, uint reg_dest, mp_uint_t i32_src); // convenience void asm_thumb_mov_reg_i32_optimised(asm_thumb_t *as, uint reg_dest, int i32_src); // convenience void asm_thumb_mov_reg_i32_aligned(asm_thumb_t *as, uint reg_dest, int i32); // convenience void asm_thumb_mov_local_reg(asm_thumb_t *as, int local_num_dest, uint rlo_src); // convenience diff --git a/py/bc.h b/py/bc.h index db44f5482f59..3704dd7c7c09 100644 --- a/py/bc.h +++ b/py/bc.h @@ -55,6 +55,6 @@ void mp_bytecode_print(const void *descr, const byte *code, int len); void mp_bytecode_print2(const byte *code, int len); // Helper macros to access pointer with least significant bit holding a flag -#define MP_TAGPTR_PTR(x) ((void*)((machine_uint_t)(x) & ~((machine_uint_t)1))) -#define MP_TAGPTR_TAG(x) ((machine_uint_t)(x) & 1) -#define MP_TAGPTR_MAKE(ptr, tag) ((void*)((machine_uint_t)(ptr) | tag)) +#define MP_TAGPTR_PTR(x) ((void*)((mp_uint_t)(x) & ~((mp_uint_t)1))) +#define MP_TAGPTR_TAG(x) ((mp_uint_t)(x) & 1) +#define MP_TAGPTR_MAKE(ptr, tag) ((void*)((mp_uint_t)(ptr) | tag)) diff --git a/py/binary.c b/py/binary.c index d755bc86e04f..a0af97208d26 100644 --- a/py/binary.c +++ b/py/binary.c @@ -88,7 +88,7 @@ int mp_binary_get_size(char struct_type, char val_type, uint *palign) { } mp_obj_t mp_binary_get_val_array(char typecode, void *p, int index) { - machine_int_t val = 0; + mp_int_t val = 0; switch (typecode) { case 'b': val = ((int8_t*)p)[index]; @@ -125,7 +125,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, int index) { return MP_OBJ_NEW_SMALL_INT(val); } -machine_int_t mp_binary_get_int(uint size, bool is_signed, bool big_endian, byte *p) { +mp_int_t mp_binary_get_int(uint size, bool is_signed, bool big_endian, byte *p) { int delta; if (!big_endian) { delta = -1; @@ -134,7 +134,7 @@ machine_int_t mp_binary_get_int(uint size, bool is_signed, bool big_endian, byte delta = 1; } - machine_int_t val = 0; + mp_int_t val = 0; if (is_signed && *p & 0x80) { val = -1; } @@ -155,7 +155,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) { int size = mp_binary_get_size(struct_type, val_type, &align); if (struct_type == '@') { // Make pointer aligned - p = (byte*)(((machine_uint_t)p + align - 1) & ~((machine_uint_t)align - 1)); + p = (byte*)(((mp_uint_t)p + align - 1) & ~((mp_uint_t)align - 1)); #if MP_ENDIANNESS_LITTLE struct_type = '<'; #else @@ -164,7 +164,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) { } *ptr = p + size; - machine_int_t val = mp_binary_get_int(size, is_signed(val_type), (struct_type == '>'), p); + mp_int_t val = mp_binary_get_int(size, is_signed(val_type), (struct_type == '>'), p); if (val_type == 'O') { return (mp_obj_t)val; @@ -184,7 +184,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte ** int size = mp_binary_get_size(struct_type, val_type, &align); if (struct_type == '@') { // Make pointer aligned - p = (byte*)(((machine_uint_t)p + align - 1) & ~((machine_uint_t)align - 1)); + p = (byte*)(((mp_uint_t)p + align - 1) & ~((mp_uint_t)align - 1)); #if MP_ENDIANNESS_LITTLE struct_type = '<'; #else @@ -196,7 +196,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte ** #if MP_ENDIANNESS_BIG #error Not implemented #endif - machine_int_t val; + mp_int_t val; byte *in = (byte*)&val; switch (val_type) { case 'O': @@ -239,7 +239,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, machine_int_t val) { +void mp_binary_set_val_array_from_int(char typecode, void *p, int index, mp_int_t val) { switch (typecode) { case 'b': ((int8_t*)p)[index] = val; diff --git a/py/binary.h b/py/binary.h index 63ea5d741efb..f18f2402064b 100644 --- a/py/binary.h +++ b/py/binary.h @@ -31,7 +31,7 @@ int mp_binary_get_size(char struct_type, char val_type, uint *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, machine_int_t val); +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(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); -machine_int_t mp_binary_get_int(uint size, bool is_signed, bool big_endian, byte *p); +mp_int_t mp_binary_get_int(uint size, bool is_signed, bool big_endian, byte *p); diff --git a/py/builtin.c b/py/builtin.c index f4bbe0e237fb..e723fad334cb 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -99,7 +99,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj, mp_builtin___repl_print mp_obj_t mp_builtin_abs(mp_obj_t o_in) { if (MP_OBJ_IS_SMALL_INT(o_in)) { - mp_small_int_t val = MP_OBJ_SMALL_INT_VALUE(o_in); + mp_int_t val = MP_OBJ_SMALL_INT_VALUE(o_in); if (val < 0) { val = -val; } @@ -173,7 +173,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable); STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { #if MICROPY_PY_BUILTINS_STR_UNICODE - machine_int_t c = mp_obj_get_int(o_in); + mp_int_t c = mp_obj_get_int(o_in); char str[4]; int len = 0; if (c < 0x80) { @@ -198,7 +198,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { } return mp_obj_new_str(str, len, true); #else - machine_int_t ord = mp_obj_get_int(o_in); + mp_int_t ord = mp_obj_get_int(o_in); if (0 <= ord && ord <= 0x10ffff) { char str[1] = {ord}; return mp_obj_new_str(str, 1, true); @@ -250,8 +250,8 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_dir_obj, 0, 1, mp_builtin_dir); STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { if (MP_OBJ_IS_SMALL_INT(o1_in) && MP_OBJ_IS_SMALL_INT(o2_in)) { - mp_small_int_t i1 = MP_OBJ_SMALL_INT_VALUE(o1_in); - mp_small_int_t i2 = MP_OBJ_SMALL_INT_VALUE(o2_in); + mp_int_t i1 = MP_OBJ_SMALL_INT_VALUE(o1_in); + mp_int_t i2 = MP_OBJ_SMALL_INT_VALUE(o2_in); mp_obj_t args[2]; args[0] = MP_OBJ_NEW_SMALL_INT(i1 / i2); args[1] = MP_OBJ_NEW_SMALL_INT(i1 % i2); @@ -372,11 +372,11 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) { uint len; const char *str = mp_obj_str_get_data(o_in, &len); #if MICROPY_PY_BUILTINS_STR_UNICODE - machine_uint_t charlen = unichar_charlen(str, len); + mp_uint_t charlen = unichar_charlen(str, len); if (charlen == 1) { if (MP_OBJ_IS_STR(o_in) && UTF8_IS_NONASCII(*str)) { - machine_int_t ord = *str++ & 0x7F; - for (machine_int_t mask = 0x40; ord & mask; mask >>= 1) { + mp_int_t ord = *str++ & 0x7F; + for (mp_int_t mask = 0x40; ord & mask; mask >>= 1) { ord &= ~mask; } while (UTF8_IS_CONT(*str)) { @@ -478,7 +478,7 @@ STATIC mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *k MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_sorted_obj, 1, mp_builtin_sorted); STATIC mp_obj_t mp_builtin_id(mp_obj_t o_in) { - return mp_obj_new_int((machine_int_t)o_in); + return mp_obj_new_int((mp_int_t)o_in); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_id_obj, mp_builtin_id); diff --git a/py/compile.c b/py/compile.c index f2a108074fc7..c5f2166003ce 100644 --- a/py/compile.c +++ b/py/compile.c @@ -95,7 +95,7 @@ typedef struct _compiler_t { STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const char *msg) { // TODO store the error message to a variable in compiler_t instead of printing it if (MP_PARSE_NODE_IS_STRUCT(pn)) { - printf(" File \"%s\", line " UINT_FMT "\n", qstr_str(comp->source_file), (machine_uint_t)((mp_parse_node_struct_t*)pn)->source_line); + printf(" File \"%s\", line " UINT_FMT "\n", qstr_str(comp->source_file), (mp_uint_t)((mp_parse_node_struct_t*)pn)->source_line); } else { printf(" File \"%s\"\n", qstr_str(comp->source_file)); } @@ -158,7 +158,7 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m compile_syntax_error(comp, (mp_parse_node_t)pns, "constant must be an integer"); break; } - machine_int_t value = MP_PARSE_NODE_LEAF_SMALL_INT(pn_value); + mp_int_t value = MP_PARSE_NODE_LEAF_SMALL_INT(pn_value); // store the value in the table of dynamic constants mp_map_elem_t *elem = mp_map_lookup(consts, MP_OBJ_NEW_QSTR(id_qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); @@ -200,8 +200,8 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m case PN_expr: if (n == 2 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[1])) { // int | int - machine_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); - machine_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[1]); + mp_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); + mp_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[1]); pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 | arg1); } break; @@ -209,16 +209,16 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m case PN_and_expr: if (n == 2 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[1])) { // int & int - machine_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); - machine_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[1]); + mp_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); + mp_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[1]); pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 & arg1); } break; case PN_shift_expr: if (n == 3 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[2])) { - machine_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); - machine_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[2]); + mp_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); + mp_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[2]); if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_DBL_LESS)) { // int << int if (!(arg1 >= BITS_PER_WORD || arg0 > (MP_SMALL_INT_MAX >> arg1) || arg0 < (MP_SMALL_INT_MIN >> arg1))) { @@ -235,10 +235,10 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m break; case PN_arith_expr: - // overflow checking here relies on SMALL_INT being strictly smaller than machine_int_t + // overflow checking here relies on SMALL_INT being strictly smaller than mp_int_t if (n == 3 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[2])) { - machine_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); - machine_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[2]); + mp_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); + mp_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[2]); if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_PLUS)) { // int + int arg0 += arg1; @@ -258,8 +258,8 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m case PN_term: if (n == 3 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[2])) { - machine_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); - machine_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[2]); + mp_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); + mp_int_t arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[2]); if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_STAR)) { // int * int if (!mp_small_int_mul_overflow(arg0, arg1)) { @@ -288,7 +288,7 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m case PN_factor_2: if (MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[1])) { - machine_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[1]); + mp_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[1]); if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_PLUS)) { // +int pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg); @@ -336,7 +336,7 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m mp_obj_t dest[2]; mp_load_method_maybe(elem->value, q_attr, dest); if (MP_OBJ_IS_SMALL_INT(dest[0]) && dest[1] == NULL) { - machine_int_t val = MP_OBJ_SMALL_INT_VALUE(dest[0]); + mp_int_t val = MP_OBJ_SMALL_INT_VALUE(dest[0]); if (MP_SMALL_INT_FITS(val)) { pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, val); } @@ -482,7 +482,7 @@ STATIC void cpython_c_print_quoted_str(vstr_t *vstr, const char *str, uint len, STATIC void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vstr_t *vstr) { if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_string)) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; - cpython_c_print_quoted_str(vstr, (const char*)pns->nodes[0], (machine_uint_t)pns->nodes[1], false); + cpython_c_print_quoted_str(vstr, (const char*)pns->nodes[0], (mp_uint_t)pns->nodes[1], false); return; } @@ -2528,7 +2528,7 @@ void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_struct_t *pns_string = (mp_parse_node_struct_t*)pns->nodes[i]; assert(MP_PARSE_NODE_STRUCT_KIND(pns_string) == PN_string); pn_kind = MP_PARSE_NODE_STRING; - n_bytes += (machine_uint_t)pns_string->nodes[1]; + n_bytes += (mp_uint_t)pns_string->nodes[1]; } if (i == 0) { string_kind = pn_kind; @@ -2549,8 +2549,8 @@ void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) { s_dest += s_len; } else { mp_parse_node_struct_t *pns_string = (mp_parse_node_struct_t*)pns->nodes[i]; - memcpy(s_dest, (const char*)pns_string->nodes[0], (machine_uint_t)pns_string->nodes[1]); - s_dest += (machine_uint_t)pns_string->nodes[1]; + memcpy(s_dest, (const char*)pns_string->nodes[0], (mp_uint_t)pns_string->nodes[1]); + s_dest += (mp_uint_t)pns_string->nodes[1]; } } qstr q = qstr_build_end(q_ptr); @@ -2858,10 +2858,10 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_NULL(pn)) { // pass } else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { - machine_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn); + mp_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn); EMIT_ARG(load_const_small_int, arg); } else if (MP_PARSE_NODE_IS_LEAF(pn)) { - machine_uint_t 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: EMIT_ARG(load_id, arg); break; case MP_PARSE_NODE_INTEGER: EMIT_ARG(load_const_int, arg); break; @@ -2883,7 +2883,7 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; EMIT_ARG(set_line_number, pns->source_line); if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_string) { - EMIT_ARG(load_const_str, qstr_from_strn((const char*)pns->nodes[0], (machine_uint_t)pns->nodes[1]), false); + EMIT_ARG(load_const_str, qstr_from_strn((const char*)pns->nodes[0], (mp_uint_t)pns->nodes[1]), false); } else { compile_function_t f = compile_function[MP_PARSE_NODE_STRUCT_KIND(pns)]; if (f == NULL) { @@ -3337,7 +3337,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind return; } if (pass > MP_PASS_SCOPE) { - machine_int_t bytesize = MP_PARSE_NODE_LEAF_SMALL_INT(pn_arg[0]); + mp_int_t bytesize = MP_PARSE_NODE_LEAF_SMALL_INT(pn_arg[0]); for (uint i = 1; i < n_args; i++) { if (!MP_PARSE_NODE_IS_SMALL_INT(pn_arg[i])) { compile_syntax_error(comp, nodes[i], "inline assembler 'data' requires integer arguments"); diff --git a/py/emit.h b/py/emit.h index 03834cb213b3..c760344c1f1e 100644 --- a/py/emit.h +++ b/py/emit.h @@ -65,7 +65,7 @@ typedef struct _emit_method_table_t { void (*import_from)(emit_t *emit, qstr qstr); void (*import_star)(emit_t *emit); void (*load_const_tok)(emit_t *emit, mp_token_kind_t tok); - void (*load_const_small_int)(emit_t *emit, machine_int_t arg); + void (*load_const_small_int)(emit_t *emit, mp_int_t arg); void (*load_const_int)(emit_t *emit, qstr qstr); void (*load_const_dec)(emit_t *emit, qstr qstr); void (*load_const_str)(emit_t *emit, qstr qstr, bool bytes); diff --git a/py/emitbc.c b/py/emitbc.c index f9fbed4aaf20..ebc2ba500399 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -99,7 +99,7 @@ STATIC byte* emit_get_cur_to_write_code_info(emit_t* emit, int num_bytes_to_writ } STATIC void emit_align_code_info_to_machine_word(emit_t* emit) { - emit->code_info_offset = (emit->code_info_offset + sizeof(machine_uint_t) - 1) & (~(sizeof(machine_uint_t) - 1)); + emit->code_info_offset = (emit->code_info_offset + sizeof(mp_uint_t) - 1) & (~(sizeof(mp_uint_t) - 1)); } STATIC void emit_write_code_info_qstr(emit_t* emit, qstr qstr) { @@ -139,7 +139,7 @@ STATIC byte* emit_get_cur_to_write_bytecode(emit_t* emit, int num_bytes_to_write } STATIC void emit_align_bytecode_to_machine_word(emit_t* emit) { - emit->bytecode_offset = (emit->bytecode_offset + sizeof(machine_uint_t) - 1) & (~(sizeof(machine_uint_t) - 1)); + emit->bytecode_offset = (emit->bytecode_offset + sizeof(mp_uint_t) - 1) & (~(sizeof(mp_uint_t) - 1)); } STATIC void emit_write_bytecode_byte(emit_t* emit, byte b1) { @@ -171,7 +171,7 @@ STATIC void emit_write_bytecode_uint(emit_t* emit, uint num) { } // Similar to emit_write_bytecode_uint(), just some extra handling to encode sign -STATIC void emit_write_bytecode_byte_int(emit_t* emit, byte b1, machine_int_t num) { +STATIC void emit_write_bytecode_byte_int(emit_t* emit, byte b1, mp_int_t num) { emit_write_bytecode_byte(emit, b1); // We store each 7 bits in a separate byte, and that's how many bytes needed @@ -206,8 +206,8 @@ STATIC void emit_write_bytecode_byte_uint(emit_t* emit, byte b, uint num) { STATIC void emit_write_bytecode_byte_ptr(emit_t* emit, byte b, void *ptr) { emit_write_bytecode_byte(emit, b); emit_align_bytecode_to_machine_word(emit); - machine_uint_t *c = (machine_uint_t*)emit_get_cur_to_write_bytecode(emit, sizeof(machine_uint_t)); - *c = (machine_uint_t)ptr; + mp_uint_t *c = (mp_uint_t*)emit_get_cur_to_write_bytecode(emit, sizeof(mp_uint_t)); + *c = (mp_uint_t)ptr; } /* currently unused @@ -269,7 +269,7 @@ STATIC void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { // write code info size; use maximum space (4 bytes) to write it; TODO possible optimise this { byte* c = emit_get_cur_to_write_code_info(emit, 4); - machine_uint_t s = emit->code_info_size; + mp_uint_t s = emit->code_info_size; c[0] = s & 0xff; c[1] = (s >> 8) & 0xff; c[2] = (s >> 16) & 0xff; @@ -428,7 +428,7 @@ STATIC void emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) { } } -STATIC void emit_bc_load_const_small_int(emit_t *emit, machine_int_t arg) { +STATIC void emit_bc_load_const_small_int(emit_t *emit, mp_int_t arg) { emit_bc_pre(emit, 1); emit_write_bytecode_byte_int(emit, MP_BC_LOAD_CONST_SMALL_INT, arg); } diff --git a/py/emitcpy.c b/py/emitcpy.c index 4ff99866a053..c0d15a8716a7 100644 --- a/py/emitcpy.c +++ b/py/emitcpy.c @@ -173,7 +173,7 @@ STATIC void emit_cpy_load_const_tok(emit_t *emit, mp_token_kind_t tok) { } } -STATIC void emit_cpy_load_const_small_int(emit_t *emit, machine_int_t arg) { +STATIC void emit_cpy_load_const_small_int(emit_t *emit, mp_int_t arg) { emit_pre(emit, 1, 3); if (emit->pass == MP_PASS_EMIT) { printf("LOAD_CONST " INT_FMT "\n", arg); diff --git a/py/emitglue.c b/py/emitglue.c index 17dc8f867c13..91570bc63d16 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -95,7 +95,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void #ifdef DEBUG_PRINT DEBUG_printf("assign native: kind=%d fun=%p len=%u n_args=%d\n", kind, fun, len, n_args); - byte *fun_data = (byte*)(((machine_uint_t)fun) & (~1)); // need to clear lower bit in case it's thumb code + byte *fun_data = (byte*)(((mp_uint_t)fun) & (~1)); // need to clear lower bit in case it's thumb code for (int i = 0; i < 128 && i < len; i++) { if (i > 0 && i % 16 == 0) { DEBUG_printf("\n"); diff --git a/py/emitnative.c b/py/emitnative.c index 4cab3f469711..dde582d0954c 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -140,7 +140,7 @@ typedef struct _stack_info_t { stack_info_kind_t kind; union { int u_reg; - machine_int_t u_imm; + mp_int_t u_imm; }; } stack_info_t; @@ -285,7 +285,7 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop } } - asm_thumb_mov_reg_i32(emit->as, REG_R7, (machine_uint_t)mp_fun_table); + asm_thumb_mov_reg_i32(emit->as, REG_R7, (mp_uint_t)mp_fun_table); #endif } @@ -472,7 +472,7 @@ STATIC void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { adjust_stack(emit, 1); } -STATIC void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, machine_int_t imm) { +STATIC void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, mp_int_t imm) { stack_info_t *si = &emit->stack_info[emit->stack_size]; si->vtype = vtype; si->kind = STACK_IMM; @@ -516,9 +516,9 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, in case VTYPE_BOOL: si->vtype = VTYPE_PYOBJ; if (si->u_imm == 0) { - ASM_MOV_IMM_TO_LOCAL_USING((machine_uint_t)mp_const_false, emit->stack_start + emit->stack_size - 1 - i, reg_dest); + ASM_MOV_IMM_TO_LOCAL_USING((mp_uint_t)mp_const_false, emit->stack_start + emit->stack_size - 1 - i, reg_dest); } else { - ASM_MOV_IMM_TO_LOCAL_USING((machine_uint_t)mp_const_true, emit->stack_start + emit->stack_size - 1 - i, reg_dest); + ASM_MOV_IMM_TO_LOCAL_USING((mp_uint_t)mp_const_true, emit->stack_start + emit->stack_size - 1 - i, reg_dest); } break; case VTYPE_INT: @@ -557,7 +557,7 @@ STATIC void emit_call(emit_t *emit, mp_fun_kind_t fun_kind, void *fun) { #endif } -STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, machine_int_t arg_val, int arg_reg) { +STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, mp_int_t arg_val, int arg_reg) { need_reg_all(emit); ASM_MOV_IMM_TO_REG(arg_val, arg_reg); #if N_X64 @@ -567,8 +567,8 @@ STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, void *f #endif } -// the first arg is stored in the code aligned on a machine_uint_t boundary -STATIC void emit_call_with_imm_arg_aligned(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, machine_int_t arg_val, int arg_reg) { +// the first arg is stored in the code aligned on a mp_uint_t boundary +STATIC void emit_call_with_imm_arg_aligned(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, mp_int_t arg_val, int arg_reg) { need_reg_all(emit); ASM_MOV_ALIGNED_IMM_TO_REG(arg_val, arg_reg); #if N_X64 @@ -578,7 +578,7 @@ STATIC void emit_call_with_imm_arg_aligned(emit_t *emit, mp_fun_kind_t fun_kind, #endif } -STATIC void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, machine_int_t arg_val1, int arg_reg1, machine_int_t arg_val2, int arg_reg2) { +STATIC void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, mp_int_t arg_val1, int arg_reg1, mp_int_t arg_val2, int arg_reg2) { need_reg_all(emit); ASM_MOV_IMM_TO_REG(arg_val1, arg_reg1); ASM_MOV_IMM_TO_REG(arg_val2, arg_reg2); @@ -589,8 +589,8 @@ STATIC void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, void #endif } -// the first arg is stored in the code aligned on a machine_uint_t boundary -STATIC void emit_call_with_3_imm_args_and_first_aligned(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, machine_int_t arg_val1, int arg_reg1, machine_int_t arg_val2, int arg_reg2, machine_int_t arg_val3, int arg_reg3) { +// the first arg is stored in the code aligned on a mp_uint_t boundary +STATIC void emit_call_with_3_imm_args_and_first_aligned(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, mp_int_t arg_val1, int arg_reg1, mp_int_t arg_val2, int arg_reg2, mp_int_t arg_val3, int arg_reg3) { need_reg_all(emit); ASM_MOV_ALIGNED_IMM_TO_REG(arg_val1, arg_reg1); ASM_MOV_IMM_TO_REG(arg_val2, arg_reg2); @@ -671,7 +671,7 @@ STATIC void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { DEBUG_printf("load_const_tok %d\n", tok); emit_native_pre(emit); int vtype; - machine_uint_t val; + mp_uint_t val; if (emit->do_viper_types) { switch (tok) { case MP_TOKEN_KW_NONE: vtype = VTYPE_PTR_NONE; val = 0; break; @@ -682,16 +682,16 @@ STATIC void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { } else { vtype = VTYPE_PYOBJ; switch (tok) { - case MP_TOKEN_KW_NONE: val = (machine_uint_t)mp_const_none; break; - case MP_TOKEN_KW_FALSE: val = (machine_uint_t)mp_const_false; break; - case MP_TOKEN_KW_TRUE: val = (machine_uint_t)mp_const_true; break; + case MP_TOKEN_KW_NONE: val = (mp_uint_t)mp_const_none; break; + case MP_TOKEN_KW_FALSE: val = (mp_uint_t)mp_const_false; break; + case MP_TOKEN_KW_TRUE: val = (mp_uint_t)mp_const_true; break; default: assert(0); vtype = 0; val = 0; // shouldn't happen } } emit_post_push_imm(emit, vtype, val); } -STATIC void emit_native_load_const_small_int(emit_t *emit, machine_int_t arg) { +STATIC void emit_native_load_const_small_int(emit_t *emit, mp_int_t arg) { DEBUG_printf("load_const_small_int %d\n", arg); emit_native_pre(emit); if (emit->do_viper_types) { @@ -722,7 +722,7 @@ STATIC void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) { // not implemented properly // load a pointer to the asciiz string? assert(0); - emit_post_push_imm(emit, VTYPE_PTR, (machine_uint_t)qstr_str(qstr)); + emit_post_push_imm(emit, VTYPE_PTR, (mp_uint_t)qstr_str(qstr)); } else { if (bytes) { emit_call_with_imm_arg(emit, 0, mp_load_const_bytes, qstr, REG_ARG_1); // TODO need to add function to runtime table @@ -815,7 +815,7 @@ STATIC void emit_native_load_subscr(emit_t *emit) { vtype_kind_t vtype_lhs, vtype_rhs; emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_2, &vtype_lhs, REG_ARG_1); if (vtype_lhs == VTYPE_PYOBJ && vtype_rhs == VTYPE_PYOBJ) { - emit_call_with_imm_arg(emit, MP_F_OBJ_SUBSCR, mp_obj_subscr, (machine_uint_t)MP_OBJ_SENTINEL, REG_ARG_3); + emit_call_with_imm_arg(emit, MP_F_OBJ_SUBSCR, mp_obj_subscr, (mp_uint_t)MP_OBJ_SENTINEL, REG_ARG_3); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } else { printf("ViperTypeError: can't do subscr of types %d and %d\n", vtype_lhs, vtype_rhs); @@ -925,7 +925,7 @@ STATIC void emit_native_delete_attr(emit_t *emit, qstr qstr) { vtype_kind_t vtype_base; emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base assert(vtype_base == VTYPE_PYOBJ); - emit_call_with_2_imm_args(emit, MP_F_STORE_ATTR, mp_store_attr, qstr, REG_ARG_2, (machine_uint_t)MP_OBJ_NULL, REG_ARG_3); // arg2 = attribute name, arg3 = value (null for delete) + emit_call_with_2_imm_args(emit, MP_F_STORE_ATTR, mp_store_attr, qstr, REG_ARG_2, (mp_uint_t)MP_OBJ_NULL, REG_ARG_3); // arg2 = attribute name, arg3 = value (null for delete) emit_post(emit); } @@ -934,7 +934,7 @@ STATIC void emit_native_delete_subscr(emit_t *emit) { emit_pre_pop_reg_reg(emit, &vtype_index, REG_ARG_2, &vtype_base, REG_ARG_1); // index, base assert(vtype_index == VTYPE_PYOBJ); assert(vtype_base == VTYPE_PYOBJ); - emit_call_with_imm_arg(emit, MP_F_OBJ_SUBSCR, mp_obj_subscr, (machine_uint_t)MP_OBJ_NULL, REG_ARG_3); + emit_call_with_imm_arg(emit, MP_F_OBJ_SUBSCR, mp_obj_subscr, (mp_uint_t)MP_OBJ_NULL, REG_ARG_3); } STATIC void emit_native_dup_top(emit_t *emit) { @@ -1071,7 +1071,7 @@ STATIC void emit_native_setup_except(emit_t *emit, uint label) { emit_native_pre(emit); // need to commit stack because we may jump elsewhere need_stack_settled(emit); - emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(machine_uint_t)); // arg1 = pointer to nlr buf + emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(mp_uint_t)); // arg1 = pointer to nlr buf emit_call(emit, 0, nlr_push); // TODO need to add function to runtime table #if N_X64 asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET); @@ -1108,7 +1108,7 @@ STATIC void emit_native_for_iter(emit_t *emit, uint label) { emit_access_stack(emit, 1, &vtype, REG_ARG_1); assert(vtype == VTYPE_PYOBJ); emit_call(emit, MP_F_ITERNEXT, mp_iternext); - ASM_MOV_IMM_TO_REG((machine_uint_t)MP_OBJ_STOP_ITERATION, REG_TEMP1); + ASM_MOV_IMM_TO_REG((mp_uint_t)MP_OBJ_STOP_ITERATION, REG_TEMP1); #if N_X64 asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1); asm_x64_jcc_label(emit->as, JCC_JE, label); @@ -1129,7 +1129,7 @@ STATIC void emit_native_for_iter_end(emit_t *emit) { STATIC void emit_native_pop_block(emit_t *emit) { emit_native_pre(emit); emit_call(emit, 0, nlr_pop); // TODO need to add function to runtime table - adjust_stack(emit, -(machine_int_t)(sizeof(nlr_buf_t) / sizeof(machine_uint_t))); + adjust_stack(emit, -(mp_int_t)(sizeof(nlr_buf_t) / sizeof(mp_uint_t))); emit_post(emit); } @@ -1137,7 +1137,7 @@ STATIC void emit_native_pop_except(emit_t *emit) { /* emit_native_pre(emit); emit_call(emit, 0, nlr_pop); // TODO need to add function to runtime table - adjust_stack(emit, -(machine_int_t)(sizeof(nlr_buf_t) / sizeof(machine_uint_t))); + adjust_stack(emit, -(mp_int_t)(sizeof(nlr_buf_t) / sizeof(mp_uint_t))); emit_post(emit); */ } @@ -1271,7 +1271,7 @@ STATIC void emit_native_build_slice(emit_t *emit, int n_args) { emit_pre_pop_reg_reg(emit, &vtype_stop, REG_ARG_2, &vtype_start, REG_ARG_1); // arg1 = start, arg2 = stop assert(vtype_start == VTYPE_PYOBJ); assert(vtype_stop == VTYPE_PYOBJ); - emit_call_with_imm_arg(emit, MP_F_NEW_SLICE, mp_obj_new_slice, (machine_uint_t)mp_const_none, REG_ARG_3); // arg3 = step + emit_call_with_imm_arg(emit, MP_F_NEW_SLICE, mp_obj_new_slice, (mp_uint_t)mp_const_none, REG_ARG_3); // arg3 = step emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } else { assert(n_args == 3); @@ -1307,13 +1307,13 @@ STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, uint n_pos_d // call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them emit_native_pre(emit); if (n_pos_defaults == 0 && n_kw_defaults == 0) { - emit_call_with_3_imm_args_and_first_aligned(emit, MP_F_MAKE_FUNCTION_FROM_RAW_CODE, mp_make_function_from_raw_code, (machine_uint_t)scope->raw_code, REG_ARG_1, (machine_uint_t)MP_OBJ_NULL, REG_ARG_2, (machine_uint_t)MP_OBJ_NULL, REG_ARG_3); + emit_call_with_3_imm_args_and_first_aligned(emit, MP_F_MAKE_FUNCTION_FROM_RAW_CODE, mp_make_function_from_raw_code, (mp_uint_t)scope->raw_code, REG_ARG_1, (mp_uint_t)MP_OBJ_NULL, REG_ARG_2, (mp_uint_t)MP_OBJ_NULL, REG_ARG_3); } else { vtype_kind_t vtype_def_tuple, vtype_def_dict; emit_pre_pop_reg_reg(emit, &vtype_def_dict, REG_ARG_3, &vtype_def_tuple, REG_ARG_2); assert(vtype_def_tuple == VTYPE_PYOBJ); assert(vtype_def_dict == VTYPE_PYOBJ); - emit_call_with_imm_arg_aligned(emit, MP_F_MAKE_FUNCTION_FROM_RAW_CODE, mp_make_function_from_raw_code, (machine_uint_t)scope->raw_code, REG_ARG_1); + emit_call_with_imm_arg_aligned(emit, MP_F_MAKE_FUNCTION_FROM_RAW_CODE, mp_make_function_from_raw_code, (mp_uint_t)scope->raw_code, REG_ARG_1); } emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } diff --git a/py/gc.c b/py/gc.c index 7aa5bc326eef..802c1b1edc58 100644 --- a/py/gc.c +++ b/py/gc.c @@ -51,17 +51,17 @@ #define STACK_SIZE (64) // tunable; minimum is 1 STATIC byte *gc_alloc_table_start; -STATIC machine_uint_t gc_alloc_table_byte_len; +STATIC mp_uint_t gc_alloc_table_byte_len; #if MICROPY_ENABLE_FINALISER STATIC byte *gc_finaliser_table_start; #endif -STATIC machine_uint_t *gc_pool_start; -STATIC machine_uint_t *gc_pool_end; +STATIC mp_uint_t *gc_pool_start; +STATIC mp_uint_t *gc_pool_end; STATIC int gc_stack_overflow; -STATIC machine_uint_t gc_stack[STACK_SIZE]; -STATIC machine_uint_t *gc_sp; -STATIC machine_uint_t gc_lock_depth; +STATIC mp_uint_t gc_stack[STACK_SIZE]; +STATIC mp_uint_t *gc_sp; +STATIC mp_uint_t gc_lock_depth; // ATB = allocation table byte // 0b00 = FREE -- free block @@ -93,8 +93,8 @@ STATIC machine_uint_t gc_lock_depth; #define ATB_HEAD_TO_MARK(block) do { gc_alloc_table_start[(block) / BLOCKS_PER_ATB] |= (AT_MARK << BLOCK_SHIFT(block)); } while (0) #define ATB_MARK_TO_HEAD(block) do { gc_alloc_table_start[(block) / BLOCKS_PER_ATB] &= (~(AT_TAIL << BLOCK_SHIFT(block))); } while (0) -#define BLOCK_FROM_PTR(ptr) (((ptr) - (machine_uint_t)gc_pool_start) / BYTES_PER_BLOCK) -#define PTR_FROM_BLOCK(block) (((block) * BYTES_PER_BLOCK + (machine_uint_t)gc_pool_start)) +#define BLOCK_FROM_PTR(ptr) (((ptr) - (mp_uint_t)gc_pool_start) / BYTES_PER_BLOCK) +#define PTR_FROM_BLOCK(block) (((block) * BYTES_PER_BLOCK + (mp_uint_t)gc_pool_start)) #define ATB_FROM_BLOCK(bl) ((bl) / BLOCKS_PER_ATB) #if MICROPY_ENABLE_FINALISER @@ -111,7 +111,7 @@ STATIC machine_uint_t gc_lock_depth; // TODO waste less memory; currently requires that all entries in alloc_table have a corresponding block in pool void gc_init(void *start, void *end) { // align end pointer on block boundary - end = (void*)((machine_uint_t)end & (~(BYTES_PER_BLOCK - 1))); + end = (void*)((mp_uint_t)end & (~(BYTES_PER_BLOCK - 1))); DEBUG_printf("Initializing GC heap: %p..%p = " UINT_FMT " bytes\n", start, end, (byte*)end - (byte*)start); // calculate parameters for GC (T=total, A=alloc table, F=finaliser table, P=pool; all in bytes): @@ -119,7 +119,7 @@ void gc_init(void *start, void *end) { // F = A * BLOCKS_PER_ATB / BLOCKS_PER_FTB // P = A * BLOCKS_PER_ATB * BYTES_PER_BLOCK // => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK) - machine_uint_t total_byte_len = (byte*)end - (byte*)start; + mp_uint_t total_byte_len = (byte*)end - (byte*)start; #if MICROPY_ENABLE_FINALISER gc_alloc_table_byte_len = total_byte_len * BITS_PER_BYTE / (BITS_PER_BYTE + BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK); #else @@ -130,13 +130,13 @@ void gc_init(void *start, void *end) { gc_alloc_table_start = (byte*)start; #if MICROPY_ENABLE_FINALISER - machine_uint_t gc_finaliser_table_byte_len = (gc_alloc_table_byte_len * BLOCKS_PER_ATB) / BLOCKS_PER_FTB; + mp_uint_t gc_finaliser_table_byte_len = (gc_alloc_table_byte_len * BLOCKS_PER_ATB) / BLOCKS_PER_FTB; gc_finaliser_table_start = gc_alloc_table_start + gc_alloc_table_byte_len; #endif - machine_uint_t gc_pool_block_len = gc_alloc_table_byte_len * BLOCKS_PER_ATB; - gc_pool_start = (machine_uint_t*)((byte*)end - gc_pool_block_len * BYTES_PER_BLOCK); - gc_pool_end = (machine_uint_t*)end; + mp_uint_t gc_pool_block_len = gc_alloc_table_byte_len * BLOCKS_PER_ATB; + gc_pool_start = (mp_uint_t*)((byte*)end - gc_pool_block_len * BYTES_PER_BLOCK); + gc_pool_end = (mp_uint_t*)end; // clear ATBs memset(gc_alloc_table_start, 0, gc_alloc_table_byte_len); @@ -178,14 +178,14 @@ bool gc_is_locked(void) { #define VERIFY_PTR(ptr) ( \ (ptr & (BYTES_PER_BLOCK - 1)) == 0 /* must be aligned on a block */ \ - && ptr >= (machine_uint_t)gc_pool_start /* must be above start of pool */ \ - && ptr < (machine_uint_t)gc_pool_end /* must be below end of pool */ \ + && ptr >= (mp_uint_t)gc_pool_start /* must be above start of pool */ \ + && ptr < (mp_uint_t)gc_pool_end /* must be below end of pool */ \ ) #define VERIFY_MARK_AND_PUSH(ptr) \ do { \ if (VERIFY_PTR(ptr)) { \ - machine_uint_t _block = BLOCK_FROM_PTR(ptr); \ + mp_uint_t _block = BLOCK_FROM_PTR(ptr); \ if (ATB_GET_KIND(_block) == AT_HEAD) { \ /* an unmarked head, mark it, and push it on gc stack */ \ ATB_HEAD_TO_MARK(_block); \ @@ -201,18 +201,18 @@ bool gc_is_locked(void) { STATIC void gc_drain_stack(void) { while (gc_sp > gc_stack) { // pop the next block off the stack - machine_uint_t block = *--gc_sp; + mp_uint_t block = *--gc_sp; // work out number of consecutive blocks in the chain starting with this one - machine_uint_t n_blocks = 0; + mp_uint_t n_blocks = 0; do { n_blocks += 1; } while (ATB_GET_KIND(block + n_blocks) == AT_TAIL); // check this block's children - machine_uint_t *scan = (machine_uint_t*)PTR_FROM_BLOCK(block); - for (machine_uint_t i = n_blocks * WORDS_PER_BLOCK; i > 0; i--, scan++) { - machine_uint_t ptr2 = *scan; + mp_uint_t *scan = (mp_uint_t*)PTR_FROM_BLOCK(block); + for (mp_uint_t i = n_blocks * WORDS_PER_BLOCK; i > 0; i--, scan++) { + mp_uint_t ptr2 = *scan; VERIFY_MARK_AND_PUSH(ptr2); } } @@ -224,7 +224,7 @@ STATIC void gc_deal_with_stack_overflow(void) { gc_sp = gc_stack; // scan entire memory looking for blocks which have been marked but not their children - for (machine_uint_t block = 0; block < gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) { + for (mp_uint_t block = 0; block < gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) { // trace (again) if mark bit set if (ATB_GET_KIND(block) == AT_MARK) { *gc_sp++ = block; @@ -244,7 +244,7 @@ STATIC void gc_sweep(void) { #endif // free unmarked heads and their tails int free_tail = 0; - for (machine_uint_t block = 0; block < gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) { + for (mp_uint_t block = 0; block < gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) { switch (ATB_GET_KIND(block)) { case AT_HEAD: #if MICROPY_ENABLE_FINALISER @@ -290,9 +290,9 @@ void gc_collect_start(void) { gc_sp = gc_stack; } -void gc_collect_root(void **ptrs, machine_uint_t len) { - for (machine_uint_t i = 0; i < len; i++) { - machine_uint_t ptr = (machine_uint_t)ptrs[i]; +void gc_collect_root(void **ptrs, mp_uint_t len) { + for (mp_uint_t i = 0; i < len; i++) { + mp_uint_t ptr = (mp_uint_t)ptrs[i]; VERIFY_MARK_AND_PUSH(ptr); gc_drain_stack(); } @@ -305,14 +305,14 @@ void gc_collect_end(void) { } void gc_info(gc_info_t *info) { - info->total = (gc_pool_end - gc_pool_start) * sizeof(machine_uint_t); + info->total = (gc_pool_end - gc_pool_start) * sizeof(mp_uint_t); info->used = 0; info->free = 0; info->num_1block = 0; info->num_2block = 0; info->max_block = 0; - for (machine_uint_t block = 0, len = 0; block < gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) { - machine_uint_t kind = ATB_GET_KIND(block); + for (mp_uint_t block = 0, len = 0; block < gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) { + mp_uint_t kind = ATB_GET_KIND(block); if (kind == AT_FREE || kind == AT_HEAD) { if (len == 1) { info->num_1block += 1; @@ -349,8 +349,8 @@ void gc_info(gc_info_t *info) { info->free *= BYTES_PER_BLOCK; } -void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser) { - machine_uint_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK; +void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser) { + mp_uint_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK; DEBUG_printf("gc_alloc(" UINT_FMT " bytes -> " UINT_FMT " blocks)\n", n_bytes, n_blocks); // check if GC is locked @@ -363,10 +363,10 @@ void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser) { return NULL; } - machine_uint_t i; - machine_uint_t end_block; - machine_uint_t start_block; - machine_uint_t n_free = 0; + mp_uint_t i; + mp_uint_t end_block; + mp_uint_t start_block; + mp_uint_t n_free = 0; int collected = 0; for (;;) { @@ -399,7 +399,7 @@ void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser) { // mark rest of blocks as used tail // TODO for a run of many blocks can make this more efficient - for (machine_uint_t bl = start_block + 1; bl <= end_block; bl++) { + for (mp_uint_t bl = start_block + 1; bl <= end_block; bl++) { ATB_FREE_TO_TAIL(bl); } @@ -427,11 +427,11 @@ void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser) { } /* -void *gc_alloc(machine_uint_t n_bytes) { +void *gc_alloc(mp_uint_t n_bytes) { return _gc_alloc(n_bytes, false); } -void *gc_alloc_with_finaliser(machine_uint_t n_bytes) { +void *gc_alloc_with_finaliser(mp_uint_t n_bytes) { return _gc_alloc(n_bytes, true); } */ @@ -443,11 +443,11 @@ void gc_free(void *ptr_in) { return; } - machine_uint_t ptr = (machine_uint_t)ptr_in; + mp_uint_t ptr = (mp_uint_t)ptr_in; DEBUG_printf("gc_free(%p)\n", ptr); if (VERIFY_PTR(ptr)) { - machine_uint_t block = BLOCK_FROM_PTR(ptr); + mp_uint_t block = BLOCK_FROM_PTR(ptr); if (ATB_GET_KIND(block) == AT_HEAD) { // free head and all of its tail blocks do { @@ -458,14 +458,14 @@ void gc_free(void *ptr_in) { } } -machine_uint_t gc_nbytes(void *ptr_in) { - machine_uint_t ptr = (machine_uint_t)ptr_in; +mp_uint_t gc_nbytes(void *ptr_in) { + mp_uint_t ptr = (mp_uint_t)ptr_in; if (VERIFY_PTR(ptr)) { - machine_uint_t block = BLOCK_FROM_PTR(ptr); + mp_uint_t block = BLOCK_FROM_PTR(ptr); if (ATB_GET_KIND(block) == AT_HEAD) { // work out number of consecutive blocks in the chain starting with this on - machine_uint_t n_blocks = 0; + mp_uint_t n_blocks = 0; do { n_blocks += 1; } while (ATB_GET_KIND(block + n_blocks) == AT_TAIL); @@ -479,8 +479,8 @@ machine_uint_t gc_nbytes(void *ptr_in) { #if 0 // old, simple realloc that didn't expand memory in place -void *gc_realloc(void *ptr, machine_uint_t n_bytes) { - machine_uint_t n_existing = gc_nbytes(ptr); +void *gc_realloc(void *ptr, mp_uint_t n_bytes) { + mp_uint_t n_existing = gc_nbytes(ptr); if (n_bytes <= n_existing) { return ptr; } else { @@ -489,7 +489,7 @@ void *gc_realloc(void *ptr, machine_uint_t n_bytes) { has_finaliser = false; } else { #if MICROPY_ENABLE_FINALISER - has_finaliser = FTB_GET(BLOCK_FROM_PTR((machine_uint_t)ptr)); + has_finaliser = FTB_GET(BLOCK_FROM_PTR((mp_uint_t)ptr)); #else has_finaliser = false; #endif @@ -506,7 +506,7 @@ void *gc_realloc(void *ptr, machine_uint_t n_bytes) { #else // Alternative gc_realloc impl -void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) { +void *gc_realloc(void *ptr_in, mp_uint_t n_bytes) { if (gc_lock_depth > 0) { return NULL; } @@ -516,7 +516,7 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) { return gc_alloc(n_bytes, false); } - machine_uint_t ptr = (machine_uint_t)ptr_in; + mp_uint_t ptr = (mp_uint_t)ptr_in; // sanity check the ptr if (!VERIFY_PTR(ptr)) { @@ -524,7 +524,7 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) { } // get first block - machine_uint_t block = BLOCK_FROM_PTR(ptr); + mp_uint_t block = BLOCK_FROM_PTR(ptr); // sanity check the ptr is pointing to the head of a block if (ATB_GET_KIND(block) != AT_HEAD) { @@ -532,14 +532,14 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) { } // compute number of new blocks that are requested - machine_uint_t new_blocks = (n_bytes + BYTES_PER_BLOCK - 1) / BYTES_PER_BLOCK; + mp_uint_t new_blocks = (n_bytes + BYTES_PER_BLOCK - 1) / BYTES_PER_BLOCK; // get the number of consecutive tail blocks and // the number of free blocks after last tail block // stop if we reach (or are at) end of heap - machine_uint_t n_free = 0; - machine_uint_t n_blocks = 1; // counting HEAD block - machine_uint_t max_block = gc_alloc_table_byte_len * BLOCKS_PER_ATB; + mp_uint_t n_free = 0; + mp_uint_t n_blocks = 1; // counting HEAD block + mp_uint_t max_block = gc_alloc_table_byte_len * BLOCKS_PER_ATB; while (block + n_blocks + n_free < max_block) { if (n_blocks + n_free >= new_blocks) { // stop as soon as we find enough blocks for n_bytes @@ -562,7 +562,7 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) { // check if we can shrink the allocated area if (new_blocks < n_blocks) { // free unneeded tail blocks - for (machine_uint_t bl = block + new_blocks; ATB_GET_KIND(bl) == AT_TAIL; bl++) { + for (mp_uint_t bl = block + new_blocks; ATB_GET_KIND(bl) == AT_TAIL; bl++) { ATB_ANY_TO_FREE(bl); } return ptr_in; @@ -571,7 +571,7 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) { // check if we can expand in place if (new_blocks <= n_blocks + n_free) { // mark few more blocks as used tail - for (machine_uint_t bl = block + n_blocks; bl < block + new_blocks; bl++) { + for (mp_uint_t bl = block + n_blocks; bl < block + new_blocks; bl++) { assert(ATB_GET_KIND(bl) == AT_FREE); ATB_FREE_TO_TAIL(bl); } @@ -613,7 +613,7 @@ void gc_dump_info() { void gc_dump_alloc_table(void) { printf("GC memory layout; from %p:", gc_pool_start); - for (machine_uint_t bl = 0; bl < gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) { + for (mp_uint_t bl = 0; bl < gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) { if (bl % 64 == 0) { printf("\n%04x: ", (uint)bl); } @@ -623,12 +623,12 @@ void gc_dump_alloc_table(void) { case AT_HEAD: c = 'h'; break; /* this prints the uPy object type of the head block case AT_HEAD: { - machine_uint_t *ptr = gc_pool_start + bl * WORDS_PER_BLOCK; - if (*ptr == (machine_uint_t)&mp_type_tuple) { c = 'T'; } - else if (*ptr == (machine_uint_t)&mp_type_list) { c = 'L'; } - else if (*ptr == (machine_uint_t)&mp_type_dict) { c = 'D'; } - else if (*ptr == (machine_uint_t)&mp_type_float) { c = 'F'; } - else if (*ptr == (machine_uint_t)&mp_type_fun_bc) { c = 'B'; } + mp_uint_t *ptr = gc_pool_start + bl * WORDS_PER_BLOCK; + if (*ptr == (mp_uint_t)&mp_type_tuple) { c = 'T'; } + else if (*ptr == (mp_uint_t)&mp_type_list) { c = 'L'; } + else if (*ptr == (mp_uint_t)&mp_type_dict) { c = 'D'; } + else if (*ptr == (mp_uint_t)&mp_type_float) { c = 'F'; } + else if (*ptr == (mp_uint_t)&mp_type_fun_bc) { c = 'B'; } else { c = 'h'; } break; } @@ -643,23 +643,23 @@ void gc_dump_alloc_table(void) { #if DEBUG_PRINT void gc_test(void) { - machine_uint_t len = 500; - machine_uint_t *heap = malloc(len); - gc_init(heap, heap + len / sizeof(machine_uint_t)); + mp_uint_t len = 500; + mp_uint_t *heap = malloc(len); + gc_init(heap, heap + len / sizeof(mp_uint_t)); void *ptrs[100]; { - machine_uint_t **p = gc_alloc(16, false); + mp_uint_t **p = gc_alloc(16, false); p[0] = gc_alloc(64, false); p[1] = gc_alloc(1, false); p[2] = gc_alloc(1, false); p[3] = gc_alloc(1, false); - machine_uint_t ***p2 = gc_alloc(16, false); + mp_uint_t ***p2 = gc_alloc(16, false); p2[0] = p; p2[1] = p; ptrs[0] = p2; } for (int i = 0; i < 25; i+=2) { - machine_uint_t *p = gc_alloc(i, false); + mp_uint_t *p = gc_alloc(i, false); printf("p=%p\n", p); if (i & 3) { //ptrs[i] = p; diff --git a/py/gc.h b/py/gc.h index 3b3b7dbb50e8..fd48d26645e6 100644 --- a/py/gc.h +++ b/py/gc.h @@ -35,21 +35,21 @@ bool gc_is_locked(void); // A given port must implement gc_collect by using the other collect functions. void gc_collect(void); void gc_collect_start(void); -void gc_collect_root(void **ptrs, machine_uint_t len); +void gc_collect_root(void **ptrs, mp_uint_t len); void gc_collect_end(void); -void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser); +void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser); void gc_free(void *ptr); -machine_uint_t gc_nbytes(void *ptr); -void *gc_realloc(void *ptr, machine_uint_t n_bytes); +mp_uint_t gc_nbytes(void *ptr); +void *gc_realloc(void *ptr, mp_uint_t n_bytes); typedef struct _gc_info_t { - machine_uint_t total; - machine_uint_t used; - machine_uint_t free; - machine_uint_t num_1block; - machine_uint_t num_2block; - machine_uint_t max_block; + mp_uint_t total; + mp_uint_t used; + mp_uint_t free; + mp_uint_t num_1block; + mp_uint_t num_2block; + mp_uint_t max_block; } gc_info_t; void gc_info(gc_info_t *info); diff --git a/py/map.c b/py/map.c index dcc13c52cc63..82237381ccba 100644 --- a/py/map.c +++ b/py/map.c @@ -167,7 +167,7 @@ mp_map_elem_t* mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t } } - machine_uint_t hash = mp_obj_hash(index); + mp_uint_t hash = mp_obj_hash(index); uint pos = hash % map->alloc; uint start_pos = pos; mp_map_elem_t *avail_slot = NULL; @@ -270,7 +270,7 @@ mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t looku return NULL; } } - machine_uint_t hash = mp_obj_hash(index); + mp_uint_t hash = mp_obj_hash(index); uint pos = hash % set->alloc; uint start_pos = pos; mp_obj_t *avail_slot = NULL; diff --git a/py/misc.h b/py/misc.h index 2ac64a7b763f..c8ccdaa02e28 100644 --- a/py/misc.h +++ b/py/misc.h @@ -100,7 +100,7 @@ bool unichar_isupper(unichar c); bool unichar_islower(unichar c); unichar unichar_tolower(unichar c); unichar unichar_toupper(unichar c); -machine_uint_t unichar_charlen(const char *str, machine_uint_t len); +mp_uint_t unichar_charlen(const char *str, mp_uint_t len); #define UTF8_IS_NONASCII(ch) ((ch) & 0x80) #define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80) diff --git a/py/modgc.c b/py/modgc.c index 4ffdc2be687f..045563cd982e 100644 --- a/py/modgc.c +++ b/py/modgc.c @@ -42,7 +42,7 @@ extern uint gc_collected; STATIC mp_obj_t py_gc_collect(void) { gc_collect(); #if MICROPY_PY_GC_COLLECT_RETVAL - return MP_OBJ_NEW_SMALL_INT((machine_uint_t)gc_collected); + return MP_OBJ_NEW_SMALL_INT((mp_uint_t)gc_collected); #else return mp_const_none; #endif @@ -64,14 +64,14 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable); STATIC mp_obj_t gc_mem_free(void) { gc_info_t info; gc_info(&info); - return MP_OBJ_NEW_SMALL_INT((machine_uint_t)info.free); + return MP_OBJ_NEW_SMALL_INT((mp_uint_t)info.free); } MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free); STATIC mp_obj_t gc_mem_alloc(void) { gc_info_t info; gc_info(&info); - return MP_OBJ_NEW_SMALL_INT((machine_uint_t)info.used); + return MP_OBJ_NEW_SMALL_INT((mp_uint_t)info.used); } MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc); diff --git a/py/modmath.c b/py/modmath.c index 0d0d13b4e2e1..4db9b805477d 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -48,7 +48,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); #define MATH_FUN_1_TO_INT(py_name, c_name) \ - mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_int((machine_int_t)MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \ + mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_int((mp_int_t)MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); // These are also used by cmath.c diff --git a/py/modmicropython.c b/py/modmicropython.c index bbb315189b14..0d559c42a292 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -35,15 +35,15 @@ #if MICROPY_MEM_STATS STATIC mp_obj_t mp_micropython_mem_total() { - return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_total_bytes_allocated()); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_total_bytes_allocated()); } STATIC mp_obj_t mp_micropython_mem_current() { - return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_current_bytes_allocated()); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_current_bytes_allocated()); } STATIC mp_obj_t mp_micropython_mem_peak() { - return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_peak_bytes_allocated()); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_peak_bytes_allocated()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total); diff --git a/py/modstruct.c b/py/modstruct.c index 2e40264e8df5..61da283da508 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -74,13 +74,13 @@ STATIC char get_fmt_type(const char **fmt) { return t; } -STATIC machine_uint_t get_fmt_num(const char **p) { +STATIC mp_uint_t get_fmt_num(const char **p) { const char *num = *p; uint len = 1; while (unichar_isdigit(*++num)) { len++; } - machine_uint_t val = (machine_uint_t)MP_OBJ_SMALL_INT_VALUE(mp_parse_num_integer(*p, len, 10)); + mp_uint_t val = (mp_uint_t)MP_OBJ_SMALL_INT_VALUE(mp_parse_num_integer(*p, len, 10)); *p = num; return val; } @@ -99,10 +99,10 @@ STATIC uint calcsize_items(const char *fmt) { STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { const char *fmt = mp_obj_str_get_str(fmt_in); char fmt_type = get_fmt_type(&fmt); - machine_uint_t size; + mp_uint_t size; for (size = 0; *fmt; fmt++) { uint align = 1; - machine_uint_t cnt = 1; + mp_uint_t cnt = 1; if (unichar_isdigit(*fmt)) { cnt = get_fmt_num(&fmt); } @@ -111,14 +111,14 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { assert(*fmt == 's'); } - machine_uint_t sz; + mp_uint_t sz; if (*fmt == 's') { sz = cnt; } else { - sz = (machine_uint_t)mp_binary_get_size(fmt_type, *fmt, &align); + sz = (mp_uint_t)mp_binary_get_size(fmt_type, *fmt, &align); } // TODO - assert(sz != (machine_uint_t)-1); + assert(sz != (mp_uint_t)-1); // Apply alignment size = (size + align - 1) & ~(align - 1); size += sz; @@ -138,7 +138,7 @@ STATIC mp_obj_t struct_unpack(mp_obj_t fmt_in, mp_obj_t data_in) { byte *p = bufinfo.buf; for (uint i = 0; i < size; i++) { - machine_uint_t sz = 1; + mp_uint_t sz = 1; if (unichar_isdigit(*fmt)) { sz = get_fmt_num(&fmt); } @@ -170,7 +170,7 @@ STATIC mp_obj_t struct_pack(uint n_args, mp_obj_t *args) { memset(p, 0, size); for (uint i = 1; i < n_args; i++) { - machine_uint_t sz = 1; + mp_uint_t sz = 1; if (unichar_isdigit(*fmt)) { sz = get_fmt_num(&fmt); } @@ -182,7 +182,7 @@ STATIC mp_obj_t struct_pack(uint n_args, mp_obj_t *args) { if (*fmt == 's') { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[i], &bufinfo, MP_BUFFER_READ); - machine_uint_t to_copy = sz; + mp_uint_t to_copy = sz; if (bufinfo.len < to_copy) { to_copy = bufinfo.len; } diff --git a/py/mpconfig.h b/py/mpconfig.h index 3a9d342ea3e1..da9cffc56ad4 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -375,8 +375,8 @@ typedef double mp_float_t; #define BITS_PER_BYTE (8) #define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD) -// machine_int_t value with most significant bit set -#define WORD_MSBIT_HIGH (((machine_uint_t)1) << (BYTES_PER_WORD * 8 - 1)) +// mp_int_t value with most significant bit set +#define WORD_MSBIT_HIGH (((mp_uint_t)1) << (BYTES_PER_WORD * 8 - 1)) #if !defined(MP_ENDIANNESS_LITTLE) && !defined(MP_ENDIANNESS_BIG) // Just because most archs are such? @@ -387,14 +387,14 @@ typedef double mp_float_t; #define MP_ENDIANNESS_LITTLE (0) #endif -// printf format spec to use for machine_int_t and friends +// printf format spec to use for mp_int_t and friends #ifndef INT_FMT #ifdef __LP64__ -// Archs where machine_int_t == long, long != int +// Archs where mp_int_t == long, long != int #define UINT_FMT "%lu" #define INT_FMT "%ld" #else -// Archs where machine_int_t == int +// Archs where mp_int_t == int #define UINT_FMT "%u" #define INT_FMT "%d" #endif diff --git a/py/mpz.c b/py/mpz.c index 3f1e859fc6ba..3b96c574f398 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -351,7 +351,7 @@ STATIC uint mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, uint jlen, mpz_dig_t *kdig modifies den_dig memory, but restors it to original state at end */ -STATIC void mpn_div(mpz_dig_t *num_dig, machine_uint_t *num_len, mpz_dig_t *den_dig, machine_uint_t den_len, mpz_dig_t *quo_dig, machine_uint_t *quo_len) { +STATIC void mpn_div(mpz_dig_t *num_dig, mp_uint_t *num_len, mpz_dig_t *den_dig, mp_uint_t den_len, mpz_dig_t *quo_dig, mp_uint_t *quo_len) { mpz_dig_t *orig_num_dig = num_dig; mpz_dig_t *orig_quo_dig = quo_dig; mpz_dig_t norm_shift = 0; @@ -502,12 +502,12 @@ void mpz_init_zero(mpz_t *z) { z->dig = NULL; } -void mpz_init_from_int(mpz_t *z, machine_int_t val) { +void mpz_init_from_int(mpz_t *z, mp_int_t val) { mpz_init_zero(z); mpz_set_from_int(z, val); } -void mpz_init_fixed_from_int(mpz_t *z, mpz_dig_t *dig, uint alloc, machine_int_t val) { +void mpz_init_fixed_from_int(mpz_t *z, mpz_dig_t *dig, uint alloc, mp_int_t val) { z->neg = 0; z->fixed_dig = 1; z->alloc = alloc; @@ -528,7 +528,7 @@ mpz_t *mpz_zero(void) { return z; } -mpz_t *mpz_from_int(machine_int_t val) { +mpz_t *mpz_from_int(mp_int_t val) { mpz_t *z = mpz_zero(); mpz_set_from_int(z, val); return z; @@ -594,10 +594,10 @@ void mpz_set(mpz_t *dest, const mpz_t *src) { memcpy(dest->dig, src->dig, src->len * sizeof(mpz_dig_t)); } -void mpz_set_from_int(mpz_t *z, machine_int_t val) { +void mpz_set_from_int(mpz_t *z, mp_int_t val) { mpz_need_dig(z, MPZ_NUM_DIG_FOR_INT); - machine_uint_t uval; + mp_uint_t uval; if (val < 0) { z->neg = 1; uval = -val; @@ -704,7 +704,7 @@ int mpz_cmp(const mpz_t *z1, const mpz_t *z2) { #if 0 // obsolete // compares mpz with an integer that fits within DIG_SIZE bits -int mpz_cmp_sml_int(const mpz_t *z, machine_int_t sml_int) { +int mpz_cmp_sml_int(const mpz_t *z, mp_int_t sml_int) { int cmp; if (z->neg == 0) { if (sml_int < 0) return 1; @@ -830,7 +830,7 @@ void mpz_not_inpl(mpz_t *dest, const mpz_t *z) { /* computes dest = lhs << rhs can have dest, lhs the same */ -void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, machine_int_t rhs) { +void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs) { if (lhs->len == 0 || rhs == 0) { mpz_set(dest, lhs); } else if (rhs < 0) { @@ -845,7 +845,7 @@ void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, machine_int_t rhs) { /* computes dest = lhs >> rhs can have dest, lhs the same */ -void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, machine_int_t rhs) { +void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs) { if (lhs->len == 0 || rhs == 0) { mpz_set(dest, lhs); } else if (rhs < 0) { @@ -1214,12 +1214,12 @@ mpz_t *mpz_mod(const mpz_t *lhs, const mpz_t *rhs) { #endif // TODO check that this correctly handles overflow in all cases -machine_int_t mpz_as_int(const mpz_t *i) { - machine_int_t val = 0; +mp_int_t mpz_as_int(const mpz_t *i) { + mp_int_t val = 0; mpz_dig_t *d = i->dig + i->len; while (--d >= i->dig) { - machine_int_t oldval = val; + mp_int_t oldval = val; val = (val << DIG_SIZE) | *d; if (val < oldval) { // overflow, return +/- "infinity" @@ -1241,12 +1241,12 @@ machine_int_t mpz_as_int(const mpz_t *i) { } // TODO check that this correctly handles overflow in all cases -bool mpz_as_int_checked(const mpz_t *i, machine_int_t *value) { - machine_int_t val = 0; +bool mpz_as_int_checked(const mpz_t *i, mp_int_t *value) { + mp_int_t val = 0; mpz_dig_t *d = i->dig + i->len; while (--d >= i->dig) { - machine_int_t oldval = val; + mp_int_t oldval = val; val = (val << DIG_SIZE) | *d; if (val < oldval) { // overflow diff --git a/py/mpz.h b/py/mpz.h index 0f962cc024a1..76c308285e23 100644 --- a/py/mpz.h +++ b/py/mpz.h @@ -29,27 +29,27 @@ typedef uint32_t mpz_dbl_dig_t; typedef int32_t mpz_dbl_dig_signed_t; typedef struct _mpz_t { - machine_uint_t neg : 1; - machine_uint_t fixed_dig : 1; - machine_uint_t alloc : 30; - machine_uint_t len; + mp_uint_t neg : 1; + mp_uint_t fixed_dig : 1; + mp_uint_t alloc : 30; + mp_uint_t len; mpz_dig_t *dig; } mpz_t; #define MPZ_DIG_SIZE (15) // see mpn_div for why this needs to be at most 15 -#define MPZ_NUM_DIG_FOR_INT (sizeof(machine_int_t) * 8 / MPZ_DIG_SIZE + 1) +#define MPZ_NUM_DIG_FOR_INT (sizeof(mp_int_t) * 8 / MPZ_DIG_SIZE + 1) #define MPZ_NUM_DIG_FOR_LL (sizeof(long long) * 8 / MPZ_DIG_SIZE + 1) // convenience macro to declare an mpz with a digit array from the stack, initialised by an integer #define MPZ_CONST_INT(z, val) mpz_t z; mpz_dig_t z ## _digits[MPZ_NUM_DIG_FOR_INT]; mpz_init_fixed_from_int(&z, z_digits, MPZ_NUM_DIG_FOR_INT, val); void mpz_init_zero(mpz_t *z); -void mpz_init_from_int(mpz_t *z, machine_int_t val); -void mpz_init_fixed_from_int(mpz_t *z, mpz_dig_t *dig, uint dig_alloc, machine_int_t val); +void mpz_init_from_int(mpz_t *z, mp_int_t val); +void mpz_init_fixed_from_int(mpz_t *z, mpz_dig_t *dig, uint dig_alloc, mp_int_t val); void mpz_deinit(mpz_t *z); mpz_t *mpz_zero(); -mpz_t *mpz_from_int(machine_int_t i); +mpz_t *mpz_from_int(mp_int_t i); mpz_t *mpz_from_ll(long long i); mpz_t *mpz_from_str(const char *str, uint len, bool neg, uint base); void mpz_free(mpz_t *z); @@ -57,7 +57,7 @@ void mpz_free(mpz_t *z); mpz_t *mpz_clone(const mpz_t *src); void mpz_set(mpz_t *dest, const mpz_t *src); -void mpz_set_from_int(mpz_t *z, machine_int_t src); +void mpz_set_from_int(mpz_t *z, mp_int_t src); void mpz_set_from_ll(mpz_t *z, long long i); uint mpz_set_from_str(mpz_t *z, const char *str, uint len, bool neg, uint base); @@ -79,8 +79,8 @@ mpz_t *mpz_pow(const mpz_t *lhs, const mpz_t *rhs); void mpz_abs_inpl(mpz_t *dest, const mpz_t *z); void mpz_neg_inpl(mpz_t *dest, const mpz_t *z); void mpz_not_inpl(mpz_t *dest, const mpz_t *z); -void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, machine_int_t rhs); -void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, machine_int_t rhs); +void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs); +void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs); void mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); @@ -96,8 +96,8 @@ void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const m mpz_t *mpz_div(const mpz_t *lhs, const mpz_t *rhs); mpz_t *mpz_mod(const mpz_t *lhs, const mpz_t *rhs); -machine_int_t mpz_as_int(const mpz_t *z); -bool mpz_as_int_checked(const mpz_t *z, machine_int_t *value); +mp_int_t mpz_as_int(const mpz_t *z); +bool mpz_as_int_checked(const mpz_t *z, mp_int_t *value); #if MICROPY_PY_BUILTINS_FLOAT mp_float_t mpz_as_float(const mpz_t *z); #endif diff --git a/py/obj.c b/py/obj.c index 3077fd293746..cfebbf34661c 100644 --- a/py/obj.c +++ b/py/obj.c @@ -83,7 +83,7 @@ void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) { // helper function to print an exception with traceback void mp_obj_print_exception(mp_obj_t exc) { if (mp_obj_is_exception_instance(exc)) { - machine_uint_t n, *values; + mp_uint_t n, *values; mp_obj_exception_get_traceback(exc, &n, &values); if (n > 0) { assert(n % 3 == 0); @@ -145,7 +145,7 @@ bool mp_obj_is_callable(mp_obj_t o_in) { return mp_obj_get_type(o_in)->call != NULL; } -machine_int_t mp_obj_hash(mp_obj_t o_in) { +mp_int_t mp_obj_hash(mp_obj_t o_in) { if (o_in == mp_const_false) { return 0; // needs to hash to same as the integer 0, since False==0 } else if (o_in == mp_const_true) { @@ -155,13 +155,13 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) { } else if (MP_OBJ_IS_STR(o_in) || MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) { return mp_obj_str_get_hash(o_in); } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_NoneType)) { - return (machine_int_t)o_in; + return (mp_int_t)o_in; } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_fun_native) || MP_OBJ_IS_TYPE(o_in, &mp_type_fun_bc)) { - return (machine_int_t)o_in; + return (mp_int_t)o_in; } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_tuple)) { return mp_obj_tuple_hash(o_in); } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_type)) { - return (machine_int_t)o_in; + return (mp_int_t)o_in; // TODO hash class and instances // TODO delegate to __hash__ method if it exists @@ -225,7 +225,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { return false; } -machine_int_t mp_obj_get_int(mp_const_obj_t arg) { +mp_int_t mp_obj_get_int(mp_const_obj_t arg) { // This function essentially performs implicit type conversion to int // Note that Python does NOT provide implicit type conversion from // float to int in the core expression language, try some_list[1.0]. @@ -244,8 +244,8 @@ machine_int_t mp_obj_get_int(mp_const_obj_t arg) { // returns false if arg is not of integral type // returns true and sets *value if it is of integral type -// can throw OverflowError if arg is of integral type, but doesn't fit in a machine_int_t -bool mp_obj_get_int_maybe(mp_const_obj_t arg, machine_int_t *value) { +// can throw OverflowError if arg is of integral type, but doesn't fit in a mp_int_t +bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value) { if (arg == mp_const_false) { *value = 0; } else if (arg == mp_const_true) { @@ -330,8 +330,8 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) { } // is_slice determines whether the index is a slice index -uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice) { - machine_int_t i; +uint mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index, bool is_slice) { + mp_int_t i; if (MP_OBJ_IS_SMALL_INT(index)) { i = MP_OBJ_SMALL_INT_VALUE(index); } else if (!mp_obj_get_int_maybe(index, &i)) { @@ -363,7 +363,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) { MP_OBJ_IS_STR(o_in) || #endif MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) { - return MP_OBJ_NEW_SMALL_INT((machine_int_t)mp_obj_str_get_len(o_in)); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)mp_obj_str_get_len(o_in)); } else { mp_obj_type_t *type = mp_obj_get_type(o_in); if (type->unary_op != NULL) { diff --git a/py/obj.h b/py/obj.h index 1f5a83f919cd..d0284e6d2182 100644 --- a/py/obj.h +++ b/py/obj.h @@ -35,11 +35,6 @@ typedef machine_ptr_t mp_obj_t; typedef machine_const_ptr_t mp_const_obj_t; -// Integers that fit in a pointer have this type -// (do we need to expose this in the public API?) - -typedef machine_int_t mp_small_int_t; - // Anything that wants to be a Micro Python object must have // mp_obj_base_t as its first member (except small ints and qstrs) @@ -73,18 +68,18 @@ typedef struct _mp_obj_base_t mp_obj_base_t; // These macros check for small int, qstr or object, and access small int and qstr values // these macros have now become inline functions; see below -//#define MP_OBJ_IS_SMALL_INT(o) ((((mp_small_int_t)(o)) & 1) != 0) -//#define MP_OBJ_IS_QSTR(o) ((((mp_small_int_t)(o)) & 3) == 2) -//#define MP_OBJ_IS_OBJ(o) ((((mp_small_int_t)(o)) & 3) == 0) +//#define MP_OBJ_IS_SMALL_INT(o) ((((mp_int_t)(o)) & 1) != 0) +//#define MP_OBJ_IS_QSTR(o) ((((mp_int_t)(o)) & 3) == 2) +//#define MP_OBJ_IS_OBJ(o) ((((mp_int_t)(o)) & 3) == 0) #define MP_OBJ_IS_TYPE(o, t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))) // this does not work for checking a string, use below macro for that #define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int)) #define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str)) -#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_small_int_t)(o)) >> 1) +#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1) #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((small_int) << 1) | 1)) -#define MP_OBJ_QSTR_VALUE(o) (((mp_small_int_t)(o)) >> 2) -#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((machine_uint_t)qstr) << 2) | 2)) +#define MP_OBJ_QSTR_VALUE(o) (((mp_int_t)(o)) >> 2) +#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((mp_uint_t)qstr) << 2) | 2)) // These macros are used to declare and define constant function objects // You can put "static" in front of the definitions to make them local @@ -137,10 +132,10 @@ typedef struct _mp_map_elem_t { // would also need a trucated dict structure typedef struct _mp_map_t { - machine_uint_t all_keys_are_qstrs : 1; - machine_uint_t table_is_fixed_array : 1; - machine_uint_t used : (8 * sizeof(machine_uint_t) - 2); - machine_uint_t alloc; + mp_uint_t all_keys_are_qstrs : 1; + mp_uint_t table_is_fixed_array : 1; + mp_uint_t used : (8 * sizeof(mp_uint_t) - 2); + mp_uint_t alloc; mp_map_elem_t *table; } mp_map_t; @@ -151,7 +146,7 @@ typedef enum _mp_map_lookup_kind_t { MP_MAP_LOOKUP_REMOVE_IF_FOUND, // 2 } mp_map_lookup_kind_t; -static inline bool MP_MAP_SLOT_IS_FILLED(const mp_map_t *map, machine_uint_t pos) { return ((map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL); } +static inline bool MP_MAP_SLOT_IS_FILLED(const mp_map_t *map, mp_uint_t pos) { return ((map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL); } void mp_map_init(mp_map_t *map, int n); void mp_map_init_fixed_table(mp_map_t *map, int n, const mp_obj_t *table); @@ -165,12 +160,12 @@ void mp_map_dump(mp_map_t *map); // Underlying set implementation (not set object) typedef struct _mp_set_t { - machine_uint_t alloc; - machine_uint_t used; + mp_uint_t alloc; + mp_uint_t used; mp_obj_t *table; } mp_set_t; -static inline bool MP_SET_SLOT_IS_FILLED(const mp_set_t *set, machine_uint_t pos) { return ((set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL); } +static inline bool MP_SET_SLOT_IS_FILLED(const mp_set_t *set, mp_uint_t pos) { return ((set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL); } void mp_set_init(mp_set_t *set, int n); mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind); @@ -216,7 +211,7 @@ typedef struct _mp_buffer_info_t { //int ver; // ? void *buf; - machine_int_t len; // in bytes + mp_int_t len; // in bytes int typecode; // as per binary.h // Rationale: to load arbitrary-sized sprites directly to LCD @@ -227,7 +222,7 @@ typedef struct _mp_buffer_info_t { #define MP_BUFFER_WRITE (2) #define MP_BUFFER_RW (MP_BUFFER_READ | MP_BUFFER_WRITE) typedef struct _mp_buffer_p_t { - machine_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags); + mp_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags); } mp_buffer_p_t; bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags); void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags); @@ -236,8 +231,8 @@ void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags); typedef struct _mp_stream_p_t { // On error, functions should return -1 and fill in *errcode (values are // implementation-dependent, but will be exposed to user, e.g. via exception). - machine_int_t (*read)(mp_obj_t obj, void *buf, machine_uint_t size, int *errcode); - machine_int_t (*write)(mp_obj_t obj, const void *buf, machine_uint_t size, int *errcode); + mp_int_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode); + mp_int_t (*write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode); // add seek() ? int is_bytes : 1; } mp_stream_p_t; @@ -365,8 +360,8 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict); mp_obj_t mp_obj_new_none(void); mp_obj_t mp_obj_new_bool(bool value); mp_obj_t mp_obj_new_cell(mp_obj_t obj); -mp_obj_t mp_obj_new_int(machine_int_t value); -mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value); +mp_obj_t mp_obj_new_int(mp_int_t value); +mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value); mp_obj_t mp_obj_new_int_from_str_len(const char **str, uint len, bool neg, uint base); mp_obj_t mp_obj_new_int_from_ll(long long val); // this must return a multi-precision integer object (or raise an overflow exception) mp_obj_t mp_obj_new_str(const char* data, uint len, bool make_qstr_if_not_already); @@ -406,20 +401,20 @@ void mp_obj_print_exception(mp_obj_t exc); int mp_obj_is_true(mp_obj_t arg); // TODO make these all lower case when they have proven themselves -static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o) { return ((((mp_small_int_t)(o)) & 3) == 0); } -static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o) { return ((((mp_small_int_t)(o)) & 1) != 0); } +static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o) { return ((((mp_int_t)(o)) & 3) == 0); } +static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o) { return ((((mp_int_t)(o)) & 1) != 0); } //static inline bool MP_OBJ_IS_TYPE(mp_const_obj_t o, const mp_obj_type_t *t) { return (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))); } // this does not work for checking a string, use below macro for that //static inline bool MP_OBJ_IS_INT(mp_const_obj_t o) { return (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int)); } // returns true if o is a small int or long int static inline bool mp_obj_is_integer(mp_const_obj_t o) { return MP_OBJ_IS_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_bool); } // returns true if o is bool, small int or long int -static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o) { return ((((mp_small_int_t)(o)) & 3) == 2); } +static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o) { return ((((mp_int_t)(o)) & 3) == 2); } //static inline bool MP_OBJ_IS_STR(mp_const_obj_t o) { return (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str)); } bool mp_obj_is_callable(mp_obj_t o_in); -machine_int_t mp_obj_hash(mp_obj_t o_in); +mp_int_t mp_obj_hash(mp_obj_t o_in); bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2); -machine_int_t mp_obj_get_int(mp_const_obj_t arg); -bool mp_obj_get_int_maybe(mp_const_obj_t arg, machine_int_t *value); +mp_int_t mp_obj_get_int(mp_const_obj_t arg); +bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value); #if MICROPY_PY_BUILTINS_FLOAT mp_float_t mp_obj_get_float(mp_obj_t self_in); void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag); @@ -427,26 +422,26 @@ void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag); //qstr mp_obj_get_qstr(mp_obj_t arg); void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items); void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items); -uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice); +uint mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index, bool is_slice); mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return MP_OBJ_NULL */ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val); // bool // TODO make lower case when it has proven itself -static inline mp_obj_t MP_BOOL(machine_int_t x) { return x ? mp_const_true : mp_const_false; } +static inline mp_obj_t MP_BOOL(mp_int_t x) { return x ? mp_const_true : mp_const_false; } // cell mp_obj_t mp_obj_cell_get(mp_obj_t self_in); void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj); // int -// For long int, returns value truncated to machine_int_t -machine_int_t mp_obj_int_get(mp_const_obj_t self_in); +// For long int, returns value truncated to mp_int_t +mp_int_t mp_obj_int_get(mp_const_obj_t self_in); #if MICROPY_PY_BUILTINS_FLOAT mp_float_t mp_obj_int_as_float(mp_obj_t self_in); #endif -// Will raise exception if value doesn't fit into machine_int_t -machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in); +// Will raise exception if value doesn't fit into mp_int_t +mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in); // exception #define mp_obj_is_native_exception_instance(o) (mp_obj_get_type(o)->make_new == mp_obj_exception_make_new) @@ -454,8 +449,8 @@ bool mp_obj_is_exception_type(mp_obj_t self_in); bool mp_obj_is_exception_instance(mp_obj_t self_in); bool mp_obj_exception_match(mp_obj_t exc, const mp_obj_type_t *exc_type); void mp_obj_exception_clear_traceback(mp_obj_t self_in); -void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, machine_uint_t line, qstr block); -void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine_uint_t **values); +void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, mp_uint_t line, qstr block); +void mp_obj_exception_get_traceback(mp_obj_t self_in, mp_uint_t *n, mp_uint_t **values); mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in); mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args); @@ -488,7 +483,7 @@ mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_im // tuple void mp_obj_tuple_get(mp_obj_t self_in, uint *len, mp_obj_t **items); void mp_obj_tuple_del(mp_obj_t self_in); -machine_int_t mp_obj_tuple_hash(mp_obj_t self_in); +mp_int_t mp_obj_tuple_hash(mp_obj_t self_in); // list struct _mp_obj_list_t; @@ -562,14 +557,14 @@ const mp_obj_t *mp_obj_property_get(mp_obj_t self_in); // slice indexes resolved to particular sequence typedef struct { - machine_uint_t start; - machine_uint_t stop; - machine_int_t step; + mp_uint_t start; + mp_uint_t stop; + mp_int_t step; } mp_bound_slice_t; void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void *dest); #if MICROPY_PY_BUILTINS_SLICE -bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes); +bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes); #endif #define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t)) #define mp_seq_cat(dest, src1, len1, src2, len2, item_t) { memcpy(dest, src1, (len1) * sizeof(item_t)); memcpy(dest + (len1), src2, (len2) * sizeof(item_t)); } diff --git a/py/objarray.c b/py/objarray.c index b13df2bdba69..ca907fd01d6e 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -41,11 +41,11 @@ typedef struct _mp_obj_array_t { mp_obj_base_t base; - machine_uint_t typecode : 8; + mp_uint_t typecode : 8; // free is number of unused elements after len used elements // alloc size = len + free - machine_uint_t free : (8 * sizeof(machine_uint_t) - 8); - machine_uint_t len; // in elements + mp_uint_t free : (8 * sizeof(mp_uint_t) - 8); + mp_uint_t len; // in elements void *items; } mp_obj_array_t; @@ -206,7 +206,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value } } -STATIC machine_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, int flags) { +STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, int flags) { mp_obj_array_t *o = o_in; bufinfo->buf = o->items; bufinfo->len = o->len * mp_binary_get_size('@', o->typecode, NULL); @@ -285,7 +285,7 @@ mp_obj_t mp_obj_new_bytearray_by_ref(uint n, void *items) { typedef struct _mp_obj_array_it_t { mp_obj_base_t base; mp_obj_array_t *array; - machine_uint_t cur; + mp_uint_t cur; } mp_obj_array_it_t; STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) { diff --git a/py/objbool.c b/py/objbool.c index 4fe7a193410a..9bf30d423673 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -61,7 +61,7 @@ STATIC mp_obj_t bool_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp } STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) { - machine_int_t value = ((mp_obj_bool_t*)o_in)->value; + mp_int_t value = ((mp_obj_bool_t*)o_in)->value; switch (op) { case MP_UNARY_OP_BOOL: return o_in; case MP_UNARY_OP_POSITIVE: return MP_OBJ_NEW_SMALL_INT(value); @@ -74,7 +74,7 @@ STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) { STATIC mp_obj_t bool_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (MP_BINARY_OP_OR <= op && op <= MP_BINARY_OP_NOT_EQUAL) { - return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT((machine_int_t)mp_obj_is_true(lhs_in)), rhs_in); + return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT((mp_int_t)mp_obj_is_true(lhs_in)), rhs_in); } return MP_OBJ_NULL; // op not supported } diff --git a/py/objclosure.c b/py/objclosure.c index 2d7961baf136..900d63b4c7d5 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -37,7 +37,7 @@ typedef struct _mp_obj_closure_t { mp_obj_base_t base; mp_obj_t fun; - machine_uint_t n_closed; + mp_uint_t n_closed; mp_obj_t closed[]; } mp_obj_closure_t; diff --git a/py/objdict.c b/py/objdict.c index 696aad80f5ca..9b4133f83baa 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -75,7 +75,7 @@ STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) { mp_obj_dict_t *self = self_in; switch (op) { case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0); - case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->map.used); + case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->map.used); default: return MP_OBJ_NULL; // op not supported } } @@ -94,10 +94,10 @@ STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { return mp_const_false; } - machine_uint_t size = o->map.alloc; + mp_uint_t size = o->map.alloc; mp_map_t *map = &o->map; - for (machine_uint_t i = 0; i < size; i++) { + for (mp_uint_t i = 0; i < size; i++) { if (MP_MAP_SLOT_IS_FILLED(map, i)) { mp_map_elem_t *elem = mp_map_lookup(&rhs->map, map->table[i].key, MP_MAP_LOOKUP); if (elem == NULL || !mp_obj_equal(map->table[i].value, elem->value)) { @@ -155,12 +155,12 @@ STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { typedef struct _mp_obj_dict_it_t { mp_obj_base_t base; mp_obj_dict_t *dict; - machine_uint_t cur; + mp_uint_t cur; } mp_obj_dict_it_t; STATIC mp_map_elem_t *dict_it_iternext_elem(mp_obj_t self_in) { mp_obj_dict_it_t *self = self_in; - machine_uint_t max = self->dict->map.alloc; + mp_uint_t max = self->dict->map.alloc; mp_map_t *map = &self->dict->map; for (int i = self->cur; i < max; i++) { @@ -374,7 +374,7 @@ STATIC mp_obj_t dict_update(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) } // update the dict with any keyword args - for (machine_uint_t i = 0; i < kwargs->alloc; i++) { + for (mp_uint_t i = 0; i < kwargs->alloc; i++) { if (MP_MAP_SLOT_IS_FILLED(kwargs, i)) { mp_map_lookup(&self->map, kwargs->table[i].key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = kwargs->table[i].value; } @@ -403,7 +403,7 @@ typedef struct _mp_obj_dict_view_it_t { mp_obj_base_t base; mp_dict_view_kind_t kind; mp_obj_dict_it_t *iter; - machine_uint_t cur; + mp_uint_t cur; } mp_obj_dict_view_it_t; typedef struct _mp_obj_dict_view_t { diff --git a/py/objenumerate.c b/py/objenumerate.c index 37414464de2d..1272ba7cb489 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_enumerate_t { mp_obj_base_t base; mp_obj_t iter; - machine_int_t cur; + mp_int_t cur; } mp_obj_enumerate_t; STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in); diff --git a/py/objexcept.c b/py/objexcept.c index ad66bb50febf..68992bdaed12 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -335,7 +335,7 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in) { self->traceback = MP_OBJ_NULL; } -void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, machine_uint_t line, qstr block) { +void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, mp_uint_t line, qstr block) { #if MICROPY_ENABLE_GC if (gc_is_locked()) { // We can't allocate memory, so don't bother to try @@ -349,12 +349,12 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, machine_uint_t if (self->traceback == MP_OBJ_NULL) { self->traceback = mp_obj_new_list(0, NULL); } - mp_obj_list_append(self->traceback, (mp_obj_t)(machine_uint_t)file); - mp_obj_list_append(self->traceback, (mp_obj_t)(machine_uint_t)line); - mp_obj_list_append(self->traceback, (mp_obj_t)(machine_uint_t)block); + mp_obj_list_append(self->traceback, (mp_obj_t)(mp_uint_t)file); + mp_obj_list_append(self->traceback, (mp_obj_t)(mp_uint_t)line); + mp_obj_list_append(self->traceback, (mp_obj_t)(mp_uint_t)block); } -void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine_uint_t **values) { +void mp_obj_exception_get_traceback(mp_obj_t self_in, mp_uint_t *n, mp_uint_t **values) { GET_NATIVE_EXCEPTION(self, self_in); if (self->traceback == MP_OBJ_NULL) { diff --git a/py/objfun.c b/py/objfun.c index 74e959f9d38a..409525c670a1 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -197,7 +197,7 @@ STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, uint expected, ui // With this macro you can tune the maximum number of function state bytes // that will be allocated on the stack. Any function that needs more // than this will use the heap. -#define VM_MAX_STATE_ON_STACK (10 * sizeof(machine_uint_t)) +#define VM_MAX_STATE_ON_STACK (10 * sizeof(mp_uint_t)) // Set this to enable a simple stack overflow check. #define VM_DETECT_STACK_OVERFLOW (0) @@ -208,7 +208,7 @@ void mp_setup_code_state(mp_code_state *code_state, mp_obj_t self_in, uint n_arg // This function is pretty complicated. It's main aim is to be efficient in speed and RAM // usage for the common case of positional only args. mp_obj_fun_bc_t *self = self_in; - machine_uint_t n_state = code_state->n_state; + mp_uint_t n_state = code_state->n_state; const byte *ip = code_state->ip; code_state->code_info = self->bytecode; @@ -369,12 +369,12 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_o const byte *ip = self->bytecode; // get code info size, and skip line number table - machine_uint_t code_info_size = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24); + mp_uint_t code_info_size = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24); ip += code_info_size; // bytecode prelude: state size and exception stack size; 16 bit uints - machine_uint_t n_state = ip[0] | (ip[1] << 8); - machine_uint_t n_exc_stack = ip[2] | (ip[3] << 8); + mp_uint_t n_state = ip[0] | (ip[1] << 8); + mp_uint_t n_exc_stack = ip[2] | (ip[3] << 8); ip += 4; #if VM_DETECT_STACK_OVERFLOW @@ -509,13 +509,13 @@ typedef struct _mp_obj_fun_asm_t { void *fun; } mp_obj_fun_asm_t; -typedef machine_uint_t (*inline_asm_fun_0_t)(); -typedef machine_uint_t (*inline_asm_fun_1_t)(machine_uint_t); -typedef machine_uint_t (*inline_asm_fun_2_t)(machine_uint_t, machine_uint_t); -typedef machine_uint_t (*inline_asm_fun_3_t)(machine_uint_t, machine_uint_t, machine_uint_t); +typedef mp_uint_t (*inline_asm_fun_0_t)(); +typedef mp_uint_t (*inline_asm_fun_1_t)(mp_uint_t); +typedef mp_uint_t (*inline_asm_fun_2_t)(mp_uint_t, mp_uint_t); +typedef mp_uint_t (*inline_asm_fun_3_t)(mp_uint_t, mp_uint_t, mp_uint_t); // convert a Micro Python object to a sensible value for inline asm -STATIC machine_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { +STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { // TODO for byte_array, pass pointer to the array if (MP_OBJ_IS_SMALL_INT(obj)) { return MP_OBJ_SMALL_INT_VALUE(obj); @@ -528,42 +528,42 @@ STATIC machine_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { } else if (MP_OBJ_IS_STR(obj)) { // pointer to the string (it's probably constant though!) uint l; - return (machine_uint_t)mp_obj_str_get_data(obj, &l); + return (mp_uint_t)mp_obj_str_get_data(obj, &l); } else { mp_obj_type_t *type = mp_obj_get_type(obj); if (0) { #if MICROPY_PY_BUILTINS_FLOAT } else if (type == &mp_type_float) { // convert float to int (could also pass in float registers) - return (machine_int_t)mp_obj_float_get(obj); + return (mp_int_t)mp_obj_float_get(obj); #endif } else if (type == &mp_type_tuple) { // pointer to start of tuple (could pass length, but then could use len(x) for that) uint len; mp_obj_t *items; mp_obj_tuple_get(obj, &len, &items); - return (machine_uint_t)items; + return (mp_uint_t)items; } else if (type == &mp_type_list) { // pointer to start of list (could pass length, but then could use len(x) for that) uint len; mp_obj_t *items; mp_obj_list_get(obj, &len, &items); - return (machine_uint_t)items; + return (mp_uint_t)items; } else { mp_buffer_info_t bufinfo; if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_WRITE)) { // supports the buffer protocol, return a pointer to the data - return (machine_uint_t)bufinfo.buf; + return (mp_uint_t)bufinfo.buf; } else { // just pass along a pointer to the object - return (machine_uint_t)obj; + return (mp_uint_t)obj; } } } } // convert a return value from inline asm to a sensible Micro Python object -STATIC mp_obj_t convert_val_from_inline_asm(machine_uint_t val) { +STATIC mp_obj_t convert_val_from_inline_asm(mp_uint_t val) { return MP_OBJ_NEW_SMALL_INT(val); } @@ -572,7 +572,7 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_ mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false); - machine_uint_t ret; + mp_uint_t ret; if (n_args == 0) { ret = ((inline_asm_fun_0_t)self->fun)(); } else if (n_args == 1) { diff --git a/py/objfun.h b/py/objfun.h index f607a5eb6fa8..cc8035ef3738 100644 --- a/py/objfun.h +++ b/py/objfun.h @@ -26,15 +26,15 @@ typedef struct _mp_obj_fun_bc_t { mp_obj_base_t base; - mp_obj_dict_t *globals; // the context within which this function was defined - machine_uint_t n_pos_args : 16; // number of arguments this function takes - machine_uint_t n_kwonly_args : 16; // number of arguments this function takes - machine_uint_t n_def_args : 16; // number of default arguments - machine_uint_t has_def_kw_args : 1; // set if this function has default keyword args - machine_uint_t takes_var_args : 1; // set if this function takes variable args - machine_uint_t takes_kw_args : 1; // set if this function takes keyword args - const byte *bytecode; // bytecode for the function - qstr *args; // argument names (needed to resolve positional args passed as keywords) + mp_obj_dict_t *globals; // the context within which this function was defined + mp_uint_t n_pos_args : 16; // number of arguments this function takes + mp_uint_t n_kwonly_args : 16; // number of arguments this function takes + mp_uint_t n_def_args : 16; // number of default arguments + mp_uint_t has_def_kw_args : 1; // set if this function has default keyword args + mp_uint_t takes_var_args : 1; // set if this function takes variable args + mp_uint_t takes_kw_args : 1; // set if this function takes keyword args + const byte *bytecode; // bytecode for the function + qstr *args; // argument names (needed to resolve positional args passed as keywords) // the following extra_args array is allocated space to take (in order): // - values of positional default args (if any) // - a single slot for default kw args dict (if it has them) diff --git a/py/objgenerator.c b/py/objgenerator.c index 7eaeac9cce92..741ffc8a8436 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -59,12 +59,12 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp const byte *bytecode = self_fun->bytecode; // get code info size, and skip the line number table - machine_uint_t code_info_size = bytecode[0] | (bytecode[1] << 8) | (bytecode[2] << 16) | (bytecode[3] << 24); + mp_uint_t code_info_size = bytecode[0] | (bytecode[1] << 8) | (bytecode[2] << 16) | (bytecode[3] << 24); bytecode += code_info_size; // bytecode prelude: get state size and exception stack size - machine_uint_t n_state = bytecode[0] | (bytecode[1] << 8); - machine_uint_t n_exc_stack = bytecode[2] | (bytecode[3] << 8); + mp_uint_t n_state = bytecode[0] | (bytecode[1] << 8); + mp_uint_t n_exc_stack = bytecode[2] | (bytecode[3] << 8); bytecode += 4; // allocate the generator object, with room for local stack and exception stack diff --git a/py/objint.c b/py/objint.c index 331fdfa1b939..bca32d13fa8e 100644 --- a/py/objint.c +++ b/py/objint.c @@ -64,7 +64,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co return mp_parse_num_integer(s, l, 0); #if MICROPY_PY_BUILTINS_FLOAT } else if (MP_OBJ_IS_TYPE(args[0], &mp_type_float)) { - return MP_OBJ_NEW_SMALL_INT((machine_int_t)(MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0])))); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)(MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0])))); #endif } else { // try to convert to small int (eg from bool) @@ -85,7 +85,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { // The size of this buffer is rather arbitrary. If it's not large // enough, a dynamic one will be allocated. - char stack_buf[sizeof(machine_int_t) * 4]; + char stack_buf[sizeof(mp_int_t) * 4]; char *buf = stack_buf; int buf_size = sizeof(stack_buf); int fmt_size; @@ -101,7 +101,7 @@ void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG typedef mp_longint_impl_t fmt_int_t; #else -typedef mp_small_int_t fmt_int_t; +typedef mp_int_t fmt_int_t; #endif STATIC const uint log_base2_floor[] = { @@ -145,7 +145,7 @@ char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_const_ob // Not a small int. #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG const mp_obj_int_t *self = self_in; - // Get the value to format; mp_obj_get_int truncates to machine_int_t. + // Get the value to format; mp_obj_get_int truncates to mp_int_t. num = self->val; #else // Delegate to the implementation for the long int. @@ -241,7 +241,7 @@ mp_obj_t mp_obj_new_int_from_ll(long long val) { return mp_const_none; } -mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) { +mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) { // SMALL_INT accepts only signed numbers, of one bit less size // then word size, which totals 2 bits less for unsigned numbers. if ((value & (WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1))) == 0) { @@ -251,7 +251,7 @@ mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) { return mp_const_none; } -mp_obj_t mp_obj_new_int(machine_int_t value) { +mp_obj_t mp_obj_new_int(mp_int_t value) { if (MP_SMALL_INT_FITS(value)) { return MP_OBJ_NEW_SMALL_INT(value); } @@ -259,11 +259,11 @@ mp_obj_t mp_obj_new_int(machine_int_t value) { return mp_const_none; } -machine_int_t mp_obj_int_get(mp_const_obj_t self_in) { +mp_int_t mp_obj_int_get(mp_const_obj_t self_in) { return MP_OBJ_SMALL_INT_VALUE(self_in); } -machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { +mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { return MP_OBJ_SMALL_INT_VALUE(self_in); } @@ -304,7 +304,7 @@ STATIC mp_obj_t int_from_bytes(uint n_args, const mp_obj_t *args) { mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); // convert the bytes to an integer - machine_uint_t value = 0; + mp_uint_t value = 0; for (const byte* buf = (const byte*)bufinfo.buf + bufinfo.len - 1; buf >= (byte*)bufinfo.buf; buf--) { value = (value << 8) | *buf; } @@ -316,7 +316,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 2, 3, int_fro STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, (const mp_obj_t)&int_from_bytes_fun_obj); STATIC mp_obj_t int_to_bytes(uint n_args, const mp_obj_t *args) { - machine_int_t val = mp_obj_int_get_checked(args[0]); + mp_int_t val = mp_obj_int_get_checked(args[0]); uint len = MP_OBJ_SMALL_INT_VALUE(args[1]); byte *data; @@ -326,7 +326,7 @@ STATIC mp_obj_t int_to_bytes(uint n_args, const mp_obj_t *args) { // TODO: Support signed param mp_obj_t o = mp_obj_str_builder_start(&mp_type_bytes, len, &data); memset(data, 0, len); - memcpy(data, &val, len < sizeof(machine_int_t) ? len : sizeof(machine_int_t)); + memcpy(data, &val, len < sizeof(mp_int_t) ? len : sizeof(mp_int_t)); return mp_obj_str_builder_end(o); } diff --git a/py/objint_longlong.c b/py/objint_longlong.c index dfe069c087e3..13e3b4811ad5 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -140,14 +140,14 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } } -mp_obj_t mp_obj_new_int(machine_int_t value) { +mp_obj_t mp_obj_new_int(mp_int_t value) { if (MP_SMALL_INT_FITS(value)) { return MP_OBJ_NEW_SMALL_INT(value); } return mp_obj_new_int_from_ll(value); } -mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) { +mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) { // SMALL_INT accepts only signed numbers, of one bit less size // than word size, which totals 2 bits less for unsigned numbers. if ((value & (WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1))) == 0) { @@ -174,7 +174,7 @@ mp_obj_t mp_obj_new_int_from_str_len(const char **str, uint len, bool neg, uint return o; } -machine_int_t mp_obj_int_get(mp_const_obj_t self_in) { +mp_int_t mp_obj_int_get(mp_const_obj_t self_in) { if (MP_OBJ_IS_SMALL_INT(self_in)) { return MP_OBJ_SMALL_INT_VALUE(self_in); } else { @@ -183,7 +183,7 @@ machine_int_t mp_obj_int_get(mp_const_obj_t self_in) { } } -machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { +mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { // TODO: Check overflow return mp_obj_int_get(self_in); } diff --git a/py/objint_mpz.c b/py/objint_mpz.c index cf7896f9e109..da02b1ea9b90 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -198,7 +198,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { case MP_BINARY_OP_RSHIFT: case MP_BINARY_OP_INPLACE_RSHIFT: { // TODO check conversion overflow - machine_int_t irhs = mpz_as_int(zrhs); + mp_int_t irhs = mpz_as_int(zrhs); if (irhs < 0) { nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count")); } @@ -241,7 +241,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } } -mp_obj_t mp_obj_new_int(machine_int_t value) { +mp_obj_t mp_obj_new_int(mp_int_t value) { if (MP_SMALL_INT_FITS(value)) { return MP_OBJ_NEW_SMALL_INT(value); } @@ -254,7 +254,7 @@ mp_obj_t mp_obj_new_int_from_ll(long long val) { return o; } -mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) { +mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) { // SMALL_INT accepts only signed numbers, of one bit less size // than word size, which totals 2 bits less for unsigned numbers. if ((value & (WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1))) == 0) { @@ -270,7 +270,7 @@ mp_obj_t mp_obj_new_int_from_str_len(const char **str, uint len, bool neg, uint return o; } -machine_int_t mp_obj_int_get(mp_const_obj_t self_in) { +mp_int_t mp_obj_int_get(mp_const_obj_t self_in) { if (MP_OBJ_IS_SMALL_INT(self_in)) { return MP_OBJ_SMALL_INT_VALUE(self_in); } else { @@ -279,12 +279,12 @@ machine_int_t mp_obj_int_get(mp_const_obj_t self_in) { } } -machine_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { +mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) { if (MP_OBJ_IS_SMALL_INT(self_in)) { return MP_OBJ_SMALL_INT_VALUE(self_in); } else { const mp_obj_int_t *self = self_in; - machine_int_t value; + mp_int_t value; if (mpz_as_int_checked(&self->mpz, &value)) { return value; } else { diff --git a/py/objlist.c b/py/objlist.c index 6e22169fd96c..655a78908ecf 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -127,7 +127,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { return o; } case MP_BINARY_OP_MULTIPLY: { - machine_int_t n; + mp_int_t n; if (!mp_obj_get_int_maybe(rhs, &n)) { return MP_OBJ_NULL; // op not supported } @@ -488,7 +488,7 @@ void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { typedef struct _mp_obj_list_it_t { mp_obj_base_t base; mp_obj_list_t *list; - machine_uint_t cur; + mp_uint_t cur; } mp_obj_list_it_t; mp_obj_t list_it_iternext(mp_obj_t self_in) { diff --git a/py/objlist.h b/py/objlist.h index b71ab4fb3fe8..05a4c8d3ab2f 100644 --- a/py/objlist.h +++ b/py/objlist.h @@ -26,7 +26,7 @@ typedef struct _mp_obj_list_t { mp_obj_base_t base; - machine_uint_t alloc; - machine_uint_t len; + mp_uint_t alloc; + mp_uint_t len; mp_obj_t *items; } mp_obj_list_t; diff --git a/py/objmap.c b/py/objmap.c index 6e5c79017d07..2cbc1619ba61 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_map_t { mp_obj_base_t base; - machine_uint_t n_iters; + mp_uint_t n_iters; mp_obj_t fun; mp_obj_t iters[]; } mp_obj_map_t; diff --git a/py/objrange.c b/py/objrange.c index 1970084bd145..49fa10acc680 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -39,9 +39,9 @@ typedef struct _mp_obj_range_it_t { mp_obj_base_t base; // TODO make these values generic objects or something - machine_int_t cur; - machine_int_t stop; - machine_int_t step; + mp_int_t cur; + mp_int_t stop; + mp_int_t step; } mp_obj_range_it_t; STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) { @@ -77,9 +77,9 @@ mp_obj_t mp_obj_new_range_iterator(int cur, int stop, int step) { typedef struct _mp_obj_range_t { mp_obj_base_t base; // TODO make these values generic objects or something - machine_int_t start; - machine_int_t stop; - machine_int_t step; + mp_int_t start; + mp_int_t stop; + mp_int_t step; } mp_obj_range_t; STATIC mp_obj_t range_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { diff --git a/py/objset.c b/py/objset.c index ab76b5764257..48d037ffc25b 100644 --- a/py/objset.c +++ b/py/objset.c @@ -47,7 +47,7 @@ typedef struct _mp_obj_set_t { typedef struct _mp_obj_set_it_t { mp_obj_base_t base; mp_obj_set_t *set; - machine_uint_t cur; + mp_uint_t cur; } mp_obj_set_it_t; STATIC mp_obj_t set_it_iternext(mp_obj_t self_in); @@ -160,10 +160,10 @@ const mp_obj_type_t mp_type_set_it = { STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set_it)); mp_obj_set_it_t *self = self_in; - machine_uint_t max = self->set->set.alloc; + mp_uint_t max = self->set->set.alloc; mp_set_t *set = &self->set->set; - for (machine_uint_t i = self->cur; i < max; i++) { + for (mp_uint_t i = self->cur; i < max; i++) { if (MP_SET_SLOT_IS_FILLED(set, i)) { self->cur = i + 1; return set->table[i]; @@ -476,7 +476,7 @@ STATIC mp_obj_t set_unary_op(int op, mp_obj_t self_in) { mp_obj_set_t *self = self_in; switch (op) { case MP_UNARY_OP_BOOL: return MP_BOOL(self->set.used != 0); - case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->set.used); + case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->set.used); default: return MP_OBJ_NULL; // op not supported } } diff --git a/py/objstr.c b/py/objstr.c index b13517b63d32..63d394e0a91d 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -226,9 +226,9 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m // like strstr but with specified length and allows \0 bytes // TODO replace with something more efficient/standard -STATIC const byte *find_subbytes(const byte *haystack, machine_uint_t hlen, const byte *needle, machine_uint_t nlen, machine_int_t direction) { +STATIC const byte *find_subbytes(const byte *haystack, mp_uint_t hlen, const byte *needle, mp_uint_t nlen, mp_int_t direction) { if (hlen >= nlen) { - machine_uint_t str_index, str_index_end; + mp_uint_t str_index, str_index_end; if (direction > 0) { str_index = 0; str_index_end = hlen - nlen; @@ -348,7 +348,7 @@ mp_obj_t mp_obj_str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // objstrunicode defines own version const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, uint self_len, mp_obj_t index, bool is_slice) { - machine_uint_t index_val = mp_get_index(type, self_len, index, is_slice); + mp_uint_t index_val = mp_get_index(type, self_len, index, is_slice); return self_data + index_val; } #endif @@ -370,7 +370,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { #endif const byte *p = str_index_to_ptr(type, self_data, self_len, index, false); if (type == &mp_type_bytes) { - return MP_OBJ_NEW_SMALL_INT((mp_small_int_t)*p); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)*p); } else { return mp_obj_new_str((char*)p, 1, true); } @@ -435,7 +435,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); - machine_int_t splits = -1; + mp_int_t splits = -1; mp_obj_t sep = mp_const_none; if (n_args > 1) { sep = args[1]; @@ -515,8 +515,8 @@ STATIC mp_obj_t str_rsplit(uint n_args, const mp_obj_t *args) { mp_obj_t sep = args[1]; GET_STR_DATA_LEN(args[0], s, len); - machine_int_t splits = mp_obj_get_int(args[2]); - machine_int_t org_splits = splits; + mp_int_t splits = mp_obj_get_int(args[2]); + mp_int_t org_splits = splits; // Preallocate list to the max expected # of elements, as we // will fill it from the end. mp_obj_list_t *res = mp_obj_new_list(splits + 1, NULL); @@ -566,7 +566,7 @@ STATIC mp_obj_t str_rsplit(uint n_args, const mp_obj_t *args) { return res; } -STATIC mp_obj_t str_finder(uint n_args, const mp_obj_t *args, machine_int_t direction, bool is_index) { +STATIC mp_obj_t str_finder(uint n_args, const mp_obj_t *args, mp_int_t direction, bool is_index) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); assert(2 <= n_args && n_args <= 4); assert(MP_OBJ_IS_STR(args[0])); @@ -670,16 +670,16 @@ STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) { GET_STR_DATA_LEN(args[0], orig_str, orig_str_len); - machine_uint_t first_good_char_pos = 0; + mp_uint_t first_good_char_pos = 0; bool first_good_char_pos_set = false; - machine_uint_t last_good_char_pos = 0; - machine_uint_t i = 0; - machine_int_t delta = 1; + mp_uint_t last_good_char_pos = 0; + mp_uint_t i = 0; + mp_int_t delta = 1; if (type == RSTRIP) { i = orig_str_len - 1; delta = -1; } - for (machine_uint_t len = orig_str_len; len > 0; len--) { + for (mp_uint_t len = orig_str_len; len > 0; len--) { if (find_subbytes(chars_to_del, chars_to_del_len, &orig_str[i], 1, 1) == NULL) { if (!first_good_char_pos_set) { first_good_char_pos_set = true; @@ -705,7 +705,7 @@ STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) { assert(last_good_char_pos >= first_good_char_pos); //+1 to accomodate the last character - machine_uint_t stripped_len = last_good_char_pos - first_good_char_pos + 1; + mp_uint_t stripped_len = last_good_char_pos - first_good_char_pos + 1; if (stripped_len == orig_str_len) { // If nothing was stripped, don't bother to dup original string // TODO: watch out for this case when we'll get to bytearray.strip() @@ -768,7 +768,7 @@ static mp_obj_t arg_as_int(mp_obj_t arg) { // TODO: Needs a way to construct an mpz integer from a float - mp_small_int_t num = mp_obj_get_float(arg); + mp_int_t num = mp_obj_get_float(arg); return MP_OBJ_NEW_SMALL_INT(num); } #endif @@ -1329,7 +1329,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t STATIC mp_obj_t str_replace(uint n_args, const mp_obj_t *args) { assert(MP_OBJ_IS_STR(args[0])); - machine_int_t max_rep = -1; + mp_int_t max_rep = -1; if (n_args == 4) { max_rep = mp_obj_get_int(args[3]); if (max_rep == 0) { @@ -1370,11 +1370,11 @@ STATIC mp_obj_t str_replace(uint n_args, const mp_obj_t *args) { // first pass computes the required length of the replaced string // second pass does the replacements for (;;) { - machine_uint_t replaced_str_index = 0; - machine_uint_t num_replacements_done = 0; + mp_uint_t replaced_str_index = 0; + mp_uint_t num_replacements_done = 0; const byte *old_occurrence; const byte *offset_ptr = str; - machine_uint_t str_len_remain = str_len; + mp_uint_t str_len_remain = str_len; if (old_len == 0) { // if old_str is empty, copy new_str to start of replaced string // copy the replacement string @@ -1452,7 +1452,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) { } // count the occurrences - machine_int_t num_occurrences = 0; + mp_int_t num_occurrences = 0; for (const byte *haystack_ptr = start; haystack_ptr + needle_len <= end;) { if (memcmp(haystack_ptr, needle, needle_len) == 0) { num_occurrences++; @@ -1465,7 +1465,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(num_occurrences); } -STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, machine_int_t direction) { +STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t direction) { if (!is_str_or_bytes(self_in)) { assert(0); } @@ -1491,7 +1491,7 @@ STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, machine_int_t di const byte *position_ptr = find_subbytes(str, str_len, sep, sep_len, direction); if (position_ptr != NULL) { - machine_uint_t position = position_ptr - str; + mp_uint_t position = position_ptr - str; result[0] = mp_obj_new_str_of_type(self_type, str, position); result[1] = arg; result[2] = mp_obj_new_str_of_type(self_type, str + position + sep_len, str_len - position - sep_len); @@ -1609,7 +1609,7 @@ STATIC mp_obj_t str_encode(uint n_args, const mp_obj_t *args) { } #endif -machine_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags) { +mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags) { if (flags == MP_BUFFER_READ) { GET_STR_DATA_LEN(self_in, str_data, str_len); bufinfo->buf = (void*)str_data; @@ -1871,7 +1871,7 @@ const char *mp_obj_str_get_data(mp_obj_t self_in, uint *len) { typedef struct _mp_obj_str_it_t { mp_obj_base_t base; mp_obj_t str; - machine_uint_t cur; + mp_uint_t cur; } mp_obj_str_it_t; #if !MICROPY_PY_BUILTINS_STR_UNICODE @@ -1907,7 +1907,7 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) { mp_obj_str_it_t *self = self_in; GET_STR_DATA_LEN(self->str, str, len); if (self->cur < len) { - mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT((mp_small_int_t)str[self->cur]); + mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT((mp_int_t)str[self->cur]); self->cur += 1; return o_out; } else { diff --git a/py/objstr.h b/py/objstr.h index 515890c6e1e8..6818b4603e2e 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -27,9 +27,9 @@ typedef struct _mp_obj_str_t { mp_obj_base_t base; // XXX here we assume the hash size is 16 bits (it is at the moment; see qstr.c) - machine_uint_t hash : 16; + mp_uint_t hash : 16; // len == number of bytes used in data, alloc = len + 1 because (at the moment) we also append a null byte - machine_uint_t len : 16; + mp_uint_t len : 16; const byte *data; } mp_obj_str_t; @@ -55,7 +55,7 @@ mp_obj_t mp_obj_str_format(uint n_args, const mp_obj_t *args); mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, uint len); mp_obj_t mp_obj_str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in); -machine_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags); +mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags); const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, uint self_len, mp_obj_t index, bool is_slice); diff --git a/py/objstringio.c b/py/objstringio.c index d9ad604b417a..bffdf2cf795f 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -43,7 +43,7 @@ typedef struct _mp_obj_stringio_t { mp_obj_base_t base; vstr_t *vstr; // StringIO has single pointer used for both reading and writing - machine_uint_t pos; + mp_uint_t pos; } mp_obj_stringio_t; STATIC void stringio_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { @@ -51,9 +51,9 @@ STATIC void stringio_print(void (*print)(void *env, const char *fmt, ...), void print(env, self->base.type == &mp_type_stringio ? "" : "", self->vstr); } -STATIC machine_int_t stringio_read(mp_obj_t o_in, void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_stringio_t *o = o_in; - machine_uint_t remaining = o->vstr->len - o->pos; + mp_uint_t remaining = o->vstr->len - o->pos; if (size > remaining) { size = remaining; } @@ -62,9 +62,9 @@ STATIC machine_int_t stringio_read(mp_obj_t o_in, void *buf, machine_uint_t size return size; } -STATIC machine_int_t stringio_write(mp_obj_t o_in, const void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_stringio_t *o = o_in; - machine_uint_t remaining = o->vstr->alloc - o->pos; + mp_uint_t remaining = o->vstr->alloc - o->pos; if (size > remaining) { // Take all what's already allocated... o->vstr->len = o->vstr->alloc; diff --git a/py/objstrunicode.c b/py/objstrunicode.c index d96ce0a5527a..873b4fc58e8b 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -156,7 +156,7 @@ STATIC mp_obj_t str_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ // be capped to the first/last character of the string, depending on is_slice. const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, uint self_len, mp_obj_t index, bool is_slice) { - machine_int_t i; + mp_int_t i; // Copied from mp_get_index; I don't want bounds checking, just give me // the integer as-is. (I can't bounds-check without scanning the whole // string; an out-of-bounds index will be caught in the loops below.) @@ -221,7 +221,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } if (type == &mp_type_bytes) { - machine_int_t start = 0, stop = self_len; + mp_int_t start = 0, stop = self_len; if (ostart != mp_const_none) { start = MP_OBJ_SMALL_INT_VALUE(ostart); if (start < 0) { @@ -257,7 +257,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { #endif if (type == &mp_type_bytes) { uint index_val = mp_get_index(type, self_len, index, false); - return MP_OBJ_NEW_SMALL_INT((mp_small_int_t)self_data[index_val]); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)self_data[index_val]); } const byte *s = str_index_to_ptr(type, self_data, self_len, index, false); int len = 1; @@ -324,7 +324,7 @@ const mp_obj_type_t mp_type_str = { typedef struct _mp_obj_str_it_t { mp_obj_base_t base; mp_obj_t str; - machine_uint_t cur; + mp_uint_t cur; } mp_obj_str_it_t; STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { diff --git a/py/objtuple.c b/py/objtuple.c index 2be04400fe99..3dade2f74861 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -252,11 +252,11 @@ void mp_obj_tuple_del(mp_obj_t self_in) { m_del_var(mp_obj_tuple_t, mp_obj_t, self->len, self); } -machine_int_t mp_obj_tuple_hash(mp_obj_t self_in) { +mp_int_t mp_obj_tuple_hash(mp_obj_t self_in) { assert(MP_OBJ_IS_TYPE(self_in, &mp_type_tuple)); mp_obj_tuple_t *self = self_in; // start hash with pointer to empty tuple, to make it fairly unique - machine_int_t hash = (machine_int_t)mp_const_empty_tuple; + mp_int_t hash = (mp_int_t)mp_const_empty_tuple; for (uint i = 0; i < self->len; i++) { hash += mp_obj_hash(self->items[i]); } @@ -269,7 +269,7 @@ machine_int_t mp_obj_tuple_hash(mp_obj_t self_in) { typedef struct _mp_obj_tuple_it_t { mp_obj_base_t base; mp_obj_tuple_t *tuple; - machine_uint_t cur; + mp_uint_t cur; } mp_obj_tuple_it_t; STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) { diff --git a/py/objtuple.h b/py/objtuple.h index cabe63f80f51..b1e02e422d47 100644 --- a/py/objtuple.h +++ b/py/objtuple.h @@ -26,7 +26,7 @@ typedef struct _mp_obj_tuple_t { mp_obj_base_t base; - machine_uint_t len; + mp_uint_t len; mp_obj_t items[]; } mp_obj_tuple_t; diff --git a/py/objtype.c b/py/objtype.c index 80f39d7f1f78..f812a0e86caf 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -101,7 +101,7 @@ STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_t struct class_lookup_data { mp_obj_instance_t *obj; qstr attr; - machine_uint_t meth_offset; + mp_uint_t meth_offset; mp_obj_t *dest; bool is_type; }; diff --git a/py/parse.c b/py/parse.c index 492c1678b5cd..a41fc4c81ffa 100644 --- a/py/parse.c +++ b/py/parse.c @@ -166,7 +166,7 @@ STATIC void pop_rule(parser_t *parser, const rule_t **rule, uint *arg_i, uint *s *src_line = parser->rule_stack[parser->rule_stack_top].src_line; } -mp_parse_node_t mp_parse_node_new_leaf(machine_int_t kind, machine_int_t arg) { +mp_parse_node_t mp_parse_node_new_leaf(mp_int_t kind, mp_int_t arg) { if (kind == MP_PARSE_NODE_SMALL_INT) { return (mp_parse_node_t)(kind | (arg << 1)); } @@ -208,10 +208,10 @@ void mp_parse_node_print(mp_parse_node_t pn, int indent) { if (MP_PARSE_NODE_IS_NULL(pn)) { printf("NULL\n"); } else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { - machine_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn); + mp_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn); printf("int(" INT_FMT ")\n", arg); } else if (MP_PARSE_NODE_IS_LEAF(pn)) { - machine_uint_t 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: printf("id(%s)\n", qstr_str(arg)); break; case MP_PARSE_NODE_INTEGER: printf("int(%s)\n", qstr_str(arg)); break; @@ -292,7 +292,7 @@ STATIC void push_result_string(parser_t *parser, int src_line, const char *str, pn->kind_num_nodes = RULE_string | (2 << 8); char *p = m_new(char, len); memcpy(p, str, len); - pn->nodes[0] = (machine_int_t)p; + pn->nodes[0] = (mp_int_t)p; pn->nodes[1] = len; push_result_node(parser, (mp_parse_node_t)pn); } @@ -305,7 +305,7 @@ STATIC void push_result_token(parser_t *parser, const mp_lexer_t *lex) { } else if (tok->kind == MP_TOKEN_NUMBER) { bool dec = false; bool small_int = true; - machine_int_t int_val = 0; + mp_int_t int_val = 0; int len = tok->len; const char *str = tok->str; int base = 0; diff --git a/py/parse.h b/py/parse.h index 6950139e7b0c..782d7d483cc4 100644 --- a/py/parse.h +++ b/py/parse.h @@ -46,7 +46,7 @@ struct _mp_lexer_t; #define MP_PARSE_NODE_BYTES (0x12) #define MP_PARSE_NODE_TOKEN (0x16) -typedef machine_uint_t mp_parse_node_t; // must be pointer size +typedef mp_uint_t mp_parse_node_t; // must be pointer size typedef struct _mp_parse_node_struct_t { uint32_t source_line; // line number in source file @@ -69,12 +69,12 @@ typedef struct _mp_parse_node_struct_t { #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) (((machine_uint_t)(pn)) >> 5) -#define MP_PARSE_NODE_LEAF_SMALL_INT(pn) (((machine_int_t)(pn)) >> 1) +#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) #define MP_PARSE_NODE_STRUCT_NUM_NODES(pns) ((pns)->kind_num_nodes >> 8) -mp_parse_node_t mp_parse_node_new_leaf(machine_int_t kind, machine_int_t arg); +mp_parse_node_t mp_parse_node_new_leaf(mp_int_t kind, mp_int_t arg); void mp_parse_node_free(mp_parse_node_t pn); void mp_parse_node_print(mp_parse_node_t pn, int indent); diff --git a/py/parsenum.c b/py/parsenum.c index b9801ab6a1ca..9f84bfc5ad51 100644 --- a/py/parsenum.c +++ b/py/parsenum.c @@ -70,7 +70,7 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, uint len, int base) { str += mp_parse_num_base((const char*)str, top - str, &base); // string should be an integer number - machine_int_t int_val = 0; + mp_int_t int_val = 0; const byte *restrict str_val_start = str; for (; str < top; str++) { // get next digit as a value diff --git a/py/pfenv.c b/py/pfenv.c index ca1e3e919bc3..15793ff762eb 100644 --- a/py/pfenv.c +++ b/py/pfenv.c @@ -111,14 +111,14 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in // 32-bits is 10 digits, add 3 for commas, 1 for sign, 1 for terminating null // We can use 16 characters for 32-bit and 32 characters for 64-bit -#define INT_BUF_SIZE (sizeof(machine_int_t) * 4) +#define INT_BUF_SIZE (sizeof(mp_int_t) * 4) // This function is used by stmhal port to implement printf. // It needs to be a separate function to pfenv_print_mp_int, since converting to a mp_int looses the MSB. -int pfenv_print_int(const pfenv_t *pfenv, machine_uint_t x, int sgn, int base, int base_char, 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) { char sign = 0; if (sgn) { - if ((machine_int_t)x < 0) { + if ((mp_int_t)x < 0) { sign = '-'; x = -x; } else if (flags & PF_FLAG_SHOW_SIGN) { @@ -232,7 +232,7 @@ int pfenv_print_mp_int(const pfenv_t *pfenv, mp_obj_t x, int sgn, int base, int // The size of this buffer is rather arbitrary. If it's not large // enough, a dynamic one will be allocated. - char stack_buf[sizeof(machine_int_t) * 4]; + char stack_buf[sizeof(mp_int_t) * 4]; char *buf = stack_buf; int buf_size = sizeof(stack_buf); int fmt_size = 0; diff --git a/py/pfenv.h b/py/pfenv.h index 55eca6fed188..22b1fc8492e9 100644 --- a/py/pfenv.h +++ b/py/pfenv.h @@ -44,7 +44,7 @@ typedef struct _pfenv_t { void pfenv_vstr_add_strn(void *data, const char *str, unsigned int len); int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, int flags, char fill, int width); -int pfenv_print_int(const pfenv_t *pfenv, machine_uint_t x, int sgn, int base, int base_char, 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 int pfenv_print_float(const pfenv_t *pfenv, mp_float_t f, char fmt, int flags, char fill, int width, int prec); diff --git a/py/qstr.c b/py/qstr.c index 10bc20ecba25..27f13774e5c3 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -55,9 +55,9 @@ #define Q_GET_DATA(q) ((q) + 4) // this must match the equivalent function in makeqstrdata.py -machine_uint_t qstr_compute_hash(const byte *data, uint len) { +mp_uint_t qstr_compute_hash(const byte *data, uint len) { // djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html - machine_uint_t hash = 5381; + mp_uint_t hash = 5381; for (const byte *top = data + len; data < top; data++) { hash = ((hash << 5) + hash) ^ (*data); // hash * 33 ^ data } @@ -132,7 +132,7 @@ STATIC qstr qstr_add(const byte *q_ptr) { qstr qstr_find_strn(const char *str, uint str_len) { // work out hash of str - machine_uint_t str_hash = qstr_compute_hash((const byte*)str, str_len); + mp_uint_t str_hash = qstr_compute_hash((const byte*)str, str_len); // search pools for the data for (qstr_pool_t *pool = last_pool; pool != NULL; pool = pool->prev) { @@ -154,7 +154,7 @@ qstr qstr_from_str(const char *str) { qstr qstr_from_strn(const char *str, uint len) { qstr q = qstr_find_strn(str, len); if (q == 0) { - machine_uint_t hash = qstr_compute_hash((const byte*)str, len); + mp_uint_t hash = qstr_compute_hash((const byte*)str, len); byte *q_ptr = m_new(byte, 4 + len + 1); q_ptr[0] = hash; q_ptr[1] = hash >> 8; @@ -178,8 +178,8 @@ byte *qstr_build_start(uint len, byte **q_ptr) { qstr qstr_build_end(byte *q_ptr) { qstr q = qstr_find_strn((const char*)Q_GET_DATA(q_ptr), Q_GET_LENGTH(q_ptr)); if (q == 0) { - machine_uint_t len = Q_GET_LENGTH(q_ptr); - machine_uint_t hash = qstr_compute_hash(Q_GET_DATA(q_ptr), len); + mp_uint_t len = Q_GET_LENGTH(q_ptr); + mp_uint_t hash = qstr_compute_hash(Q_GET_DATA(q_ptr), len); q_ptr[0] = hash; q_ptr[1] = hash >> 8; q_ptr[4 + len] = '\0'; @@ -190,7 +190,7 @@ qstr qstr_build_end(byte *q_ptr) { return q; } -machine_uint_t qstr_hash(qstr q) { +mp_uint_t qstr_hash(qstr q) { return Q_GET_HASH(find_qstr(q)); } diff --git a/py/qstr.h b/py/qstr.h index 9803e672ca21..0d9db19f7bbb 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -39,13 +39,13 @@ enum { MP_QSTR_number_of, }; -typedef machine_uint_t qstr; +typedef mp_uint_t qstr; #define QSTR_FROM_STR_STATIC(s) (qstr_from_strn((s), strlen(s))) void qstr_init(void); -machine_uint_t qstr_compute_hash(const byte *data, uint len); +mp_uint_t qstr_compute_hash(const byte *data, uint len); qstr qstr_find_strn(const char *str, uint str_len); // returns MP_QSTR_NULL if not found qstr qstr_from_str(const char *str); @@ -56,7 +56,7 @@ qstr qstr_from_strn(const char *str, uint len); byte* qstr_build_start(uint len, byte **q_ptr); qstr qstr_build_end(byte *q_ptr); -machine_uint_t qstr_hash(qstr q); +mp_uint_t qstr_hash(qstr q); const char* qstr_str(qstr q); uint qstr_len(qstr q); const byte* qstr_data(qstr q, uint *len); diff --git a/py/runtime.c b/py/runtime.c index 5490bcbac51f..a478bb62fce7 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -187,7 +187,7 @@ mp_obj_t mp_unary_op(int op, mp_obj_t arg) { DEBUG_OP_printf("unary %d %p\n", op, arg); if (MP_OBJ_IS_SMALL_INT(arg)) { - mp_small_int_t val = MP_OBJ_SMALL_INT_VALUE(arg); + mp_int_t val = MP_OBJ_SMALL_INT_VALUE(arg); switch (op) { case MP_UNARY_OP_BOOL: return MP_BOOL(val != 0); @@ -272,17 +272,17 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { } if (MP_OBJ_IS_SMALL_INT(lhs)) { - mp_small_int_t lhs_val = MP_OBJ_SMALL_INT_VALUE(lhs); + mp_int_t lhs_val = MP_OBJ_SMALL_INT_VALUE(lhs); if (MP_OBJ_IS_SMALL_INT(rhs)) { - mp_small_int_t rhs_val = MP_OBJ_SMALL_INT_VALUE(rhs); + mp_int_t rhs_val = MP_OBJ_SMALL_INT_VALUE(rhs); // This is a binary operation: lhs_val op rhs_val // We need to be careful to handle overflow; see CERT INT32-C // Operations that can overflow: - // + result always fits in machine_int_t, then handled by SMALL_INT check - // - result always fits in machine_int_t, then handled by SMALL_INT check + // + result always fits in mp_int_t, then handled by SMALL_INT check + // - result always fits in mp_int_t, then handled by SMALL_INT check // * checked explicitly - // / if lhs=MIN and rhs=-1; result always fits in machine_int_t, then handled by SMALL_INT check - // % if lhs=MIN and rhs=-1; result always fits in machine_int_t, then handled by SMALL_INT check + // / if lhs=MIN and rhs=-1; result always fits in mp_int_t, then handled by SMALL_INT check + // % if lhs=MIN and rhs=-1; result always fits in mp_int_t, then handled by SMALL_INT check // << checked explicitly switch (op) { case MP_BINARY_OP_OR: @@ -323,7 +323,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { case MP_BINARY_OP_MULTIPLY: case MP_BINARY_OP_INPLACE_MULTIPLY: { - // If long long type exists and is larger than machine_int_t, then + // If long long type exists and is larger than mp_int_t, then // we can use the following code to perform overflow-checked multiplication. // Otherwise (eg in x64 case) we must use mp_small_int_mul_overflow. #if 0 @@ -334,7 +334,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { return mp_obj_new_int_from_ll(res); } else { // use standard precision - lhs_val = (mp_small_int_t)res; + lhs_val = (mp_int_t)res; } #endif @@ -381,7 +381,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative power with no float support")); #endif } else { - machine_int_t ans = 1; + mp_int_t ans = 1; while (rhs_val > 0) { if (rhs_val & 1) { if (mp_small_int_mul_overflow(ans, lhs_val)) { diff --git a/py/runtime.h b/py/runtime.h index fb61c01dd158..2feb24de9749 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -41,13 +41,13 @@ typedef enum { typedef union _mp_arg_val_t { bool u_bool; - machine_int_t u_int; + mp_int_t u_int; mp_obj_t u_obj; } mp_arg_val_t; typedef struct _mp_arg_t { qstr qstr; - machine_uint_t flags; + mp_uint_t flags; mp_arg_val_t defval; } mp_arg_t; diff --git a/py/sequence.c b/py/sequence.c index df8248811928..e180bf1d69db 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -53,9 +53,9 @@ void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void #if MICROPY_PY_BUILTINS_SLICE -bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes) { +bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes) { mp_obj_t ostart, ostop, ostep; - machine_int_t start, stop; + mp_int_t start, stop; mp_obj_slice_get(slice, &ostart, &ostop, &ostep); if (ostart == mp_const_none) { @@ -103,8 +103,8 @@ bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_ #endif mp_obj_t mp_seq_extract_slice(uint len, const mp_obj_t *seq, mp_bound_slice_t *indexes) { - machine_int_t start = indexes->start, stop = indexes->stop; - machine_int_t step = indexes->step; + mp_int_t start = indexes->start, stop = indexes->stop; + mp_int_t step = indexes->step; mp_obj_t res = mp_obj_new_list(0, NULL); @@ -231,7 +231,7 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, uint len, uint n_args, const mp } } - for (machine_uint_t i = start; i < stop; i++) { + for (mp_uint_t i = start; i < stop; i++) { if (mp_obj_equal(items[i], value)) { // Common sense says this cannot overflow small int return MP_OBJ_NEW_SMALL_INT(i); @@ -242,7 +242,7 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, uint len, uint n_args, const mp } mp_obj_t mp_seq_count_obj(const mp_obj_t *items, uint len, mp_obj_t value) { - machine_uint_t count = 0; + mp_uint_t count = 0; for (uint i = 0; i < len; i++) { if (mp_obj_equal(items[i], value)) { count++; diff --git a/py/showbc.c b/py/showbc.c index 5a4e918cd5ed..12400fa7c264 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -49,9 +49,9 @@ } while ((*ip++ & 0x80) != 0); \ } #define DECODE_PTR do { \ - ip = (byte*)(((machine_uint_t)ip + sizeof(machine_uint_t) - 1) & (~(sizeof(machine_uint_t) - 1))); /* align ip */ \ - unum = *(machine_uint_t*)ip; \ - ip += sizeof(machine_uint_t); \ + ip = (byte*)(((mp_uint_t)ip + sizeof(mp_uint_t) - 1) & (~(sizeof(mp_uint_t) - 1))); /* align ip */ \ + unum = *(mp_uint_t*)ip; \ + ip += sizeof(mp_uint_t); \ } while (0) void mp_bytecode_print2(const byte *ip, int len); @@ -60,7 +60,7 @@ void mp_bytecode_print(const void *descr, const byte *ip, int len) { const byte *ip_start = ip; // get code info size - machine_uint_t code_info_size = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24); + mp_uint_t code_info_size = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24); const byte *code_info = ip; ip += code_info_size; @@ -92,8 +92,8 @@ void mp_bytecode_print(const void *descr, const byte *ip, int len) { // print out line number info { - machine_int_t bc = (code_info + code_info_size) - ip; - machine_uint_t source_line = 1; + mp_int_t bc = (code_info + code_info_size) - ip; + mp_uint_t source_line = 1; printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line); for (const byte* ci = code_info + 12; *ci; ci++) { bc += *ci & 31; @@ -106,7 +106,7 @@ void mp_bytecode_print(const void *descr, const byte *ip, int len) { void mp_bytecode_print2(const byte *ip, int len) { const byte *ip_start = ip; - machine_uint_t unum; + mp_uint_t unum; qstr qstr; while (ip - ip_start < len) { printf("%02u ", (uint)(ip - ip_start)); @@ -129,7 +129,7 @@ void mp_bytecode_print2(const byte *ip, int len) { break; case MP_BC_LOAD_CONST_SMALL_INT: { - machine_int_t num = 0; + mp_int_t num = 0; if ((ip[0] & 0x40) != 0) { // Number is negative num--; @@ -445,14 +445,14 @@ void mp_bytecode_print2(const byte *ip, int len) { case MP_BC_MAKE_CLOSURE: { DECODE_PTR; - machine_uint_t n_closed_over = *ip++; + mp_uint_t n_closed_over = *ip++; printf("MAKE_CLOSURE %p " UINT_FMT, (void*)unum, n_closed_over); break; } case MP_BC_MAKE_CLOSURE_DEFARGS: { DECODE_PTR; - machine_uint_t n_closed_over = *ip++; + mp_uint_t n_closed_over = *ip++; printf("MAKE_CLOSURE_DEFARGS %p " UINT_FMT, (void*)unum, n_closed_over); break; } diff --git a/py/smallint.c b/py/smallint.c index c57f364e36d5..804514799fed 100644 --- a/py/smallint.c +++ b/py/smallint.c @@ -30,7 +30,7 @@ #include "obj.h" #include "smallint.h" -bool mp_small_int_mul_overflow(machine_int_t x, machine_int_t y) { +bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y) { // Check for multiply overflow; see CERT INT32-C if (x > 0) { // x is positive if (y > 0) { // x and y are positive @@ -56,20 +56,19 @@ bool mp_small_int_mul_overflow(machine_int_t x, machine_int_t y) { return false; } -machine_int_t mp_small_int_modulo(machine_int_t dividend, machine_int_t divisor) { - machine_int_t lsign = (dividend >= 0) ? 1 :-1; - machine_int_t rsign = (divisor >= 0) ? 1 :-1; +mp_int_t mp_small_int_modulo(mp_int_t dividend, mp_int_t divisor) { + mp_int_t lsign = (dividend >= 0) ? 1 :-1; + mp_int_t rsign = (divisor >= 0) ? 1 :-1; dividend %= divisor; if (lsign != rsign) { dividend += divisor; } - return dividend; + return dividend; } - -machine_int_t mp_small_int_floor_divide(machine_int_t num, machine_int_t denom) { - machine_int_t lsign = num > 0 ? 1 : -1; - machine_int_t rsign = denom > 0 ? 1 : -1; +mp_int_t mp_small_int_floor_divide(mp_int_t num, mp_int_t denom) { + mp_int_t lsign = num > 0 ? 1 : -1; + mp_int_t rsign = denom > 0 ? 1 : -1; if (lsign == -1) {num *= -1;} if (rsign == -1) {denom *= -1;} if (lsign != rsign){ diff --git a/py/smallint.h b/py/smallint.h index 36b55f919715..26a12874ef58 100644 --- a/py/smallint.h +++ b/py/smallint.h @@ -27,10 +27,10 @@ // Functions for small integer arithmetic // In SMALL_INT, next-to-highest bits is used as sign, so both must match for value in range -#define MP_SMALL_INT_MIN ((mp_small_int_t)(((machine_int_t)WORD_MSBIT_HIGH) >> 1)) -#define MP_SMALL_INT_MAX ((mp_small_int_t)(~(MP_SMALL_INT_MIN))) +#define MP_SMALL_INT_MIN ((mp_int_t)(((mp_int_t)WORD_MSBIT_HIGH) >> 1)) +#define MP_SMALL_INT_MAX ((mp_int_t)(~(MP_SMALL_INT_MIN))) #define MP_SMALL_INT_FITS(n) ((((n) ^ ((n) << 1)) & WORD_MSBIT_HIGH) == 0) -bool mp_small_int_mul_overflow(machine_int_t x, machine_int_t y); -machine_int_t mp_small_int_modulo(machine_int_t dividend, machine_int_t divisor); -machine_int_t mp_small_int_floor_divide(machine_int_t num, machine_int_t denom); +bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y); +mp_int_t mp_small_int_modulo(mp_int_t dividend, mp_int_t divisor); +mp_int_t mp_small_int_floor_divide(mp_int_t num, mp_int_t denom); diff --git a/py/stream.c b/py/stream.c index cfdea15cca96..98f62518a5b0 100644 --- a/py/stream.c +++ b/py/stream.c @@ -67,7 +67,7 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported")); } - machine_int_t sz; + mp_int_t sz; if (n_args == 1 || ((sz = mp_obj_get_int(args[1])) == -1)) { return stream_readall(args[0]); } @@ -80,7 +80,7 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) { byte *buf = m_new(byte, sz); int error; - machine_int_t out_sz = o->type->stream_p->read(o, buf, sz, &error); + mp_int_t out_sz = o->type->stream_p->read(o, buf, sz, &error); if (out_sz == -1) { if (is_nonblocking_error(error)) { // https://docs.python.org/3.4/library/io.html#io.RawIOBase.read @@ -109,7 +109,7 @@ STATIC mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) { mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); int error; - machine_int_t out_sz = o->type->stream_p->write(self_in, bufinfo.buf, bufinfo.len, &error); + mp_int_t out_sz = o->type->stream_p->write(self_in, bufinfo.buf, bufinfo.len, &error); if (out_sz == -1) { if (is_nonblocking_error(error)) { // http://docs.python.org/3/library/io.html#io.RawIOBase.write @@ -139,7 +139,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) { int error; int current_read = DEFAULT_BUFFER_SIZE; while (true) { - machine_int_t out_sz = o->type->stream_p->read(self_in, p, current_read, &error); + mp_int_t out_sz = o->type->stream_p->read(self_in, p, current_read, &error); if (out_sz == -1) { if (is_nonblocking_error(error)) { // With non-blocking streams, we read as much as we can. @@ -182,7 +182,7 @@ STATIC mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported")); } - machine_int_t max_size = -1; + mp_int_t max_size = -1; if (n_args > 1) { max_size = MP_OBJ_SMALL_INT_VALUE(args[1]); } @@ -201,7 +201,7 @@ STATIC mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError, "out of memory")); } - machine_int_t out_sz = o->type->stream_p->read(o, p, 1, &error); + mp_int_t out_sz = o->type->stream_p->read(o, p, 1, &error); if (out_sz == -1) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error)); } diff --git a/py/unicode.c b/py/unicode.c index d69e81c8e057..17d3c7265051 100644 --- a/py/unicode.c +++ b/py/unicode.c @@ -96,8 +96,8 @@ const byte *utf8_next_char(const byte *s) { #endif } -machine_uint_t utf8_ptr_to_index(const char *s, const char *ptr) { - machine_uint_t i = 0; +mp_uint_t utf8_ptr_to_index(const char *s, const char *ptr) { + mp_uint_t i = 0; while (ptr > s) { if (!UTF8_IS_CONT(*--ptr)) { i++; @@ -108,10 +108,10 @@ machine_uint_t utf8_ptr_to_index(const char *s, const char *ptr) { } // TODO: Rename to str_charlen -machine_uint_t unichar_charlen(const char *str, machine_uint_t len) +mp_uint_t unichar_charlen(const char *str, mp_uint_t len) { #if MICROPY_PY_BUILTINS_STR_UNICODE - machine_uint_t charlen = 0; + mp_uint_t charlen = 0; for (const char *top = str + len; str < top; ++str) { if (!UTF8_IS_CONT(*str)) { ++charlen; diff --git a/py/unicode.h b/py/unicode.h index 2468b2fecf3c..283a7d044da2 100644 --- a/py/unicode.h +++ b/py/unicode.h @@ -1 +1 @@ -machine_uint_t utf8_ptr_to_index(const byte *s, const byte *ptr); +mp_uint_t utf8_ptr_to_index(const byte *s, const byte *ptr); diff --git a/py/vm.c b/py/vm.c index 42709889cdd2..ade2ee2b5a5e 100644 --- a/py/vm.c +++ b/py/vm.c @@ -74,9 +74,9 @@ typedef enum { qst = (qst << 7) + (*ip & 0x7f); \ } while ((*ip++ & 0x80) != 0) #define DECODE_PTR do { \ - ip = (byte*)(((machine_uint_t)ip + sizeof(machine_uint_t) - 1) & (~(sizeof(machine_uint_t) - 1))); /* align ip */ \ - unum = *(machine_uint_t*)ip; \ - ip += sizeof(machine_uint_t); \ + ip = (byte*)(((mp_uint_t)ip + sizeof(mp_uint_t) - 1) & (~(sizeof(mp_uint_t) - 1))); /* align ip */ \ + unum = *(mp_uint_t*)ip; \ + ip += sizeof(mp_uint_t); \ } while (0) #define PUSH(val) *++sp = (val) #define POP() (*sp--) @@ -140,7 +140,7 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o // local variables that are not visible to the exception handler const byte *ip = code_state->ip; mp_obj_t *sp = code_state->sp; - machine_uint_t unum; + mp_uint_t unum; mp_obj_t obj_shared; // If we have exception to inject, now that we finish setting up @@ -183,7 +183,7 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o DISPATCH(); ENTRY(MP_BC_LOAD_CONST_SMALL_INT): { - machine_int_t num = 0; + mp_int_t num = 0; if ((ip[0] & 0x40) != 0) { // Number is negative num--; @@ -503,9 +503,9 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o ENTRY(MP_BC_UNWIND_JUMP): DECODE_SLABEL; PUSH((void*)(ip + unum)); // push destination ip for jump - PUSH((void*)(machine_uint_t)(*ip)); // push number of exception handlers to unwind (0x80 bit set if we also need to pop stack) + PUSH((void*)(mp_uint_t)(*ip)); // push number of exception handlers to unwind (0x80 bit set if we also need to pop stack) unwind_jump: - unum = (machine_uint_t)POP(); // get number of exception handlers to unwind + unum = (mp_uint_t)POP(); // get number of exception handlers to unwind while ((unum & 0x7f) > 0) { unum -= 1; assert(exc_sp >= exc_stack); @@ -713,7 +713,7 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o ENTRY(MP_BC_MAKE_CLOSURE): { DECODE_PTR; - machine_uint_t n_closed_over = *ip++; + mp_uint_t n_closed_over = *ip++; // Stack layout: closed_overs <- TOS sp -= n_closed_over - 1; SET_TOP(mp_make_closure_from_raw_code((mp_raw_code_t*)unum, n_closed_over, sp)); @@ -722,7 +722,7 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o ENTRY(MP_BC_MAKE_CLOSURE_DEFARGS): { DECODE_PTR; - machine_uint_t n_closed_over = *ip++; + mp_uint_t n_closed_over = *ip++; // Stack layout: def_tuple def_dict closed_overs <- TOS sp -= 2 + n_closed_over - 1; SET_TOP(mp_make_closure_from_raw_code((mp_raw_code_t*)unum, 0x100 | n_closed_over, sp)); @@ -909,7 +909,7 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o // check if it's a StopIteration within a for block if (*code_state->ip == MP_BC_FOR_ITER && mp_obj_is_subclass_fast(mp_obj_get_type(nlr.ret_val), &mp_type_StopIteration)) { const byte *ip = code_state->ip + 1; - machine_uint_t unum; + mp_uint_t unum; DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward code_state->ip = ip + unum; // jump to after for-block code_state->sp -= 1; // pop the exhausted iterator @@ -922,11 +922,11 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o // TODO need a better way of not adding traceback to constant objects (right now, just GeneratorExit_obj and MemoryError_obj) if (mp_obj_is_exception_instance(nlr.ret_val) && nlr.ret_val != &mp_const_GeneratorExit_obj && nlr.ret_val != &mp_const_MemoryError_obj) { const byte *code_info = code_state->code_info; - machine_uint_t code_info_size = code_info[0] | (code_info[1] << 8) | (code_info[2] << 16) | (code_info[3] << 24); + mp_uint_t code_info_size = code_info[0] | (code_info[1] << 8) | (code_info[2] << 16) | (code_info[3] << 24); qstr source_file = code_info[4] | (code_info[5] << 8) | (code_info[6] << 16) | (code_info[7] << 24); qstr block_name = code_info[8] | (code_info[9] << 8) | (code_info[10] << 16) | (code_info[11] << 24); - machine_uint_t source_line = 0; - machine_uint_t bc = code_state->ip - code_info - code_info_size; + mp_uint_t source_line = 0; + mp_uint_t bc = code_state->ip - code_info - code_info_size; //printf("find %lu %d %d\n", bc, code_info[12], code_info[13]); const byte* ci = code_info + 12; if (*ci) { diff --git a/qemu-arm/mpconfigport.h b/qemu-arm/mpconfigport.h index e2c625ce29b7..3fde1aa20392 100644 --- a/qemu-arm/mpconfigport.h +++ b/qemu-arm/mpconfigport.h @@ -23,8 +23,8 @@ #define UINT_FMT "%lu" #define INT_FMT "%ld" -typedef int32_t machine_int_t; // must be pointer size -typedef uint32_t machine_uint_t; // must be pointer size +typedef int32_t mp_int_t; // must be pointer size +typedef uint32_t mp_uint_t; // must be pointer size typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size diff --git a/stmhal/dac.c b/stmhal/dac.c index 725e14e90670..df46d2490451 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -97,7 +97,7 @@ typedef struct _pyb_dac_obj_t { mp_obj_base_t base; uint32_t dac_channel; // DAC_CHANNEL_1 or DAC_CHANNEL_2 DMA_Stream_TypeDef *dma_stream; // DMA1_Stream5 or DMA1_Stream6 - machine_uint_t state; + mp_uint_t state; } pyb_dac_obj_t; // create the dac object @@ -114,7 +114,7 @@ STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const pyb_dac_obj_t *dac = m_new_obj(pyb_dac_obj_t); dac->base.type = &pyb_dac_type; - machine_int_t dac_id = mp_obj_get_int(args[0]); + mp_int_t dac_id = mp_obj_get_int(args[0]); uint32_t pin; if (dac_id == 1) { pin = GPIO_PIN_4; diff --git a/stmhal/extint.c b/stmhal/extint.c index 591246cdd1d6..d2eace57453e 100644 --- a/stmhal/extint.c +++ b/stmhal/extint.c @@ -101,14 +101,14 @@ #define EXTI_SWIER_BB(line) (*(__IO uint32_t *)(PERIPH_BB_BASE + ((EXTI_OFFSET + offsetof(EXTI_TypeDef, SWIER)) * 32) + ((line) * 4))) typedef struct { - mp_obj_base_t base; - mp_small_int_t line; + mp_obj_base_t base; + mp_int_t line; } extint_obj_t; typedef struct { - mp_obj_t callback_obj; - void *param; - uint32_t mode; + mp_obj_t callback_obj; + void *param; + uint32_t mode; } extint_vector_t; STATIC extint_vector_t extint_vector[EXTI_NUM_VECTORS]; diff --git a/stmhal/file.c b/stmhal/file.c index 079ab3965b94..2d33a8f7b464 100644 --- a/stmhal/file.c +++ b/stmhal/file.c @@ -73,7 +73,7 @@ void file_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, m print(env, "", mp_obj_get_type_str(self_in), self_in); } -STATIC machine_int_t file_obj_read(mp_obj_t self_in, void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { pyb_file_obj_t *self = self_in; UINT sz_out; FRESULT res = f_read(&self->fp, buf, size, &sz_out); @@ -84,7 +84,7 @@ STATIC machine_int_t file_obj_read(mp_obj_t self_in, void *buf, machine_uint_t s return sz_out; } -STATIC machine_int_t file_obj_write(mp_obj_t self_in, const void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_file_obj_t *self = self_in; UINT sz_out; FRESULT res = f_write(&self->fp, buf, size, &sz_out); @@ -109,8 +109,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(file_obj___exit___obj, 4, 4, file_obj mp_obj_t file_obj_seek(uint n_args, const mp_obj_t *args) { pyb_file_obj_t *self = args[0]; - machine_int_t offset = mp_obj_get_int(args[1]); - machine_int_t whence = 0; + mp_int_t offset = mp_obj_get_int(args[1]); + mp_int_t whence = 0; if (n_args == 3) { whence = mp_obj_get_int(args[2]); } @@ -199,7 +199,7 @@ STATIC mp_obj_t file_obj_make_new(mp_obj_t type, uint n_args, uint n_kw, const m FRESULT res = f_open(&o->fp, fname, mode); if (res != FR_OK) { m_del_obj(pyb_file_obj_t, o); - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)fresult_to_errno_table[res]))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)fresult_to_errno_table[res]))); } // for 'a' mode, we must begin at the end of the file diff --git a/stmhal/gccollect.c b/stmhal/gccollect.c index c71ed13a5e45..e79dc38494bf 100644 --- a/stmhal/gccollect.c +++ b/stmhal/gccollect.c @@ -35,10 +35,10 @@ #include "gccollect.h" #include MICROPY_HAL_H -machine_uint_t gc_helper_get_regs_and_sp(machine_uint_t *regs); +mp_uint_t gc_helper_get_regs_and_sp(mp_uint_t *regs); // obsolete -// void gc_helper_get_regs_and_clean_stack(machine_uint_t *regs, machine_uint_t heap_end); +// void gc_helper_get_regs_and_clean_stack(mp_uint_t *regs, mp_uint_t heap_end); void gc_collect(void) { // get current time, in case we want to time the GC @@ -52,8 +52,8 @@ void gc_collect(void) { gc_collect_root((void**)&_sbss, ((uint32_t)&_ebss - (uint32_t)&_sbss) / sizeof(uint32_t)); // get the registers and the sp - machine_uint_t regs[10]; - machine_uint_t sp = gc_helper_get_regs_and_sp(regs); + mp_uint_t regs[10]; + mp_uint_t sp = gc_helper_get_regs_and_sp(regs); // trace the stack, including the registers (since they live on the stack in this function) gc_collect_root((void**)sp, ((uint32_t)&_ram_end - sp) / sizeof(uint32_t)); diff --git a/stmhal/i2c.c b/stmhal/i2c.c index b6ab531293ab..9a616c6d62de 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -268,7 +268,7 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // get i2c number - machine_int_t i2c_id = mp_obj_get_int(args[0]) - 1; + mp_int_t i2c_id = mp_obj_get_int(args[0]) - 1; // check i2c number if (!(0 <= i2c_id && i2c_id < MP_ARRAY_SIZE(pyb_i2c_obj) && pyb_i2c_obj[i2c_id].i2c != NULL)) { @@ -311,7 +311,7 @@ STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) { nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master")); } - machine_uint_t i2c_addr = mp_obj_get_int(i2c_addr_o) << 1; + mp_uint_t i2c_addr = mp_obj_get_int(i2c_addr_o) << 1; for (int i = 0; i < 10; i++) { HAL_StatusTypeDef status = HAL_I2C_IsDeviceReady(self->i2c, i2c_addr, 10, 200); @@ -383,7 +383,7 @@ STATIC mp_obj_t pyb_i2c_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg if (vals[1].u_int == PYB_I2C_MASTER_ADDRESS) { nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "addr argument required")); } - machine_uint_t i2c_addr = vals[1].u_int << 1; + mp_uint_t i2c_addr = vals[1].u_int << 1; status = HAL_I2C_Master_Transmit(self->i2c, i2c_addr, bufinfo.buf, bufinfo.len, vals[2].u_int); } else { status = HAL_I2C_Slave_Transmit(self->i2c, bufinfo.buf, bufinfo.len, vals[2].u_int); @@ -433,7 +433,7 @@ STATIC mp_obj_t pyb_i2c_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg if (vals[1].u_int == PYB_I2C_MASTER_ADDRESS) { nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "addr argument required")); } - machine_uint_t i2c_addr = vals[1].u_int << 1; + mp_uint_t i2c_addr = vals[1].u_int << 1; status = HAL_I2C_Master_Receive(self->i2c, i2c_addr, bufinfo.buf, bufinfo.len, vals[2].u_int); } else { status = HAL_I2C_Slave_Receive(self->i2c, bufinfo.buf, bufinfo.len, vals[2].u_int); @@ -488,8 +488,8 @@ STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args, mp_map_t *kw mp_obj_t o_ret = pyb_buf_get_for_recv(vals[0].u_obj, &bufinfo); // get the addresses - machine_uint_t i2c_addr = vals[1].u_int << 1; - machine_uint_t mem_addr = vals[2].u_int; + mp_uint_t i2c_addr = vals[1].u_int << 1; + mp_uint_t mem_addr = vals[2].u_int; HAL_StatusTypeDef status = HAL_I2C_Mem_Read(self->i2c, i2c_addr, mem_addr, I2C_MEMADD_SIZE_8BIT, bufinfo.buf, bufinfo.len, vals[3].u_int); @@ -535,8 +535,8 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args, mp_map_t *k pyb_buf_get_for_send(vals[0].u_obj, &bufinfo, data); // get the addresses - machine_uint_t i2c_addr = vals[1].u_int << 1; - machine_uint_t mem_addr = vals[2].u_int; + mp_uint_t i2c_addr = vals[1].u_int << 1; + mp_uint_t mem_addr = vals[2].u_int; HAL_StatusTypeDef status = HAL_I2C_Mem_Write(self->i2c, i2c_addr, mem_addr, I2C_MEMADD_SIZE_8BIT, bufinfo.buf, bufinfo.len, vals[3].u_int); diff --git a/stmhal/led.c b/stmhal/led.c index c1b298b17928..51eaeb488569 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -45,7 +45,7 @@ typedef struct _pyb_led_obj_t { mp_obj_base_t base; - machine_uint_t led_id; + mp_uint_t led_id; const pin_obj_t *led_pin; } pyb_led_obj_t; @@ -160,7 +160,7 @@ int led_get_intensity(pyb_led_t led) { #if defined(PYBV4) || defined(PYBV10) if (led == 4) { - machine_uint_t i = (TIM3->CCR1 * 255 + (USBD_CDC_POLLING_INTERVAL*1000) - 2) / ((USBD_CDC_POLLING_INTERVAL*1000) - 1); + mp_uint_t i = (TIM3->CCR1 * 255 + (USBD_CDC_POLLING_INTERVAL*1000) - 2) / ((USBD_CDC_POLLING_INTERVAL*1000) - 1); if (i > 255) { i = 255; } @@ -181,7 +181,7 @@ int led_get_intensity(pyb_led_t led) { } } -void led_set_intensity(pyb_led_t led, machine_int_t intensity) { +void led_set_intensity(pyb_led_t led, mp_int_t intensity) { #if defined(PYBV4) || defined(PYBV10) if (led == 4) { // set intensity using PWM pulse width @@ -226,7 +226,7 @@ STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_arg_check_num(n_args, n_kw, 1, 1, false); // get led number - machine_int_t led_id = mp_obj_get_int(args[0]); + mp_int_t led_id = mp_obj_get_int(args[0]); // check led number if (!(1 <= led_id && led_id <= NUM_LEDS)) { diff --git a/stmhal/modos.c b/stmhal/modos.c index e0df05ca6b79..dd6fd67ec9d3 100644 --- a/stmhal/modos.c +++ b/stmhal/modos.c @@ -162,7 +162,7 @@ STATIC mp_obj_t os_sync(void) { MP_DEFINE_CONST_FUN_OBJ_0(os_sync_obj, os_sync); STATIC mp_obj_t os_urandom(mp_obj_t num) { - machine_int_t n = mp_obj_get_int(num); + mp_int_t n = mp_obj_get_int(num); byte *data; mp_obj_t o = mp_obj_str_builder_start(&mp_type_bytes, n, &data); for (int i = 0; i < n; i++) { diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c index 9dcd0e76caf9..8b594332b725 100644 --- a/stmhal/modpyb.c +++ b/stmhal/modpyb.c @@ -194,7 +194,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis); /// \function delay(ms) /// Delay for the given number of milliseconds. STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) { - machine_int_t ms = mp_obj_get_int(ms_in); + mp_int_t ms = mp_obj_get_int(ms_in); if (ms >= 0) { HAL_Delay(ms); } @@ -205,7 +205,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay); /// \function udelay(us) /// Delay for the given number of microseconds. STATIC mp_obj_t pyb_udelay(mp_obj_t usec_in) { - machine_int_t usec = mp_obj_get_int(usec_in); + mp_int_t usec = mp_obj_get_int(usec_in); if (usec > 0) { uint32_t count = 0; const uint32_t utime = (168 * usec / 4); diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 28e654c8a639..00afa989ccca 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -84,8 +84,8 @@ extern const struct _mp_obj_module_t time_module; #define UINT_FMT "%u" #define INT_FMT "%d" -typedef int machine_int_t; // must be pointer size -typedef unsigned int machine_uint_t; // must be pointer size +typedef int mp_int_t; // must be pointer size +typedef unsigned int mp_uint_t; // must be pointer size typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size diff --git a/stmhal/pin.c b/stmhal/pin.c index a9ebfa97668b..56f179f40c09 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -352,7 +352,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name); /// Get the pin port. STATIC mp_obj_t pin_port(mp_obj_t self_in) { pin_obj_t *self = self_in; - return MP_OBJ_NEW_SMALL_INT((mp_small_int_t)self->port); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->port); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port); @@ -360,7 +360,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port); /// Get the pin number. STATIC mp_obj_t pin_pin(mp_obj_t self_in) { pin_obj_t *self = self_in; - return MP_OBJ_NEW_SMALL_INT((mp_small_int_t)self->pin); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->pin); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin); diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c index 5447a6220209..2a4386e097ec 100644 --- a/stmhal/pybstdio.c +++ b/stmhal/pybstdio.c @@ -99,7 +99,7 @@ void stdio_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, print(env, "", self->fd); } -STATIC machine_int_t stdio_read(mp_obj_t self_in, void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { pyb_stdio_obj_t *self = self_in; if (self->fd == STDIO_FD_IN) { for (uint i = 0; i < size; i++) { @@ -117,7 +117,7 @@ STATIC machine_int_t stdio_read(mp_obj_t self_in, void *buf, machine_uint_t size } } -STATIC machine_int_t stdio_write(mp_obj_t self_in, const void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_stdio_obj_t *self = self_in; if (self->fd == STDIO_FD_OUT || self->fd == STDIO_FD_ERR) { stdout_tx_strn(buf, size); diff --git a/stmhal/rtc.c b/stmhal/rtc.c index 8f0d0073273f..9cc9268763d7 100644 --- a/stmhal/rtc.c +++ b/stmhal/rtc.c @@ -51,7 +51,7 @@ RTC_HandleTypeDef RTCHandle; // rtc_info indicates various things about RTC startup // it's a bit of a hack at the moment -static machine_uint_t rtc_info; +static mp_uint_t rtc_info; // Note: LSI is around (32KHz), these dividers should work either way // ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1) @@ -90,7 +90,7 @@ void rtc_init(void) { RCC_LSEConfig(RCC_LSE_ON); // Wait till LSE is ready - machine_uint_t sys_tick = sys_tick_counter; + mp_uint_t sys_tick = sys_tick_counter; while((RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (--timeout > 0)) { } @@ -181,7 +181,7 @@ void rtc_init(void) { RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; - machine_uint_t tick = HAL_GetTick(); + mp_uint_t tick = HAL_GetTick(); if (HAL_RTC_Init(&RTCHandle) != HAL_OK) { // init error diff --git a/stmhal/servo.c b/stmhal/servo.c index 3da445fa8db9..8cd0a4ef76d6 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -194,7 +194,7 @@ STATIC mp_obj_t pyb_servo_make_new(mp_obj_t type_in, uint n_args, uint n_kw, con mp_arg_check_num(n_args, n_kw, 1, 1, false); // get servo number - machine_int_t servo_id = mp_obj_get_int(args[0]) - 1; + mp_int_t servo_id = mp_obj_get_int(args[0]) - 1; // check servo number if (!(0 <= servo_id && servo_id < PYB_SERVO_NUM)) { diff --git a/stmhal/spi.c b/stmhal/spi.c index 448b8696ea76..52f80ce29258 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -314,7 +314,7 @@ STATIC mp_obj_t pyb_spi_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // get SPI number - machine_int_t spi_id = mp_obj_get_int(args[0]) - 1; + mp_int_t spi_id = mp_obj_get_int(args[0]) - 1; // check SPI number if (!(0 <= spi_id && spi_id < PYB_NUM_SPI && pyb_spi_obj[spi_id].spi != NULL)) { diff --git a/stmhal/timer.c b/stmhal/timer.c index 73842e4b1ded..30bcf2c0796d 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -90,7 +90,7 @@ typedef struct _pyb_timer_obj_t { mp_obj_base_t base; - machine_uint_t tim_id; + mp_uint_t tim_id; mp_obj_t callback; TIM_HandleTypeDef tim; IRQn_Type irqn; diff --git a/stmhal/uart.c b/stmhal/uart.c index a85f7f9e3aec..9436c2938b04 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -289,7 +289,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, uint n_args, const mp if (vals[3].u_obj == mp_const_none) { init->Parity = UART_PARITY_NONE; } else { - machine_int_t parity = mp_obj_get_int(vals[3].u_obj); + mp_int_t parity = mp_obj_get_int(vals[3].u_obj); init->Parity = (parity & 1) ? UART_PARITY_ODD : UART_PARITY_EVEN; } init->Mode = UART_MODE_TX_RX; diff --git a/teensy/led.c b/teensy/led.c index 5a9d8701d23a..999ca98071b2 100644 --- a/teensy/led.c +++ b/teensy/led.c @@ -15,7 +15,7 @@ typedef struct _pyb_led_obj_t { mp_obj_base_t base; - machine_uint_t led_id; + mp_uint_t led_id; const pin_obj_t *led_pin; } pyb_led_obj_t; @@ -98,7 +98,7 @@ STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_arg_check_num(n_args, n_kw, 1, 1, false); // get led number - machine_int_t led_id = mp_obj_get_int(args[0]); + mp_int_t led_id = mp_obj_get_int(args[0]); // check led number if (!(1 <= led_id && led_id <= NUM_LEDS)) { diff --git a/teensy/main.c b/teensy/main.c index 97c1db652817..5e7918cdc6c0 100644 --- a/teensy/main.c +++ b/teensy/main.c @@ -150,7 +150,7 @@ static mp_obj_t pyb_info(void) { #if 0 -void gc_helper_get_regs_and_clean_stack(machine_uint_t *regs, machine_uint_t heap_end); +void gc_helper_get_regs_and_clean_stack(mp_uint_t *regs, mp_uint_t heap_end); mp_obj_t pyb_gc(void) { gc_collect(); diff --git a/teensy/modpyb.c b/teensy/modpyb.c index 0240395dc7ab..435b198d0b20 100644 --- a/teensy/modpyb.c +++ b/teensy/modpyb.c @@ -164,7 +164,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis); /// \function delay(ms) /// Delay for the given number of milliseconds. STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) { - machine_int_t ms = mp_obj_get_int(ms_in); + mp_int_t ms = mp_obj_get_int(ms_in); if (ms >= 0) { HAL_Delay(ms); } @@ -175,7 +175,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay); /// \function udelay(us) /// Delay for the given number of microseconds. STATIC mp_obj_t pyb_udelay(mp_obj_t usec_in) { - machine_int_t usec = mp_obj_get_int(usec_in); + mp_int_t usec = mp_obj_get_int(usec_in); delayMicroseconds(usec); return mp_const_none; } diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h index ff0a31f27269..108b230dfde8 100644 --- a/teensy/mpconfigport.h +++ b/teensy/mpconfigport.h @@ -46,8 +46,8 @@ extern const struct _mp_obj_module_t time_module; #define UINT_FMT "%u" #define INT_FMT "%d" -typedef int32_t machine_int_t; // must be pointer size -typedef unsigned int machine_uint_t; // must be pointer size +typedef int32_t mp_int_t; // must be pointer size +typedef unsigned int mp_uint_t; // must be pointer size typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size diff --git a/teensy/uart.c b/teensy/uart.c index 97a1a058c915..e3a35153bc52 100644 --- a/teensy/uart.c +++ b/teensy/uart.c @@ -309,7 +309,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, uint n_args, const mp if (vals[3].u_obj == mp_const_none) { init->Parity = UART_PARITY_NONE; } else { - machine_int_t parity = mp_obj_get_int(vals[3].u_obj); + mp_int_t parity = mp_obj_get_int(vals[3].u_obj); init->Parity = (parity & 1) ? UART_PARITY_ODD : UART_PARITY_EVEN; } init->Mode = UART_MODE_TX_RX; diff --git a/unix-cpy/mpconfigport.h b/unix-cpy/mpconfigport.h index a4b5cc0879eb..4d1deb87931d 100644 --- a/unix-cpy/mpconfigport.h +++ b/unix-cpy/mpconfigport.h @@ -34,16 +34,16 @@ // type definitions for the specific machine #ifdef __LP64__ -typedef long machine_int_t; // must be pointer size -typedef unsigned long machine_uint_t; // must be pointer size +typedef long mp_int_t; // must be pointer size +typedef unsigned long mp_uint_t; // must be pointer size #else // These are definitions for machines where sizeof(int) == sizeof(void*), // regardless for actual size. -typedef int machine_int_t; // must be pointer size -typedef unsigned int machine_uint_t; // must be pointer size +typedef int mp_int_t; // must be pointer size +typedef unsigned int mp_uint_t; // must be pointer size #endif -#define BYTES_PER_WORD sizeof(machine_int_t) +#define BYTES_PER_WORD sizeof(mp_int_t) typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size diff --git a/unix/file.c b/unix/file.c index 386f018bdddd..62e3253b7da5 100644 --- a/unix/file.c +++ b/unix/file.c @@ -62,20 +62,20 @@ STATIC void fdfile_print(void (*print)(void *env, const char *fmt, ...), void *e print(env, "", mp_obj_get_type_str(self), self->fd); } -STATIC machine_int_t fdfile_read(mp_obj_t o_in, void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t fdfile_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_fdfile_t *o = o_in; check_fd_is_open(o); - machine_int_t r = read(o->fd, buf, size); + mp_int_t r = read(o->fd, buf, size); if (r == -1) { *errcode = errno; } return r; } -STATIC machine_int_t fdfile_write(mp_obj_t o_in, const void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t fdfile_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_fdfile_t *o = o_in; check_fd_is_open(o); - machine_int_t r = write(o->fd, buf, size); + mp_int_t r = write(o->fd, buf, size); if (r == -1) { *errcode = errno; } @@ -100,7 +100,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fdfile___exit___obj, 4, 4, fdfile___e STATIC mp_obj_t fdfile_fileno(mp_obj_t self_in) { mp_obj_fdfile_t *self = self_in; check_fd_is_open(self); - return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->fd); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->fd); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_fileno_obj, fdfile_fileno); @@ -153,7 +153,7 @@ STATIC mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const const char *fname = mp_obj_str_get_str(args[0]); int fd = open(fname, mode, 0644); if (fd == -1) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)errno))); } o->fd = fd; return o; diff --git a/unix/gccollect.c b/unix/gccollect.c index d04e5d87fbe5..32b3d8bc61b6 100644 --- a/unix/gccollect.c +++ b/unix/gccollect.c @@ -50,7 +50,7 @@ void gc_helper_get_regs(regs_t arr) { // to capture caller-saved registers, because they, well, put on the // stack already by the caller. #ifdef __x86_64__ -typedef machine_uint_t regs_t[6]; +typedef mp_uint_t regs_t[6]; void gc_helper_get_regs(regs_t arr) { register long rbx asm ("rbx"); @@ -83,7 +83,7 @@ void gc_helper_get_regs(regs_t arr) { #endif #ifdef __i386__ -typedef machine_uint_t regs_t[4]; +typedef mp_uint_t regs_t[4]; void gc_helper_get_regs(regs_t arr) { register long ebx asm ("ebx"); @@ -98,7 +98,7 @@ void gc_helper_get_regs(regs_t arr) { #endif #if defined(__thumb2__) || defined(__thumb__) || defined(__arm__) -typedef machine_uint_t regs_t[10]; +typedef mp_uint_t regs_t[10]; void gc_helper_get_regs(regs_t arr) { register long r4 asm ("r4"); @@ -140,12 +140,12 @@ void gc_collect(void) { #endif extern char BSS_START, _end; //printf(".bss: %p-%p\n", &BSS_START, &_end); - gc_collect_root((void**)&BSS_START, ((machine_uint_t)&_end - (machine_uint_t)&BSS_START) / sizeof(machine_uint_t)); + gc_collect_root((void**)&BSS_START, ((mp_uint_t)&_end - (mp_uint_t)&BSS_START) / sizeof(mp_uint_t)); regs_t regs; gc_helper_get_regs(regs); // GC stack (and regs because we captured them) void **regs_ptr = (void**)(void*)®s; - gc_collect_root(regs_ptr, ((machine_uint_t)stack_top - (machine_uint_t)®s) / sizeof(machine_uint_t)); + gc_collect_root(regs_ptr, ((mp_uint_t)stack_top - (mp_uint_t)®s) / sizeof(mp_uint_t)); gc_collect_end(); //printf("-----\n"); diff --git a/unix/main.c b/unix/main.c index 176cbc6ec332..d0222de0d1c8 100644 --- a/unix/main.c +++ b/unix/main.c @@ -61,7 +61,7 @@ uint mp_verbose_flag; #if MICROPY_ENABLE_GC // Heap size of GC heap (if enabled) // Make it larger on a 64 bit machine, because pointers are larger. -long heap_size = 128*1024 * (sizeof(machine_uint_t) / 4); +long heap_size = 128*1024 * (sizeof(mp_uint_t) / 4); #endif void microsocket_init(); diff --git a/unix/modffi.c b/unix/modffi.c index eca3f9131bff..796dec41995f 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -179,7 +179,7 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) { void *sym = dlsym(self->handle, symname); if (sym == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)errno))); } int nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[3])); mp_obj_ffifunc_t *o = m_new_obj_var(mp_obj_ffifunc_t, ffi_type*, nparams); @@ -253,7 +253,7 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna void *sym = dlsym(self->handle, symname); if (sym == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)errno))); } mp_obj_ffivar_t *o = m_new_obj(mp_obj_ffivar_t); o->base.type = &ffivar_type; @@ -269,7 +269,7 @@ STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const void *mod = dlopen(fname, RTLD_NOW | RTLD_LOCAL); if (mod == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)errno))); } mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t); o->base.type = type_in; diff --git a/unix/modos.c b/unix/modos.c index 9b034cdbc245..7ff3fbbb89f8 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -40,7 +40,7 @@ #define RAISE_ERRNO(err_flag, error_val) \ { if (err_flag == -1) \ - { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)error_val))); } } + { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)error_val))); } } STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) { struct stat sb; @@ -51,12 +51,12 @@ STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) { RAISE_ERRNO(res, errno); mp_obj_tuple_t *t = mp_obj_new_tuple(10, NULL); - t->items[0] = MP_OBJ_NEW_SMALL_INT((machine_int_t)sb.st_mode); - t->items[1] = MP_OBJ_NEW_SMALL_INT((machine_int_t)sb.st_ino); - t->items[2] = MP_OBJ_NEW_SMALL_INT((machine_int_t)sb.st_dev); - t->items[3] = MP_OBJ_NEW_SMALL_INT((machine_int_t)sb.st_nlink); - t->items[4] = MP_OBJ_NEW_SMALL_INT((machine_int_t)sb.st_uid); - t->items[5] = MP_OBJ_NEW_SMALL_INT((machine_int_t)sb.st_gid); + t->items[0] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_mode); + t->items[1] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_ino); + t->items[2] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_dev); + t->items[3] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_nlink); + t->items[4] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_uid); + t->items[5] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_gid); t->items[6] = MP_OBJ_NEW_SMALL_INT(sb.st_size); t->items[7] = MP_OBJ_NEW_SMALL_INT(sb.st_atime); t->items[8] = MP_OBJ_NEW_SMALL_INT(sb.st_mtime); diff --git a/unix/modsocket.c b/unix/modsocket.c index 5b3fb0187728..160a1dcc02b7 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -76,7 +76,7 @@ STATIC const mp_obj_type_t microsocket_type; // Helper functions #define RAISE_ERRNO(err_flag, error_val) \ { if (err_flag == -1) \ - { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)error_val))); } } + { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)error_val))); } } STATIC mp_obj_socket_t *socket_new(int fd) { mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t); @@ -91,18 +91,18 @@ STATIC void socket_print(void (*print)(void *env, const char *fmt, ...), void *e print(env, "<_socket %d>", self->fd); } -STATIC machine_int_t socket_read(mp_obj_t o_in, void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_socket_t *o = o_in; - machine_int_t r = read(o->fd, buf, size); + mp_int_t r = read(o->fd, buf, size); if (r == -1) { *errcode = errno; } return r; } -STATIC machine_int_t socket_write(mp_obj_t o_in, const void *buf, machine_uint_t size, int *errcode) { +STATIC mp_int_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_socket_t *o = o_in; - machine_int_t r = write(o->fd, buf, size); + mp_int_t r = write(o->fd, buf, size); if (r == -1) { *errcode = errno; } @@ -118,7 +118,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close); STATIC mp_obj_t socket_fileno(mp_obj_t self_in) { mp_obj_socket_t *self = self_in; - return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->fd); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->fd); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno); @@ -203,7 +203,7 @@ STATIC mp_obj_t socket_send(uint n_args, const mp_obj_t *args) { int out_sz = send(self->fd, bufinfo.buf, bufinfo.len, flags); RAISE_ERRNO(out_sz, errno); - return MP_OBJ_NEW_SMALL_INT((machine_int_t)out_sz); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)out_sz); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send); @@ -253,7 +253,7 @@ STATIC mp_obj_t socket_makefile(uint n_args, const mp_obj_t *args) { mp_obj_socket_t *self = args[0]; mp_obj_t *new_args = alloca(n_args * sizeof(mp_obj_t)); memcpy(new_args + 1, args + 1, (n_args - 1) * sizeof(mp_obj_t)); - new_args[0] = MP_OBJ_NEW_SMALL_INT((machine_int_t)self->fd); + new_args[0] = MP_OBJ_NEW_SMALL_INT((mp_int_t)self->fd); return mp_builtin_open(n_args, new_args); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); @@ -319,7 +319,7 @@ STATIC const mp_obj_type_t microsocket_type = { #if MICROPY_SOCKET_EXTRA STATIC mp_obj_t mod_socket_htons(mp_obj_t arg) { - return MP_OBJ_NEW_SMALL_INT((machine_int_t)htons(MP_OBJ_SMALL_INT_VALUE(arg))); + return MP_OBJ_NEW_SMALL_INT((mp_int_t)htons(MP_OBJ_SMALL_INT_VALUE(arg))); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons); @@ -341,7 +341,7 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { struct hostent *h = gethostbyname(s); if (h == NULL) { // CPython: socket.herror - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((machine_int_t)h_errno))); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)h_errno))); } assert(h->h_length == 4); return mp_obj_new_int(*(int*)*h->h_addr_list); @@ -395,9 +395,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { mp_obj_t list = mp_obj_new_list(0, NULL); for (struct addrinfo *addr = addr_list; addr; addr = addr->ai_next) { mp_obj_tuple_t *t = mp_obj_new_tuple(5, NULL); - t->items[0] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_family); - t->items[1] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_socktype); - t->items[2] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_protocol); + t->items[0] = MP_OBJ_NEW_SMALL_INT((mp_int_t)addr->ai_family); + t->items[1] = MP_OBJ_NEW_SMALL_INT((mp_int_t)addr->ai_socktype); + t->items[2] = MP_OBJ_NEW_SMALL_INT((mp_int_t)addr->ai_protocol); // "canonname will be a string representing the canonical name of the host // if AI_CANONNAME is part of the flags argument; else canonname will be empty." ?? if (addr->ai_canonname) { diff --git a/unix/modtime.c b/unix/modtime.c index 286d8ea97ef7..15352735c6e1 100644 --- a/unix/modtime.c +++ b/unix/modtime.c @@ -68,7 +68,7 @@ STATIC mp_obj_t mod_time_time() { mp_float_t val = tv.tv_sec + (mp_float_t)tv.tv_usec / 1000000; return mp_obj_new_float(val); #else - return mp_obj_new_int((machine_int_t)time(NULL)); + return mp_obj_new_int((mp_int_t)time(NULL)); #endif } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time); @@ -81,7 +81,7 @@ STATIC mp_obj_t mod_time_clock() { // to preserve integer part resolution. return mp_obj_new_float((float)(clock() / 1000) / CLOCK_DIV); #else - return mp_obj_new_int((machine_int_t)clock()); + return mp_obj_new_int((mp_int_t)clock()); #endif } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 763b34ba3eb9..002ea79f9488 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -83,16 +83,16 @@ extern const struct _mp_obj_module_t mp_module_ffi; // type definitions for the specific machine #ifdef __LP64__ -typedef long machine_int_t; // must be pointer size -typedef unsigned long machine_uint_t; // must be pointer size +typedef long mp_int_t; // must be pointer size +typedef unsigned long mp_uint_t; // must be pointer size #else // These are definitions for machines where sizeof(int) == sizeof(void*), // regardless for actual size. -typedef int machine_int_t; // must be pointer size -typedef unsigned int machine_uint_t; // must be pointer size +typedef int mp_int_t; // must be pointer size +typedef unsigned int mp_uint_t; // must be pointer size #endif -#define BYTES_PER_WORD sizeof(machine_int_t) +#define BYTES_PER_WORD sizeof(mp_int_t) typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h index 963fcfe768ab..93b450dbbc1d 100644 --- a/windows/mpconfigport.h +++ b/windows/mpconfigport.h @@ -65,19 +65,19 @@ // type definitions for the specific machine #if defined( __MINGW32__ ) && defined( __LP64__ ) -typedef long machine_int_t; // must be pointer size -typedef unsigned long machine_uint_t; // must be pointer size +typedef long mp_int_t; // must be pointer size +typedef unsigned long mp_uint_t; // must be pointer size #elif defined ( _MSC_VER ) && defined( _WIN64 ) -typedef __int64 machine_int_t; -typedef unsigned __int64 machine_uint_t; +typedef __int64 mp_int_t; +typedef unsigned __int64 mp_uint_t; #else // These are definitions for machines where sizeof(int) == sizeof(void*), // regardless for actual size. -typedef int machine_int_t; // must be pointer size -typedef unsigned int machine_uint_t; // must be pointer size +typedef int mp_int_t; // must be pointer size +typedef unsigned int mp_uint_t; // must be pointer size #endif -#define BYTES_PER_WORD sizeof(machine_int_t) +#define BYTES_PER_WORD sizeof(mp_int_t) typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size