Commit 40f3c026 authored by Damien George's avatar Damien George
Browse files

Rename machine_(u)int_t to mp_(u)int_t.

See discussion in issue #50.
parent 065aba58
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
#define UINT_FMT "%lu" #define UINT_FMT "%lu"
#define INT_FMT "%ld" #define INT_FMT "%ld"
typedef int32_t machine_int_t; // must be pointer size typedef int32_t mp_int_t; // must be pointer size
typedef uint32_t machine_uint_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 void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size
......
...@@ -133,7 +133,7 @@ uint asm_thumb_get_code_size(asm_thumb_t *as) { ...@@ -133,7 +133,7 @@ uint asm_thumb_get_code_size(asm_thumb_t *as) {
void *asm_thumb_get_code(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 // 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) { ...@@ -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 // 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 // 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 ...@@ -499,7 +499,7 @@ void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp
if (0) { if (0) {
// load ptr to function into register using immediate, then branch // load ptr to function into register using immediate, then branch
// not relocatable // 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)); asm_thumb_op16(as, OP_BLX(reg_temp));
} else if (1) { } 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)); 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));
......
...@@ -185,7 +185,7 @@ void asm_thumb_ite_ge(asm_thumb_t *as); ...@@ -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_b_n(asm_thumb_t *as, uint label);
void asm_thumb_bcc_n(asm_thumb_t *as, int cond, 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_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_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 void asm_thumb_mov_local_reg(asm_thumb_t *as, int local_num_dest, uint rlo_src); // convenience
......
...@@ -55,6 +55,6 @@ void mp_bytecode_print(const void *descr, const byte *code, int len); ...@@ -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); void mp_bytecode_print2(const byte *code, int len);
// Helper macros to access pointer with least significant bit holding a flag // 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_PTR(x) ((void*)((mp_uint_t)(x) & ~((mp_uint_t)1)))
#define MP_TAGPTR_TAG(x) ((machine_uint_t)(x) & 1) #define MP_TAGPTR_TAG(x) ((mp_uint_t)(x) & 1)
#define MP_TAGPTR_MAKE(ptr, tag) ((void*)((machine_uint_t)(ptr) | tag)) #define MP_TAGPTR_MAKE(ptr, tag) ((void*)((mp_uint_t)(ptr) | tag))
...@@ -88,7 +88,7 @@ int mp_binary_get_size(char struct_type, char val_type, uint *palign) { ...@@ -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) { 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) { switch (typecode) {
case 'b': case 'b':
val = ((int8_t*)p)[index]; val = ((int8_t*)p)[index];
...@@ -125,7 +125,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, int 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); 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; int delta;
if (!big_endian) { if (!big_endian) {
delta = -1; delta = -1;
...@@ -134,7 +134,7 @@ machine_int_t mp_binary_get_int(uint size, bool is_signed, bool big_endian, byte ...@@ -134,7 +134,7 @@ machine_int_t mp_binary_get_int(uint size, bool is_signed, bool big_endian, byte
delta = 1; delta = 1;
} }
machine_int_t val = 0; mp_int_t val = 0;
if (is_signed && *p & 0x80) { if (is_signed && *p & 0x80) {
val = -1; val = -1;
} }
...@@ -155,7 +155,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) { ...@@ -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); int size = mp_binary_get_size(struct_type, val_type, &align);
if (struct_type == '@') { if (struct_type == '@') {
// Make pointer aligned // 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 #if MP_ENDIANNESS_LITTLE
struct_type = '<'; struct_type = '<';
#else #else
...@@ -164,7 +164,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) { ...@@ -164,7 +164,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
} }
*ptr = p + size; *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') { if (val_type == 'O') {
return (mp_obj_t)val; 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 ** ...@@ -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); int size = mp_binary_get_size(struct_type, val_type, &align);
if (struct_type == '@') { if (struct_type == '@') {
// Make pointer aligned // 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 #if MP_ENDIANNESS_LITTLE
struct_type = '<'; struct_type = '<';
#else #else
...@@ -196,7 +196,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte ** ...@@ -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 #if MP_ENDIANNESS_BIG
#error Not implemented #error Not implemented
#endif #endif
machine_int_t val; mp_int_t val;
byte *in = (byte*)&val; byte *in = (byte*)&val;
switch (val_type) { switch (val_type) {
case 'O': case 'O':
...@@ -239,7 +239,7 @@ void mp_binary_set_val_array(char typecode, void *p, int index, mp_obj_t val_in) ...@@ -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) { switch (typecode) {
case 'b': case 'b':
((int8_t*)p)[index] = val; ((int8_t*)p)[index] = val;
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
int mp_binary_get_size(char struct_type, char val_type, uint *palign); 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); 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(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); 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); 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);
...@@ -99,7 +99,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj, mp_builtin___repl_print ...@@ -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) { mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
if (MP_OBJ_IS_SMALL_INT(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) { if (val < 0) {
val = -val; val = -val;
} }
...@@ -173,7 +173,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable); ...@@ -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) { STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
#if MICROPY_PY_BUILTINS_STR_UNICODE #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]; char str[4];
int len = 0; int len = 0;
if (c < 0x80) { if (c < 0x80) {
...@@ -198,7 +198,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { ...@@ -198,7 +198,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
} }
return mp_obj_new_str(str, len, true); return mp_obj_new_str(str, len, true);
#else #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) { if (0 <= ord && ord <= 0x10ffff) {
char str[1] = {ord}; char str[1] = {ord};
return mp_obj_new_str(str, 1, true); 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); ...@@ -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) { 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)) { 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_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 i2 = MP_OBJ_SMALL_INT_VALUE(o2_in);
mp_obj_t args[2]; mp_obj_t args[2];
args[0] = MP_OBJ_NEW_SMALL_INT(i1 / i2); args[0] = MP_OBJ_NEW_SMALL_INT(i1 / i2);
args[1] = 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) { ...@@ -372,11 +372,11 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
uint len; uint len;
const char *str = mp_obj_str_get_data(o_in, &len); const char *str = mp_obj_str_get_data(o_in, &len);
#if MICROPY_PY_BUILTINS_STR_UNICODE #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 (charlen == 1) {
if (MP_OBJ_IS_STR(o_in) && UTF8_IS_NONASCII(*str)) { if (MP_OBJ_IS_STR(o_in) && UTF8_IS_NONASCII(*str)) {
machine_int_t ord = *str++ & 0x7F; mp_int_t ord = *str++ & 0x7F;
for (machine_int_t mask = 0x40; ord & mask; mask >>= 1) { for (mp_int_t mask = 0x40; ord & mask; mask >>= 1) {
ord &= ~mask; ord &= ~mask;
} }
while (UTF8_IS_CONT(*str)) { 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 ...@@ -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); 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) { 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); MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_id_obj, mp_builtin_id);
......
...@@ -95,7 +95,7 @@ typedef struct _compiler_t { ...@@ -95,7 +95,7 @@ typedef struct _compiler_t {
STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const char *msg) { 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 // TODO store the error message to a variable in compiler_t instead of printing it
if (MP_PARSE_NODE_IS_STRUCT(pn)) { 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 { } else {
printf(" File \"%s\"\n", qstr_str(comp->source_file)); 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 ...@@ -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"); compile_syntax_error(comp, (mp_parse_node_t)pns, "constant must be an integer");
break; 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 // 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); 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 ...@@ -200,8 +200,8 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m
case PN_expr: case PN_expr:
if (n == 2 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[1])) { if (n == 2 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[1])) {
// int | int // int | int
machine_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); mp_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 arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[1]);
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 | arg1); pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 | arg1);
} }
break; break;
...@@ -209,16 +209,16 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m ...@@ -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: 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])) { if (n == 2 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[1])) {
// int & int // int & int
machine_int_t arg0 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[0]); mp_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 arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[1]);
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 & arg1); pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 & arg1);
} }
break; break;
case PN_shift_expr: 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])) { 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]); mp_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 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)) { if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_DBL_LESS)) {
// int << int // int << int
if (!(arg1 >= BITS_PER_WORD || arg0 > (MP_SMALL_INT_MAX >> arg1) || arg0 < (MP_SMALL_INT_MIN >> arg1))) { 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 ...@@ -235,10 +235,10 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m
break; break;
case PN_arith_expr: 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])) { 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]); mp_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 arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[2]);
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_PLUS)) { if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_PLUS)) {
// int + int // int + int
arg0 += arg1; arg0 += arg1;
...@@ -258,8 +258,8 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m ...@@ -258,8 +258,8 @@ STATIC mp_parse_node_t fold_constants(compiler_t *comp, mp_parse_node_t pn, mp_m
case PN_term: case PN_term:
if (n == 3 && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[0]) && MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[2])) { 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]); mp_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 arg1 = MP_PARSE_NODE_LEAF_SMALL_INT(pns->nodes[2]);
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_STAR)) { if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_STAR)) {
// int * int // int * int
if (!mp_small_int_mul_overflow(arg0, arg1)) { 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 ...@@ -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: case PN_factor_2:
if (MP_PARSE_NODE_IS_SMALL_INT(pns->nodes[1])) { 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)) { if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_PLUS)) {
// +int // +int
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg); 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 ...@@ -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_obj_t dest[2];
mp_load_method_maybe(elem->value, q_attr, dest); mp_load_method_maybe(elem->value, q_attr, dest);
if (MP_OBJ_IS_SMALL_INT(dest[0]) && dest[1] == NULL) { 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)) { if (MP_SMALL_INT_FITS(val)) {
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, 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, ...@@ -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) { 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)) { if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_string)) {
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; 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; return;
} }
...@@ -2528,7 +2528,7 @@ void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -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]; 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); assert(MP_PARSE_NODE_STRUCT_KIND(pns_string) == PN_string);
pn_kind = MP_PARSE_NODE_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) { if (i == 0) {
string_kind = pn_kind; string_kind = pn_kind;
...@@ -2549,8 +2549,8 @@ void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) { ...@@ -2549,8 +2549,8 @@ void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) {
s_dest += s_len; s_dest += s_len;
} else { } else {
mp_parse_node_struct_t *pns_string = (mp_parse_node_struct_t*)pns->nodes[i]; 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]); memcpy(s_dest, (const char*)pns_string->nodes[0], (mp_uint_t)pns_string->nodes[1]);
s_dest += (machine_uint_t)pns_string->nodes[1]; s_dest += (mp_uint_t)pns_string->nodes[1];
} }
} }
qstr q = qstr_build_end(q_ptr); qstr q = qstr_build_end(q_ptr);
...@@ -2858,10 +2858,10 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) { ...@@ -2858,10 +2858,10 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) {
if (MP_PARSE_NODE_IS_NULL(pn)) { if (MP_PARSE_NODE_IS_NULL(pn)) {
// pass // pass
} else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { } 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); EMIT_ARG(load_const_small_int, arg);
} else if (MP_PARSE_NODE_IS_LEAF(pn)) { } 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)) { switch (MP_PARSE_NODE_LEAF_KIND(pn)) {
case MP_PARSE_NODE_ID: EMIT_ARG(load_id, arg); break; case MP_PARSE_NODE_ID: EMIT_ARG(load_id, arg); break;
case MP_PARSE_NODE_INTEGER: EMIT_ARG(load_const_int, 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) { ...@@ -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; mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
EMIT_ARG(set_line_number, pns->source_line); EMIT_ARG(set_line_number, pns->source_line);
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_string) { 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 { } else {
compile_function_t f = compile_function[MP_PARSE_NODE_STRUCT_KIND(pns)]; compile_function_t f = compile_function[MP_PARSE_NODE_STRUCT_KIND(pns)];
if (f == NULL) { if (f == NULL) {
...@@ -3337,7 +3337,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind ...@@ -3337,7 +3337,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
return; return;
} }
if (pass > MP_PASS_SCOPE) { 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++) { for (uint i = 1; i < n_args; i++) {
if (!MP_PARSE_NODE_IS_SMALL_INT(pn_arg[i])) { if (!MP_PARSE_NODE_IS_SMALL_INT(pn_arg[i])) {
compile_syntax_error(comp, nodes[i], "inline assembler 'data' requires integer arguments"); compile_syntax_error(comp, nodes[i], "inline assembler 'data' requires integer arguments");
......
...@@ -65,7 +65,7 @@ typedef struct _emit_method_table_t { ...@@ -65,7 +65,7 @@ typedef struct _emit_method_table_t {
void (*import_from)(emit_t *emit, qstr qstr); void (*import_from)(emit_t *emit, qstr qstr);
void (*import_star)(emit_t *emit); void (*import_star)(emit_t *emit);
void (*load_const_tok)(emit_t *emit, mp_token_kind_t tok); 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_int)(emit_t *emit, qstr qstr);
void (*load_const_dec)(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); void (*load_const_str)(emit_t *emit, qstr qstr, bool bytes);
......
...@@ -99,7 +99,7 @@ STATIC byte* emit_get_cur_to_write_code_info(emit_t* emit, int num_bytes_to_writ ...@@ -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) { 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) { 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 ...@@ -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) { 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) { 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) { ...@@ -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 // 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); emit_write_bytecode_byte(emit, b1);
// We store each 7 bits in a separate byte, and that's how many bytes needed // 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) { ...@@ -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) { STATIC void emit_write_bytecode_byte_ptr(emit_t* emit, byte b, void *ptr) {
emit_write_bytecode_byte(emit, b); emit_write_bytecode_byte(emit, b);
emit_align_bytecode_to_machine_word(emit); 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)); mp_uint_t *c = (mp_uint_t*)emit_get_cur_to_write_bytecode(emit, sizeof(mp_uint_t));
*c = (machine_uint_t)ptr; *c = (mp_uint_t)ptr;
} }
/* currently unused /* currently unused
...@@ -269,7 +269,7 @@ STATIC void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { ...@@ -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 // 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); 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;