You've already forked Core2forAWS-MicroPython
mirror of
https://github.com/m5stack/Core2forAWS-MicroPython.git
synced 2026-05-20 10:30:31 -07:00
py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.
This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
This commit is contained in:
+2
-2
@@ -77,13 +77,13 @@ typedef struct _machine_mem_obj_t {
|
||||
|
||||
STATIC void machine_mem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
machine_mem_obj_t *self = self_in;
|
||||
machine_mem_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<%u-bit memory>", 8 * self->elem_size);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
// TODO support slice index to read/write multiple values at once
|
||||
machine_mem_obj_t *self = self_in;
|
||||
machine_mem_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (value == MP_OBJ_NULL) {
|
||||
// delete
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
|
||||
+24
-24
@@ -124,24 +124,24 @@ STATIC NORETURN void syntax_error(void) {
|
||||
STATIC mp_obj_t uctypes_struct_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, 3, false);
|
||||
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
||||
o->base.type = type_in;
|
||||
o->addr = (void*)mp_obj_get_int(args[0]);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->addr = (void*)(uintptr_t)mp_obj_get_int(args[0]);
|
||||
o->desc = args[1];
|
||||
o->flags = LAYOUT_NATIVE;
|
||||
if (n_args == 3) {
|
||||
o->flags = mp_obj_get_int(args[2]);
|
||||
}
|
||||
return o;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
mp_obj_uctypes_struct_t *self = self_in;
|
||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
const char *typen = "unk";
|
||||
if (MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)) {
|
||||
typen = "STRUCT";
|
||||
} else if (MP_OBJ_IS_TYPE(self->desc, &mp_type_tuple)) {
|
||||
mp_obj_tuple_t *t = (mp_obj_tuple_t*)self->desc;
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
|
||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||
switch (agg_type) {
|
||||
@@ -207,12 +207,9 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, mp_uint_t *max_field
|
||||
}
|
||||
|
||||
STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, mp_uint_t *max_field_size) {
|
||||
mp_obj_dict_t *d = desc_in;
|
||||
mp_uint_t total_size = 0;
|
||||
|
||||
if (!MP_OBJ_IS_TYPE(desc_in, &mp_type_dict)) {
|
||||
if (MP_OBJ_IS_TYPE(desc_in, &mp_type_tuple)) {
|
||||
return uctypes_struct_agg_size((mp_obj_tuple_t*)desc_in, max_field_size);
|
||||
return uctypes_struct_agg_size((mp_obj_tuple_t*)MP_OBJ_TO_PTR(desc_in), max_field_size);
|
||||
} else if (MP_OBJ_IS_SMALL_INT(desc_in)) {
|
||||
// We allow sizeof on both type definitions and structures/structure fields,
|
||||
// but scalar structure field is lowered into native Python int, so all
|
||||
@@ -223,6 +220,9 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, mp_uint_t *max_field_size
|
||||
syntax_error();
|
||||
}
|
||||
|
||||
mp_obj_dict_t *d = MP_OBJ_TO_PTR(desc_in);
|
||||
mp_uint_t total_size = 0;
|
||||
|
||||
for (mp_uint_t i = 0; i < d->map.alloc; i++) {
|
||||
if (MP_MAP_SLOT_IS_FILLED(&d->map, i)) {
|
||||
mp_obj_t v = d->map.table[i].value;
|
||||
@@ -241,7 +241,7 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, mp_uint_t *max_field_size
|
||||
if (!MP_OBJ_IS_TYPE(v, &mp_type_tuple)) {
|
||||
syntax_error();
|
||||
}
|
||||
mp_obj_tuple_t *t = (mp_obj_tuple_t*)v;
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(v);
|
||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||
offset &= VALUE_MASK(AGG_TYPE_BITS);
|
||||
mp_uint_t s = uctypes_struct_agg_size(t, max_field_size);
|
||||
@@ -266,7 +266,7 @@ STATIC mp_obj_t uctypes_struct_sizeof(mp_obj_t obj_in) {
|
||||
// or to instantiated structure
|
||||
if (MP_OBJ_IS_TYPE(obj_in, &uctypes_struct_type)) {
|
||||
// Extract structure definition
|
||||
mp_obj_uctypes_struct_t *obj = obj_in;
|
||||
mp_obj_uctypes_struct_t *obj = MP_OBJ_TO_PTR(obj_in);
|
||||
obj_in = obj->desc;
|
||||
}
|
||||
mp_uint_t size = uctypes_struct_size(obj_in, &max_field_size);
|
||||
@@ -365,7 +365,7 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set_val) {
|
||||
mp_obj_uctypes_struct_t *self = self_in;
|
||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// TODO: Support at least OrderedDict in addition
|
||||
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)) {
|
||||
@@ -443,7 +443,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
||||
syntax_error();
|
||||
}
|
||||
|
||||
mp_obj_tuple_t *sub = (mp_obj_tuple_t*)deref;
|
||||
mp_obj_tuple_t *sub = MP_OBJ_TO_PTR(deref);
|
||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(sub->items[0]);
|
||||
mp_uint_t agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||
offset &= VALUE_MASK(AGG_TYPE_BITS);
|
||||
@@ -456,7 +456,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
||||
o->desc = sub->items[1];
|
||||
o->addr = self->addr + offset;
|
||||
o->flags = self->flags;
|
||||
return o;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
case ARRAY: {
|
||||
mp_uint_t dummy;
|
||||
@@ -468,11 +468,11 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
||||
case PTR: {
|
||||
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
||||
o->base.type = &uctypes_struct_type;
|
||||
o->desc = sub;
|
||||
o->desc = MP_OBJ_FROM_PTR(sub);
|
||||
o->addr = self->addr + offset;
|
||||
o->flags = self->flags;
|
||||
//printf("PTR/ARR base addr=%p\n", o->addr);
|
||||
return o;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ STATIC void uctypes_struct_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
|
||||
mp_obj_uctypes_struct_t *self = self_in;
|
||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (value == MP_OBJ_NULL) {
|
||||
// delete
|
||||
@@ -505,7 +505,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "struct: cannot index"));
|
||||
}
|
||||
|
||||
mp_obj_tuple_t *t = (mp_obj_tuple_t*)self->desc;
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
|
||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||
|
||||
@@ -530,7 +530,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
|
||||
o->desc = t->items[2];
|
||||
o->addr = self->addr + size * index;
|
||||
o->flags = self->flags;
|
||||
return o;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
} else if (agg_type == PTR) {
|
||||
byte *p = *(void**)self->addr;
|
||||
@@ -545,7 +545,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
|
||||
o->desc = t->items[1];
|
||||
o->addr = p + size * index;
|
||||
o->flags = self->flags;
|
||||
return o;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
|
||||
|
||||
STATIC mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||
(void)flags;
|
||||
mp_obj_uctypes_struct_t *self = self_in;
|
||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_uint_t max_field_size = 0;
|
||||
mp_uint_t size = uctypes_struct_size(self->desc, &max_field_size);
|
||||
|
||||
@@ -575,7 +575,7 @@ STATIC mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo,
|
||||
STATIC mp_obj_t uctypes_struct_addressof(mp_obj_t buf) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
|
||||
return mp_obj_new_int((mp_int_t)bufinfo.buf);
|
||||
return mp_obj_new_int((mp_int_t)(uintptr_t)bufinfo.buf);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof);
|
||||
|
||||
@@ -584,7 +584,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof
|
||||
/// captured by reference (and thus memory pointed by bytearray may change
|
||||
/// or become invalid at later time). Use bytes_at() to capture by value.
|
||||
STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) {
|
||||
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr));
|
||||
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)(uintptr_t)mp_obj_int_get_truncated(ptr));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at);
|
||||
|
||||
@@ -593,7 +593,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytear
|
||||
/// captured by value, i.e. copied. Use bytearray_at() to capture by reference
|
||||
/// ("zero copy").
|
||||
STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
|
||||
return mp_obj_new_bytes((void*)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
|
||||
return mp_obj_new_bytes((void*)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);
|
||||
|
||||
|
||||
@@ -44,16 +44,16 @@ STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
STATIC mp_obj_t hash_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(SHA256_CTX));
|
||||
o->base.type = type_in;
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
sha256_init((SHA256_CTX*)o->state);
|
||||
if (n_args == 1) {
|
||||
hash_update(o, args[0]);
|
||||
hash_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
return o;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = self_in;
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
sha256_update((SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len);
|
||||
@@ -62,7 +62,7 @@ STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(hash_update_obj, hash_update);
|
||||
|
||||
STATIC mp_obj_t hash_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = self_in;
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
|
||||
sha256_final((SHA256_CTX*)self->state, (byte*)vstr.buf);
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ STATIC mp_obj_list_t *get_heap(mp_obj_t heap_in) {
|
||||
if (!MP_OBJ_IS_TYPE(heap_in, &mp_type_list)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "heap must be a list"));
|
||||
}
|
||||
return heap_in;
|
||||
return MP_OBJ_TO_PTR(heap_in);
|
||||
}
|
||||
|
||||
STATIC void heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) {
|
||||
@@ -74,7 +74,7 @@ STATIC void heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) {
|
||||
|
||||
STATIC mp_obj_t mod_uheapq_heappush(mp_obj_t heap_in, mp_obj_t item) {
|
||||
mp_obj_list_t *heap = get_heap(heap_in);
|
||||
mp_obj_list_append(heap, item);
|
||||
mp_obj_list_append(heap_in, item);
|
||||
heap_siftdown(heap, 0, heap->len - 1);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
+1
-1
@@ -222,7 +222,7 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
|
||||
mp_obj_list_init(&stack, 1);
|
||||
stack.items[0] = stack_top;
|
||||
} else {
|
||||
mp_obj_list_append(&stack, stack_top);
|
||||
mp_obj_list_append(MP_OBJ_FROM_PTR(&stack), stack_top);
|
||||
}
|
||||
stack_top = next;
|
||||
stack_top_type = mp_obj_get_type(stack_top);
|
||||
|
||||
+11
-11
@@ -53,12 +53,12 @@ typedef struct _mp_obj_match_t {
|
||||
|
||||
STATIC void match_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
mp_obj_match_t *self = self_in;
|
||||
mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<match num=%d>", self->num_matches);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
|
||||
mp_obj_match_t *self = self_in;
|
||||
mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t no = mp_obj_get_int(no_in);
|
||||
if (no < 0 || no >= self->num_matches) {
|
||||
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, no_in));
|
||||
@@ -83,18 +83,18 @@ STATIC const mp_obj_type_t match_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_match,
|
||||
.print = match_print,
|
||||
.locals_dict = (mp_obj_t)&match_locals_dict,
|
||||
.locals_dict = (void*)&match_locals_dict,
|
||||
};
|
||||
|
||||
STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
mp_obj_re_t *self = self_in;
|
||||
mp_obj_re_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<re %p>", self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
mp_obj_re_t *self = args[0];
|
||||
mp_obj_re_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
Subject subj;
|
||||
mp_uint_t len;
|
||||
subj.begin = mp_obj_str_get_data(args[1], &len);
|
||||
@@ -112,7 +112,7 @@ STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
match->base.type = &match_type;
|
||||
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
|
||||
match->str = args[1];
|
||||
return match;
|
||||
return MP_OBJ_FROM_PTR(match);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t re_match(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
@@ -126,7 +126,7 @@ STATIC mp_obj_t re_search(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_search_obj, 2, 4, re_search);
|
||||
|
||||
STATIC mp_obj_t re_split(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_re_t *self = args[0];
|
||||
mp_obj_re_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
Subject subj;
|
||||
mp_uint_t len;
|
||||
subj.begin = mp_obj_str_get_data(args[1], &len);
|
||||
@@ -179,7 +179,7 @@ STATIC const mp_obj_type_t re_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_ure,
|
||||
.print = re_print,
|
||||
.locals_dict = (mp_obj_t)&re_locals_dict,
|
||||
.locals_dict = (void*)&re_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mod_re_compile(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
@@ -202,16 +202,16 @@ error:
|
||||
if (flags & FLAG_DEBUG) {
|
||||
re1_5_dumpcode(&o->re);
|
||||
}
|
||||
return o;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_compile_obj, 1, 2, mod_re_compile);
|
||||
|
||||
STATIC mp_obj_t mod_re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
mp_obj_re_t *self = mod_re_compile(1, args);
|
||||
mp_obj_t self = mod_re_compile(1, args);
|
||||
|
||||
const mp_obj_t args2[] = {self, args[1]};
|
||||
mp_obj_match_t *match = re_exec(is_anchored, 2, args2);
|
||||
mp_obj_t match = re_exec(is_anchored, 2, args2);
|
||||
return match;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, mp_uint_t expecte
|
||||
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"%q() takes %d positional arguments but %d were given",
|
||||
mp_obj_fun_get_name(f), expected, given));
|
||||
mp_obj_fun_get_name(MP_OBJ_FROM_PTR(f)), expected, given));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ void mp_setup_code_state(mp_code_state *code_state, mp_obj_fun_bc_t *self, mp_ui
|
||||
mp_uint_t n_state = code_state->n_state;
|
||||
|
||||
// ip comes in as an offset into bytecode, so turn it into a true pointer
|
||||
code_state->ip = self->bytecode + (mp_uint_t)code_state->ip;
|
||||
code_state->ip = self->bytecode + (size_t)code_state->ip;
|
||||
|
||||
// store pointer to constant table
|
||||
code_state->const_table = self->const_table;
|
||||
@@ -219,7 +219,7 @@ continue2:;
|
||||
if (code_state->state[n_state - 1 - n_pos_args - i] == MP_OBJ_NULL) {
|
||||
mp_map_elem_t *elem = NULL;
|
||||
if ((scope_flags & MP_SCOPE_FLAG_DEFKWARGS) != 0) {
|
||||
elem = mp_map_lookup(&((mp_obj_dict_t*)self->extra_args[n_def_pos_args])->map, arg_names[n_pos_args + i], MP_MAP_LOOKUP);
|
||||
elem = mp_map_lookup(&((mp_obj_dict_t*)MP_OBJ_TO_PTR(self->extra_args[n_def_pos_args]))->map, arg_names[n_pos_args + i], MP_MAP_LOOKUP);
|
||||
}
|
||||
if (elem != NULL) {
|
||||
code_state->state[n_state - 1 - n_pos_args - i] = elem->value;
|
||||
|
||||
@@ -66,7 +66,7 @@ typedef struct _mp_exc_stack {
|
||||
// bit 1 is whether the opcode was SETUP_WITH or SETUP_FINALLY
|
||||
mp_obj_t *val_sp;
|
||||
// Saved exception, valid if currently_in_except_block bit is 1
|
||||
mp_obj_t prev_exc;
|
||||
mp_obj_base_t *prev_exc;
|
||||
} mp_exc_stack_t;
|
||||
|
||||
typedef struct _mp_code_state {
|
||||
|
||||
+3
-3
@@ -147,7 +147,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
|
||||
return ((mp_obj_t*)p)[index];
|
||||
// Extension to CPython: array of pointers
|
||||
case 'P':
|
||||
return mp_obj_new_int((mp_int_t)((void**)p)[index]);
|
||||
return mp_obj_new_int((mp_int_t)(uintptr_t)((void**)p)[index]);
|
||||
}
|
||||
return MP_OBJ_NEW_SMALL_INT(val);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
|
||||
if (val_type == 'O') {
|
||||
return (mp_obj_t)(mp_uint_t)val;
|
||||
} else if (val_type == 'S') {
|
||||
const char *s_val = (const char*)(mp_uint_t)val;
|
||||
const char *s_val = (const char*)(uintptr_t)(mp_uint_t)val;
|
||||
return mp_obj_new_str(s_val, strlen(s_val), false);
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
} else if (val_type == 'f') {
|
||||
@@ -374,6 +374,6 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
|
||||
#endif
|
||||
// Extension to CPython: array of pointers
|
||||
case 'P':
|
||||
((void**)p)[index] = (void*)val;
|
||||
((void**)p)[index] = (void*)(uintptr_t)val;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -44,7 +44,7 @@ STATIC const mp_obj_type_t mp_type_code = {
|
||||
.name = MP_QSTR_code,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_t globals, mp_obj_t locals) {
|
||||
STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj_dict_t *locals) {
|
||||
// save context and set new context
|
||||
mp_obj_dict_t *old_globals = mp_globals_get();
|
||||
mp_obj_dict_t *old_locals = mp_locals_get();
|
||||
@@ -54,7 +54,7 @@ STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_t globals, mp_obj_t loc
|
||||
// a bit of a hack: fun_bc will re-set globals, so need to make sure it's
|
||||
// the correct one
|
||||
if (MP_OBJ_IS_TYPE(self->module_fun, &mp_type_fun_bc)) {
|
||||
mp_obj_fun_bc_t *fun_bc = self->module_fun;
|
||||
mp_obj_fun_bc_t *fun_bc = MP_OBJ_TO_PTR(self->module_fun);
|
||||
fun_bc->globals = globals;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_t globals, mp_obj_t loc
|
||||
// exception; restore context and re-raise same exception
|
||||
mp_globals_set(old_globals);
|
||||
mp_locals_set(old_locals);
|
||||
nlr_raise(nlr.ret_val);
|
||||
nlr_jump(nlr.ret_val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ STATIC mp_obj_t mp_builtin_compile(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_code_t *code = m_new_obj(mp_obj_code_t);
|
||||
code->base.type = &mp_type_code;
|
||||
code->module_fun = mp_parse_compile_execute(lex, parse_input_kind, NULL, NULL);
|
||||
return code;
|
||||
return MP_OBJ_FROM_PTR(code);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_compile_obj, 3, 6, mp_builtin_compile);
|
||||
|
||||
@@ -112,9 +112,9 @@ STATIC mp_obj_t eval_exec_helper(mp_uint_t n_args, const mp_obj_t *args, mp_pars
|
||||
mp_obj_dict_t *globals = mp_globals_get();
|
||||
mp_obj_dict_t *locals = mp_locals_get();
|
||||
if (n_args > 1) {
|
||||
globals = args[1];
|
||||
globals = MP_OBJ_TO_PTR(args[1]);
|
||||
if (n_args > 2) {
|
||||
locals = args[2];
|
||||
locals = MP_OBJ_TO_PTR(args[2]);
|
||||
} else {
|
||||
locals = globals;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ STATIC mp_obj_t eval_exec_helper(mp_uint_t n_args, const mp_obj_t *args, mp_pars
|
||||
|
||||
#if MICROPY_PY_BUILTINS_COMPILE
|
||||
if (MP_OBJ_IS_TYPE(args[0], &mp_type_code)) {
|
||||
return code_execute(args[0], globals, locals);
|
||||
return code_execute(MP_OBJ_TO_PTR(args[0]), globals, locals);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+9
-9
@@ -174,7 +174,7 @@ STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code) {
|
||||
// exception; restore context and re-raise same exception
|
||||
mp_globals_set(old_globals);
|
||||
mp_locals_set(old_locals);
|
||||
nlr_raise(nlr.ret_val);
|
||||
nlr_jump(nlr.ret_val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -237,15 +237,15 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
// "Relative imports use a module's __name__ attribute to determine that
|
||||
// module's position in the package hierarchy."
|
||||
level--;
|
||||
mp_obj_t this_name_q = mp_obj_dict_get(mp_globals_get(), MP_OBJ_NEW_QSTR(MP_QSTR___name__));
|
||||
mp_obj_t this_name_q = mp_obj_dict_get(MP_OBJ_FROM_PTR(mp_globals_get()), MP_OBJ_NEW_QSTR(MP_QSTR___name__));
|
||||
assert(this_name_q != MP_OBJ_NULL);
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
if (MP_OBJ_QSTR_VALUE(this_name_q) == MP_QSTR___main__) {
|
||||
// This is a module run by -m command-line switch, get its real name from backup attribute
|
||||
this_name_q = mp_obj_dict_get(mp_globals_get(), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
|
||||
this_name_q = mp_obj_dict_get(MP_OBJ_FROM_PTR(mp_globals_get()), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
|
||||
}
|
||||
#endif
|
||||
mp_map_t *globals_map = mp_obj_dict_get_map(mp_globals_get());
|
||||
mp_map_t *globals_map = &mp_globals_get()->map;
|
||||
mp_map_elem_t *elem = mp_map_lookup(globals_map, MP_OBJ_NEW_QSTR(MP_QSTR___path__), MP_MAP_LOOKUP);
|
||||
bool is_pkg = (elem != NULL);
|
||||
|
||||
@@ -338,8 +338,8 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
// name to __main__ instead of real name).
|
||||
// TODO: Duplicated below too.
|
||||
if (fromtuple == mp_const_false) {
|
||||
mp_obj_module_t *o = module_obj;
|
||||
mp_obj_dict_store(o->globals, MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
|
||||
mp_obj_module_t *o = MP_OBJ_TO_PTR(module_obj);
|
||||
mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
|
||||
}
|
||||
do_load_from_lexer(module_obj, lex, mod_str);
|
||||
return module_obj;
|
||||
@@ -409,11 +409,11 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
// this module for command-line "-m" option (set module's
|
||||
// name to __main__ instead of real name).
|
||||
if (i == mod_len && fromtuple == mp_const_false) {
|
||||
mp_obj_module_t *o = module_obj;
|
||||
mp_obj_dict_store(o->globals, MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
|
||||
mp_obj_module_t *o = MP_OBJ_TO_PTR(module_obj);
|
||||
mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
// Store real name in "__main__" attribute. Choosen semi-randonly, to reuse existing qstr's.
|
||||
mp_obj_dict_store(o->globals, MP_OBJ_NEW_QSTR(MP_QSTR___main__), MP_OBJ_NEW_QSTR(mod_name));
|
||||
mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___main__), MP_OBJ_NEW_QSTR(mod_name));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+28
-24
@@ -38,6 +38,11 @@
|
||||
#define DUMMY_DATA_SIZE (BYTES_FOR_INT)
|
||||
|
||||
struct _emit_t {
|
||||
// Accessed as mp_obj_t, so must be aligned as such, and we rely on the
|
||||
// memory allocator returning a suitably aligned pointer.
|
||||
// Should work for cases when mp_obj_t is 64-bit on a 32-bit machine.
|
||||
byte dummy_data[DUMMY_DATA_SIZE];
|
||||
|
||||
pass_kind_t pass : 8;
|
||||
mp_uint_t last_emit_was_return_value : 8;
|
||||
|
||||
@@ -51,10 +56,10 @@ struct _emit_t {
|
||||
mp_uint_t max_num_labels;
|
||||
mp_uint_t *label_offsets;
|
||||
|
||||
mp_uint_t code_info_offset;
|
||||
mp_uint_t code_info_size;
|
||||
mp_uint_t bytecode_offset;
|
||||
mp_uint_t bytecode_size;
|
||||
size_t code_info_offset;
|
||||
size_t code_info_size;
|
||||
size_t bytecode_offset;
|
||||
size_t bytecode_size;
|
||||
byte *code_base; // stores both byte code and code info
|
||||
|
||||
#if MICROPY_PERSISTENT_CODE
|
||||
@@ -63,9 +68,6 @@ struct _emit_t {
|
||||
uint16_t ct_cur_raw_code;
|
||||
#endif
|
||||
mp_uint_t *const_table;
|
||||
|
||||
// Accessed as mp_uint_t, so must be aligned as such
|
||||
byte dummy_data[DUMMY_DATA_SIZE];
|
||||
};
|
||||
|
||||
emit_t *emit_bc_new(void) {
|
||||
@@ -224,16 +226,6 @@ STATIC void emit_write_bytecode_byte_const(emit_t *emit, byte b, mp_uint_t n, mp
|
||||
}
|
||||
emit_write_bytecode_byte_uint(emit, b, n);
|
||||
}
|
||||
#else
|
||||
STATIC void emit_write_bytecode_byte_ptr(emit_t *emit, byte b, void *ptr) {
|
||||
// aligns the pointer so it is friendly to GC
|
||||
emit_write_bytecode_byte(emit, b);
|
||||
emit->bytecode_offset = (mp_uint_t)MP_ALIGN(emit->bytecode_offset, sizeof(mp_uint_t));
|
||||
mp_uint_t *c = (mp_uint_t*)emit_get_cur_to_write_bytecode(emit, sizeof(mp_uint_t));
|
||||
// Verify thar c is already uint-aligned
|
||||
assert(c == MP_ALIGN(c, sizeof(mp_uint_t)));
|
||||
*c = (mp_uint_t)ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC void emit_write_bytecode_byte_qstr(emit_t* emit, byte b, qstr qst) {
|
||||
@@ -248,13 +240,19 @@ STATIC void emit_write_bytecode_byte_qstr(emit_t* emit, byte b, qstr qst) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC void emit_write_bytecode_byte_obj(emit_t *emit, byte b, void *ptr) {
|
||||
STATIC void emit_write_bytecode_byte_obj(emit_t *emit, byte b, mp_obj_t obj) {
|
||||
#if MICROPY_PERSISTENT_CODE
|
||||
emit_write_bytecode_byte_const(emit, b,
|
||||
emit->scope->num_pos_args + emit->scope->num_kwonly_args
|
||||
+ emit->ct_cur_obj++, (mp_uint_t)ptr);
|
||||
+ emit->ct_cur_obj++, (mp_uint_t)obj);
|
||||
#else
|
||||
emit_write_bytecode_byte_ptr(emit, b, ptr);
|
||||
// aligns the pointer so it is friendly to GC
|
||||
emit_write_bytecode_byte(emit, b);
|
||||
emit->bytecode_offset = (size_t)MP_ALIGN(emit->bytecode_offset, sizeof(mp_obj_t));
|
||||
mp_obj_t *c = (mp_obj_t*)emit_get_cur_to_write_bytecode(emit, sizeof(mp_obj_t));
|
||||
// Verify thar c is already uint-aligned
|
||||
assert(c == MP_ALIGN(c, sizeof(mp_obj_t)));
|
||||
*c = obj;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -262,9 +260,15 @@ STATIC void emit_write_bytecode_byte_raw_code(emit_t *emit, byte b, mp_raw_code_
|
||||
#if MICROPY_PERSISTENT_CODE
|
||||
emit_write_bytecode_byte_const(emit, b,
|
||||
emit->scope->num_pos_args + emit->scope->num_kwonly_args
|
||||
+ emit->ct_num_obj + emit->ct_cur_raw_code++, (mp_uint_t)rc);
|
||||
+ emit->ct_num_obj + emit->ct_cur_raw_code++, (mp_uint_t)(uintptr_t)rc);
|
||||
#else
|
||||
emit_write_bytecode_byte_ptr(emit, b, rc);
|
||||
// aligns the pointer so it is friendly to GC
|
||||
emit_write_bytecode_byte(emit, b);
|
||||
emit->bytecode_offset = (size_t)MP_ALIGN(emit->bytecode_offset, sizeof(void*));
|
||||
void **c = (void**)emit_get_cur_to_write_bytecode(emit, sizeof(void*));
|
||||
// Verify thar c is already uint-aligned
|
||||
assert(c == MP_ALIGN(c, sizeof(void*)));
|
||||
*c = rc;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -416,7 +420,7 @@ void mp_emit_bc_end_pass(emit_t *emit) {
|
||||
if (emit->pass == MP_PASS_CODE_SIZE) {
|
||||
#if !MICROPY_PERSISTENT_CODE
|
||||
// so bytecode is aligned
|
||||
emit->code_info_offset = (mp_uint_t)MP_ALIGN(emit->code_info_offset, sizeof(mp_uint_t));
|
||||
emit->code_info_offset = (size_t)MP_ALIGN(emit->code_info_offset, sizeof(mp_uint_t));
|
||||
#endif
|
||||
|
||||
// calculate size of total code-info + bytecode, in bytes
|
||||
@@ -523,7 +527,7 @@ void mp_emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
|
||||
case MP_TOKEN_KW_NONE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_NONE); break;
|
||||
case MP_TOKEN_KW_TRUE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_TRUE); break;
|
||||
no_other_choice:
|
||||
case MP_TOKEN_ELLIPSIS: emit_write_bytecode_byte_obj(emit, MP_BC_LOAD_CONST_OBJ, (void*)&mp_const_ellipsis_obj); break;
|
||||
case MP_TOKEN_ELLIPSIS: emit_write_bytecode_byte_obj(emit, MP_BC_LOAD_CONST_OBJ, MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj)); break;
|
||||
default: assert(0); goto no_other_choice; // to help flow control analysis
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -263,7 +263,7 @@ STATIC qstr load_qstr(mp_reader_t *reader) {
|
||||
STATIC mp_obj_t load_obj(mp_reader_t *reader) {
|
||||
byte obj_type = read_byte(reader);
|
||||
if (obj_type == 'e') {
|
||||
return (mp_obj_t)&mp_const_ellipsis_obj;
|
||||
return MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj);
|
||||
} else {
|
||||
size_t len = read_uint(reader);
|
||||
vstr_t vstr;
|
||||
@@ -324,7 +324,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader) {
|
||||
*ct++ = (mp_uint_t)load_obj(reader);
|
||||
}
|
||||
for (mp_uint_t i = 0; i < n_raw_code; ++i) {
|
||||
*ct++ = (mp_uint_t)load_raw_code(reader);
|
||||
*ct++ = (mp_uint_t)(uintptr_t)load_raw_code(reader);
|
||||
}
|
||||
|
||||
// create raw_code and return it
|
||||
@@ -511,7 +511,7 @@ STATIC void save_obj(mp_print_t *print, mp_obj_t o) {
|
||||
mp_print_bytes(print, &obj_type, 1);
|
||||
mp_print_uint(print, len);
|
||||
mp_print_bytes(print, (const byte*)str, len);
|
||||
} else if (o == &mp_const_ellipsis_obj) {
|
||||
} else if (MP_OBJ_TO_PTR(o) == &mp_const_ellipsis_obj) {
|
||||
byte obj_type = 'e';
|
||||
mp_print_bytes(print, &obj_type, 1);
|
||||
} else {
|
||||
@@ -582,7 +582,7 @@ STATIC void save_raw_code(mp_print_t *print, mp_raw_code_t *rc) {
|
||||
save_obj(print, (mp_obj_t)*const_table++);
|
||||
}
|
||||
for (uint i = 0; i < rc->data.u_byte.n_raw_code; ++i) {
|
||||
save_raw_code(print, (mp_raw_code_t*)*const_table++);
|
||||
save_raw_code(print, (mp_raw_code_t*)(uintptr_t)*const_table++);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,7 +614,7 @@ STATIC void fd_print_strn(void *env, const char *str, size_t len) {
|
||||
|
||||
void mp_raw_code_save_file(mp_raw_code_t *rc, const char *filename) {
|
||||
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
mp_print_t fd_print = {(void*)(mp_int_t)fd, fd_print_strn};
|
||||
mp_print_t fd_print = {(void*)(intptr_t)fd, fd_print_strn};
|
||||
mp_raw_code_save(rc, &fd_print);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ STATIC void gc_drain_stack(void) {
|
||||
mp_obj_t *scan = (mp_obj_t*)PTR_FROM_BLOCK(block);
|
||||
for (mp_uint_t i = n_blocks * WORDS_PER_BLOCK; i > 0; i--, scan++) {
|
||||
mp_obj_t obj = *scan;
|
||||
void *ptr2 = (void*)obj;
|
||||
void *ptr2 = MP_OBJ_TO_PTR(obj);
|
||||
VERIFY_MARK_AND_PUSH(ptr2);
|
||||
}
|
||||
}
|
||||
@@ -237,7 +237,7 @@ STATIC void gc_sweep(void) {
|
||||
#if MICROPY_ENABLE_FINALISER
|
||||
if (FTB_GET(block)) {
|
||||
mp_obj_t obj = (mp_obj_t)PTR_FROM_BLOCK(block);
|
||||
if (((mp_obj_base_t*)obj)->type != MP_OBJ_NULL) {
|
||||
if (((mp_obj_base_t*)MP_OBJ_TO_PTR(obj))->type != NULL) {
|
||||
// if the object has a type then see if it has a __del__ method
|
||||
mp_obj_t dest[2];
|
||||
mp_load_method_maybe(obj, MP_QSTR___del__, dest);
|
||||
|
||||
@@ -101,7 +101,7 @@ size_t m_get_peak_bytes_allocated(void);
|
||||
#define MP_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
// align ptr to the nearest multiple of "alignment"
|
||||
#define MP_ALIGN(ptr, alignment) (void*)(((mp_uint_t)(ptr) + ((alignment) - 1)) & ~((alignment) - 1))
|
||||
#define MP_ALIGN(ptr, alignment) (void*)(((uintptr_t)(ptr) + ((alignment) - 1)) & ~((alignment) - 1))
|
||||
|
||||
/** unichar / UTF-8 *********************************************/
|
||||
|
||||
|
||||
+12
-12
@@ -53,7 +53,7 @@ STATIC mp_obj_t mp_builtin___build_class__(mp_uint_t n_args, const mp_obj_t *arg
|
||||
// set the new classes __locals__ object
|
||||
mp_obj_dict_t *old_locals = mp_locals_get();
|
||||
mp_obj_t class_locals = mp_obj_new_dict(0);
|
||||
mp_locals_set(class_locals);
|
||||
mp_locals_set(MP_OBJ_TO_PTR(class_locals));
|
||||
|
||||
// call the class code
|
||||
mp_obj_t cell = mp_call_function_0(args[0]);
|
||||
@@ -65,10 +65,10 @@ STATIC mp_obj_t mp_builtin___build_class__(mp_uint_t n_args, const mp_obj_t *arg
|
||||
mp_obj_t meta;
|
||||
if (n_args == 2) {
|
||||
// no explicit bases, so use 'type'
|
||||
meta = (mp_obj_t)&mp_type_type;
|
||||
meta = MP_OBJ_FROM_PTR(&mp_type_type);
|
||||
} else {
|
||||
// use type of first base object
|
||||
meta = mp_obj_get_type(args[2]);
|
||||
meta = MP_OBJ_FROM_PTR(mp_obj_get_type(args[2]));
|
||||
}
|
||||
|
||||
// TODO do proper metaclass resolution for multiple base objects
|
||||
@@ -206,11 +206,11 @@ STATIC mp_obj_t mp_builtin_dir(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
} else {
|
||||
mp_obj_type_t *type;
|
||||
if (MP_OBJ_IS_TYPE(args[0], &mp_type_type)) {
|
||||
type = args[0];
|
||||
type = MP_OBJ_TO_PTR(args[0]);
|
||||
} else {
|
||||
type = mp_obj_get_type(args[0]);
|
||||
}
|
||||
if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) {
|
||||
if (type->locals_dict != NULL && type->locals_dict->base.type == &mp_type_dict) {
|
||||
dict = type->locals_dict;
|
||||
}
|
||||
}
|
||||
@@ -376,18 +376,18 @@ STATIC mp_obj_t mp_builtin_print(mp_uint_t n_args, const mp_obj_t *args, mp_map_
|
||||
end_data = mp_obj_str_get_data(end_elem->value, &end_len);
|
||||
}
|
||||
#if MICROPY_PY_IO
|
||||
mp_obj_t stream_obj = &mp_sys_stdout_obj;
|
||||
void *stream_obj = &mp_sys_stdout_obj;
|
||||
mp_map_elem_t *file_elem = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_file), MP_MAP_LOOKUP);
|
||||
if (file_elem != NULL && file_elem->value != mp_const_none) {
|
||||
stream_obj = file_elem->value;
|
||||
stream_obj = MP_OBJ_TO_PTR(file_elem->value); // XXX may not be a concrete object
|
||||
}
|
||||
|
||||
mp_print_t print = {stream_obj, (mp_print_strn_t)mp_stream_write};
|
||||
mp_print_t print = {stream_obj, mp_stream_write_adaptor};
|
||||
#endif
|
||||
for (mp_uint_t i = 0; i < n_args; i++) {
|
||||
if (i > 0) {
|
||||
#if MICROPY_PY_IO
|
||||
mp_stream_write(stream_obj, sep_data, sep_len);
|
||||
mp_stream_write_adaptor(stream_obj, sep_data, sep_len);
|
||||
#else
|
||||
mp_print_strn(&mp_plat_print, sep_data, sep_len, 0, 0, 0);
|
||||
#endif
|
||||
@@ -399,7 +399,7 @@ STATIC mp_obj_t mp_builtin_print(mp_uint_t n_args, const mp_obj_t *args, mp_map_
|
||||
#endif
|
||||
}
|
||||
#if MICROPY_PY_IO
|
||||
mp_stream_write(stream_obj, end_data, end_len);
|
||||
mp_stream_write_adaptor(stream_obj, end_data, end_len);
|
||||
#else
|
||||
mp_print_strn(&mp_plat_print, end_data, end_len, 0, 0, 0);
|
||||
#endif
|
||||
@@ -418,7 +418,7 @@ STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
|
||||
#endif
|
||||
#if MICROPY_CAN_OVERRIDE_BUILTINS
|
||||
mp_obj_t dest[2] = {MP_OBJ_SENTINEL, o};
|
||||
mp_type_module.attr((mp_obj_t)&mp_module_builtins, MP_QSTR__, dest);
|
||||
mp_type_module.attr(MP_OBJ_FROM_PTR(&mp_module_builtins), MP_QSTR__, dest);
|
||||
#endif
|
||||
}
|
||||
return mp_const_none;
|
||||
@@ -490,7 +490,7 @@ STATIC mp_obj_t mp_builtin_sorted(mp_uint_t n_args, const mp_obj_t *args, mp_map
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||
"must use keyword argument for key function"));
|
||||
}
|
||||
mp_obj_t self = mp_type_list.make_new((mp_obj_t)&mp_type_list, 1, 0, args);
|
||||
mp_obj_t self = mp_type_list.make_new(MP_OBJ_FROM_PTR(&mp_type_list), 1, 0, args);
|
||||
mp_obj_list_sort(1, &self, kwargs);
|
||||
|
||||
return self;
|
||||
|
||||
+2
-2
@@ -137,7 +137,7 @@ STATIC mp_obj_t struct_unpack(mp_obj_t fmt_in, mp_obj_t data_in) {
|
||||
const char *fmt = mp_obj_str_get_str(fmt_in);
|
||||
char fmt_type = get_fmt_type(&fmt);
|
||||
uint size = calcsize_items(fmt);
|
||||
mp_obj_tuple_t *res = mp_obj_new_tuple(size, NULL);
|
||||
mp_obj_tuple_t *res = MP_OBJ_TO_PTR(mp_obj_new_tuple(size, NULL));
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(data_in, &bufinfo, MP_BUFFER_READ);
|
||||
byte *p = bufinfo.buf;
|
||||
@@ -161,7 +161,7 @@ STATIC mp_obj_t struct_unpack(mp_obj_t fmt_in, mp_obj_t data_in) {
|
||||
}
|
||||
fmt++;
|
||||
}
|
||||
return res;
|
||||
return MP_OBJ_FROM_PTR(res);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(struct_unpack_obj, struct_unpack);
|
||||
|
||||
|
||||
+9
-9
@@ -45,7 +45,7 @@ extern struct _mp_dummy_t mp_sys_stdout_obj;
|
||||
extern struct _mp_dummy_t mp_sys_stderr_obj;
|
||||
|
||||
#if MICROPY_PY_IO
|
||||
const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, (mp_print_strn_t)mp_stream_write};
|
||||
const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adaptor};
|
||||
#endif
|
||||
|
||||
/// \constant version - Python language version that this implementation conforms to, as a string
|
||||
@@ -106,12 +106,12 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit);
|
||||
|
||||
STATIC mp_obj_t mp_sys_print_exception(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
#if MICROPY_PY_IO
|
||||
mp_obj_t stream_obj = &mp_sys_stdout_obj;
|
||||
void *stream_obj = &mp_sys_stdout_obj;
|
||||
if (n_args > 1) {
|
||||
stream_obj = args[1];
|
||||
stream_obj = MP_OBJ_TO_PTR(args[1]); // XXX may fail
|
||||
}
|
||||
|
||||
mp_print_t print = {stream_obj, (mp_print_strn_t)mp_stream_write};
|
||||
mp_print_t print = {stream_obj, mp_stream_write_adaptor};
|
||||
mp_obj_print_exception(&print, args[0]);
|
||||
#else
|
||||
(void)n_args;
|
||||
@@ -124,20 +124,20 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_print_exception_obj, 1, 2, mp_sys_pri
|
||||
|
||||
#if MICROPY_PY_SYS_EXC_INFO
|
||||
STATIC mp_obj_t mp_sys_exc_info(void) {
|
||||
mp_obj_t cur_exc = MP_STATE_VM(cur_exception);
|
||||
mp_obj_tuple_t *t = mp_obj_new_tuple(3, NULL);
|
||||
mp_obj_t cur_exc = MP_OBJ_FROM_PTR(MP_STATE_VM(cur_exception));
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||
|
||||
if (cur_exc == MP_OBJ_NULL) {
|
||||
t->items[0] = mp_const_none;
|
||||
t->items[1] = mp_const_none;
|
||||
t->items[2] = mp_const_none;
|
||||
return t;
|
||||
return MP_OBJ_FROM_PTR(t);
|
||||
}
|
||||
|
||||
t->items[0] = mp_obj_get_type(cur_exc);
|
||||
t->items[0] = MP_OBJ_FROM_PTR(mp_obj_get_type(cur_exc));
|
||||
t->items[1] = cur_exc;
|
||||
t->items[2] = mp_const_none;
|
||||
return t;
|
||||
return MP_OBJ_FROM_PTR(t);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info);
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ typedef struct _mp_state_vm_t {
|
||||
|
||||
// current exception being handled, for sys.exc_info()
|
||||
#if MICROPY_PY_SYS_EXC_INFO
|
||||
mp_obj_t cur_exception;
|
||||
mp_obj_base_t *cur_exception;
|
||||
#endif
|
||||
|
||||
// dictionary for the __main__ module
|
||||
|
||||
@@ -39,7 +39,7 @@ typedef struct _nlr_buf_t nlr_buf_t;
|
||||
struct _nlr_buf_t {
|
||||
// the entries here must all be machine word size
|
||||
nlr_buf_t *prev;
|
||||
void *ret_val;
|
||||
void *ret_val; // always a concrete object (an exception instance)
|
||||
#if !defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP
|
||||
#if defined(__i386__)
|
||||
void *regs[6];
|
||||
@@ -86,16 +86,16 @@ void nlr_jump_fail(void *val);
|
||||
|
||||
// use nlr_raise instead of nlr_jump so that debugging is easier
|
||||
#ifndef DEBUG
|
||||
#define nlr_raise(val) nlr_jump(val)
|
||||
#define nlr_raise(val) nlr_jump(MP_OBJ_TO_PTR(val))
|
||||
#else
|
||||
#include "mpstate.h"
|
||||
#define nlr_raise(val) \
|
||||
do { \
|
||||
/*printf("nlr_raise: nlr_top=%p\n", MP_STATE_VM(nlr_top)); \
|
||||
fflush(stdout);*/ \
|
||||
void *_val = val; \
|
||||
void *_val = MP_OBJ_TO_PTR(val); \
|
||||
assert(_val != NULL); \
|
||||
assert(mp_obj_is_exception_instance(_val)); \
|
||||
assert(mp_obj_is_exception_instance(val)); \
|
||||
nlr_jump(_val); \
|
||||
} while (0)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user