Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
3e1a5c10
Commit
3e1a5c10
authored
Mar 29, 2014
by
Damien George
Browse files
py: Rename old const type objects to mp_type_* for consistency.
parent
07ddab52
Changes
27
Show whitespace changes
Inline
Side-by-side
py/builtin.c
View file @
3e1a5c10
...
...
@@ -166,7 +166,7 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
}
else
{
type
=
mp_obj_get_type
(
args
[
0
]);
}
if
(
type
->
locals_dict
!=
MP_OBJ_NULL
&&
MP_OBJ_IS_TYPE
(
type
->
locals_dict
,
&
dict
_type
))
{
if
(
type
->
locals_dict
!=
MP_OBJ_NULL
&&
MP_OBJ_IS_TYPE
(
type
->
locals_dict
,
&
mp
_type
_dict
))
{
map
=
mp_obj_dict_get_map
(
type
->
locals_dict
);
}
}
...
...
@@ -375,7 +375,7 @@ STATIC mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *k
nlr_jump
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"must use keyword argument for key function"
));
}
mp_obj_t
self
=
list
_type
.
make_new
((
mp_obj_t
)
&
list
_type
,
1
,
0
,
args
);
mp_obj_t
self
=
mp
_type
_list
.
make_new
((
mp_obj_t
)
&
mp
_type
_list
,
1
,
0
,
args
);
mp_obj_list_sort
(
1
,
&
self
,
kwargs
);
return
self
;
...
...
py/builtintables.c
View file @
3e1a5c10
...
...
@@ -26,26 +26,26 @@ STATIC const mp_builtin_elem_t builtin_object_table[] = {
// built-in types
{
MP_QSTR_bool
,
(
mp_obj_t
)
&
mp_type_bool
},
{
MP_QSTR_bytes
,
(
mp_obj_t
)
&
bytes
_type
},
{
MP_QSTR_bytes
,
(
mp_obj_t
)
&
mp_type_
bytes
},
#if MICROPY_ENABLE_FLOAT
{
MP_QSTR_complex
,
(
mp_obj_t
)
&
mp_type_complex
},
#endif
{
MP_QSTR_dict
,
(
mp_obj_t
)
&
dict
_type
},
{
MP_QSTR_enumerate
,
(
mp_obj_t
)
&
enumerate
_type
},
{
MP_QSTR_filter
,
(
mp_obj_t
)
&
filter
_type
},
{
MP_QSTR_dict
,
(
mp_obj_t
)
&
mp
_type
_dict
},
{
MP_QSTR_enumerate
,
(
mp_obj_t
)
&
mp_type_
enumerate
},
{
MP_QSTR_filter
,
(
mp_obj_t
)
&
mp_type_
filter
},
#if MICROPY_ENABLE_FLOAT
{
MP_QSTR_float
,
(
mp_obj_t
)
&
mp_type_float
},
#endif
{
MP_QSTR_int
,
(
mp_obj_t
)
&
int
_type
},
{
MP_QSTR_list
,
(
mp_obj_t
)
&
list
_type
},
{
MP_QSTR_map
,
(
mp_obj_t
)
&
m
a
p_type
},
{
MP_QSTR_int
,
(
mp_obj_t
)
&
mp
_type
_int
},
{
MP_QSTR_list
,
(
mp_obj_t
)
&
mp
_type
_list
},
{
MP_QSTR_map
,
(
mp_obj_t
)
&
mp_type
_map
},
{
MP_QSTR_object
,
(
mp_obj_t
)
&
mp_type_object
},
{
MP_QSTR_set
,
(
mp_obj_t
)
&
set
_type
},
{
MP_QSTR_str
,
(
mp_obj_t
)
&
str
_type
},
{
MP_QSTR_super
,
(
mp_obj_t
)
&
super
_type
},
{
MP_QSTR_set
,
(
mp_obj_t
)
&
mp
_type
_set
},
{
MP_QSTR_str
,
(
mp_obj_t
)
&
mp
_type
_str
},
{
MP_QSTR_super
,
(
mp_obj_t
)
&
mp_type_
super
},
{
MP_QSTR_tuple
,
(
mp_obj_t
)
&
mp_type_tuple
},
{
MP_QSTR_type
,
(
mp_obj_t
)
&
mp_type_type
},
{
MP_QSTR_zip
,
(
mp_obj_t
)
&
zi
p_type
},
{
MP_QSTR_zip
,
(
mp_obj_t
)
&
m
p_type
_zip
},
{
MP_QSTR_classmethod
,
(
mp_obj_t
)
&
mp_type_classmethod
},
{
MP_QSTR_staticmethod
,
(
mp_obj_t
)
&
mp_type_staticmethod
},
...
...
py/obj.c
View file @
3e1a5c10
...
...
@@ -13,9 +13,9 @@
mp_obj_type_t
*
mp_obj_get_type
(
mp_obj_t
o_in
)
{
if
(
MP_OBJ_IS_SMALL_INT
(
o_in
))
{
return
(
mp_obj_t
)
&
int
_type
;
return
(
mp_obj_t
)
&
mp
_type
_int
;
}
else
if
(
MP_OBJ_IS_QSTR
(
o_in
))
{
return
(
mp_obj_t
)
&
str
_type
;
return
(
mp_obj_t
)
&
mp
_type
_str
;
}
else
{
mp_obj_base_t
*
o
=
o_in
;
return
(
mp_obj_t
)
o
->
type
;
...
...
@@ -81,7 +81,7 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
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
;
}
else
if
(
MP_OBJ_IS_TYPE
(
o_in
,
&
fun_native
_type
)
||
MP_OBJ_IS_TYPE
(
o_in
,
&
fun_bc
_type
))
{
}
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
;
}
else
if
(
MP_OBJ_IS_TYPE
(
o_in
,
&
mp_type_tuple
))
{
return
mp_obj_tuple_hash
(
o_in
);
...
...
@@ -116,7 +116,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
return
val
==
0
;
}
else
if
(
o2
==
mp_const_true
)
{
return
val
==
1
;
}
else
if
(
MP_OBJ_IS_TYPE
(
o2
,
&
int
_type
))
{
}
else
if
(
MP_OBJ_IS_TYPE
(
o2
,
&
mp
_type
_int
))
{
// If o2 is long int, dispatch to its virtual methods
mp_obj_base_t
*
o
=
o2
;
if
(
o
->
type
->
binary_op
!=
NULL
)
{
...
...
@@ -161,7 +161,7 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) {
return
1
;
}
else
if
(
MP_OBJ_IS_SMALL_INT
(
arg
))
{
return
MP_OBJ_SMALL_INT_VALUE
(
arg
);
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
int
_type
))
{
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp
_type
_int
))
{
return
mp_obj_int_get_checked
(
arg
);
}
else
{
nlr_jump
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"can't convert %s to int"
,
mp_obj_get_type_str
(
arg
)));
...
...
@@ -176,7 +176,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
return
1
;
}
else
if
(
MP_OBJ_IS_SMALL_INT
(
arg
))
{
return
MP_OBJ_SMALL_INT_VALUE
(
arg
);
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
int
_type
))
{
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp
_type
_int
))
{
return
mp_obj_int_as_float
(
arg
);
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_float
))
{
return
mp_obj_float_get
(
arg
);
...
...
@@ -209,7 +209,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
void
mp_obj_get_array
(
mp_obj_t
o
,
uint
*
len
,
mp_obj_t
**
items
)
{
if
(
MP_OBJ_IS_TYPE
(
o
,
&
mp_type_tuple
))
{
mp_obj_tuple_get
(
o
,
len
,
items
);
}
else
if
(
MP_OBJ_IS_TYPE
(
o
,
&
list
_type
))
{
}
else
if
(
MP_OBJ_IS_TYPE
(
o
,
&
mp
_type
_list
))
{
mp_obj_list_get
(
o
,
len
,
items
);
}
else
{
nlr_jump
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"object '%s' is not a tuple or list"
,
mp_obj_get_type_str
(
o
)));
...
...
@@ -217,7 +217,7 @@ 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
)
{
if
(
MP_OBJ_IS_TYPE
(
o
,
&
mp_type_tuple
)
||
MP_OBJ_IS_TYPE
(
o
,
&
list
_type
))
{
if
(
MP_OBJ_IS_TYPE
(
o
,
&
mp_type_tuple
)
||
MP_OBJ_IS_TYPE
(
o
,
&
mp
_type
_list
))
{
uint
seq_len
;
if
(
MP_OBJ_IS_TYPE
(
o
,
&
mp_type_tuple
))
{
mp_obj_tuple_get
(
o
,
&
seq_len
,
items
);
...
...
py/obj.h
View file @
3e1a5c10
...
...
@@ -36,8 +36,8 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#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_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, &
int
_type))
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &
str
_type))
#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_NEW_SMALL_INT(small_int) ((mp_obj_t)(((small_int) << 1) | 1))
...
...
@@ -50,7 +50,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name
#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, is_kw, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native
_type
}, is_kw, n_args_min, n_args_max, (void *)fun_name}
#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, is_kw, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&
mp_type_
fun_native}, is_kw, n_args_min, n_args_max, (void *)fun_name}
#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 0, 0, (mp_fun_0_t)fun_name)
#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 1, 1, (mp_fun_1_t)fun_name)
#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 2, 2, (mp_fun_2_t)fun_name)
...
...
@@ -64,7 +64,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#define MP_DEFINE_CONST_DICT(dict_name, table_name) \
const mp_obj_dict_t dict_name = { \
.base = {&
dict
_type}, \
.base = {&
mp
_type
_dict
}, \
.map = { \
.all_keys_are_qstrs = 1, \
.table_is_fixed_array = 1, \
...
...
@@ -197,6 +197,31 @@ typedef struct _mp_obj_type_t mp_obj_type_t;
// Constant types, globally accessible
extern
const
mp_obj_type_t
mp_type_type
;
extern
const
mp_obj_type_t
mp_type_object
;
extern
const
mp_obj_type_t
mp_type_NoneType
;
extern
const
mp_obj_type_t
mp_type_bool
;
extern
const
mp_obj_type_t
mp_type_int
;
extern
const
mp_obj_type_t
mp_type_str
;
extern
const
mp_obj_type_t
mp_type_bytes
;
extern
const
mp_obj_type_t
mp_type_float
;
extern
const
mp_obj_type_t
mp_type_complex
;
extern
const
mp_obj_type_t
mp_type_tuple
;
extern
const
mp_obj_type_t
mp_type_list
;
extern
const
mp_obj_type_t
mp_type_map
;
// map (the python builtin, not the dict implementation detail)
extern
const
mp_obj_type_t
mp_type_enumerate
;
extern
const
mp_obj_type_t
mp_type_filter
;
extern
const
mp_obj_type_t
mp_type_dict
;
extern
const
mp_obj_type_t
mp_type_set
;
extern
const
mp_obj_type_t
mp_type_slice
;
extern
const
mp_obj_type_t
mp_type_zip
;
extern
const
mp_obj_type_t
mp_type_array
;
extern
const
mp_obj_type_t
mp_type_super
;
extern
const
mp_obj_type_t
mp_type_gen_instance
;
extern
const
mp_obj_type_t
mp_type_fun_native
;
extern
const
mp_obj_type_t
mp_type_fun_bc
;
extern
const
mp_obj_type_t
mp_type_module
;
extern
const
mp_obj_type_t
mp_type_staticmethod
;
extern
const
mp_obj_type_t
mp_type_classmethod
;
// Exceptions
extern
const
mp_obj_type_t
mp_type_BaseException
;
...
...
@@ -299,14 +324,7 @@ 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
);
mp_obj_t
mp_obj_len_maybe
(
mp_obj_t
o_in
);
/* may return NULL */
// object
extern
const
mp_obj_type_t
mp_type_object
;
// none
extern
const
mp_obj_type_t
mp_type_NoneType
;
// bool
extern
const
mp_obj_type_t
mp_type_bool
;
#define MP_BOOL(x) (x ? mp_const_true : mp_const_false)
// cell
...
...
@@ -314,7 +332,6 @@ 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
extern
const
mp_obj_type_t
int_type
;
// For long int, returns value truncated to machine_int_t
machine_int_t
mp_obj_int_get
(
mp_obj_t
self_in
);
#if MICROPY_ENABLE_FLOAT
...
...
@@ -333,7 +350,6 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine
mp_obj_t
mp_obj_exception_get_value
(
mp_obj_t
self_in
);
// str
extern
const
mp_obj_type_t
str_type
;
mp_obj_t
mp_obj_str_builder_start
(
const
mp_obj_type_t
*
type
,
uint
len
,
byte
**
data
);
mp_obj_t
mp_obj_str_builder_end
(
mp_obj_t
o_in
);
bool
mp_obj_str_equal
(
mp_obj_t
s1
,
mp_obj_t
s2
);
...
...
@@ -344,66 +360,43 @@ const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need t
const
char
*
mp_obj_str_get_data
(
mp_obj_t
self_in
,
uint
*
len
);
void
mp_str_print_quoted
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
const
byte
*
str_data
,
uint
str_len
);
// bytes
extern
const
mp_obj_type_t
bytes_type
;
#if MICROPY_ENABLE_FLOAT
// float
typedef
struct
_mp_obj_float_t
{
mp_obj_base_t
base
;
mp_float_t
value
;
}
mp_obj_float_t
;
extern
const
mp_obj_type_t
mp_type_float
;
mp_float_t
mp_obj_float_get
(
mp_obj_t
self_in
);
mp_obj_t
mp_obj_float_binary_op
(
int
op
,
mp_float_t
lhs_val
,
mp_obj_t
rhs
);
// complex
extern
const
mp_obj_type_t
mp_type_complex
;
void
mp_obj_complex_get
(
mp_obj_t
self_in
,
mp_float_t
*
real
,
mp_float_t
*
imag
);
mp_obj_t
mp_obj_complex_binary_op
(
int
op
,
mp_float_t
lhs_real
,
mp_float_t
lhs_imag
,
mp_obj_t
rhs_in
);
#endif
// tuple
extern
const
mp_obj_type_t
mp_type_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
);
// list
extern
const
mp_obj_type_t
list_type
;
mp_obj_t
mp_obj_list_append
(
mp_obj_t
self_in
,
mp_obj_t
arg
);
void
mp_obj_list_get
(
mp_obj_t
self_in
,
uint
*
len
,
mp_obj_t
**
items
);
void
mp_obj_list_store
(
mp_obj_t
self_in
,
mp_obj_t
index
,
mp_obj_t
value
);
mp_obj_t
mp_obj_list_sort
(
uint
n_args
,
const
mp_obj_t
*
args
,
struct
_mp_map_t
*
kwargs
);
// map (the python builtin, not the dict implementation detail)
extern
const
mp_obj_type_t
map_type
;
// enumerate
extern
const
mp_obj_type_t
enumerate_type
;
// filter
extern
const
mp_obj_type_t
filter_type
;
// dict
extern
const
mp_obj_type_t
dict_type
;
uint
mp_obj_dict_len
(
mp_obj_t
self_in
);
mp_obj_t
mp_obj_dict_store
(
mp_obj_t
self_in
,
mp_obj_t
key
,
mp_obj_t
value
);
struct
_mp_map_t
*
mp_obj_dict_get_map
(
mp_obj_t
self_in
);
// set
extern
const
mp_obj_type_t
set_type
;
void
mp_obj_set_store
(
mp_obj_t
self_in
,
mp_obj_t
item
);
// slice
extern
const
mp_obj_type_t
slice_type
;
void
mp_obj_slice_get
(
mp_obj_t
self_in
,
machine_int_t
*
start
,
machine_int_t
*
stop
,
machine_int_t
*
step
);
// zip
extern
const
mp_obj_type_t
zip_type
;
// array
extern
const
mp_obj_type_t
mp_type_array
;
uint
mp_obj_array_len
(
mp_obj_t
self_in
);
mp_obj_t
mp_obj_new_bytearray_by_ref
(
uint
n
,
void
*
items
);
...
...
@@ -420,33 +413,20 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object
// such functions won't be able to access the global scope, but that's probably okay
}
mp_obj_fun_native_t
;
extern
const
mp_obj_type_t
fun_native_type
;
extern
const
mp_obj_type_t
fun_bc_type
;
void
mp_obj_fun_bc_get
(
mp_obj_t
self_in
,
int
*
n_args
,
const
byte
**
code
);
mp_obj_t
mp_identity
(
mp_obj_t
self
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_identity_obj
);
// super
extern
const
mp_obj_type_t
super_type
;
// generator
extern
const
mp_obj_type_t
gen_instance_type
;
// module
typedef
struct
_mp_obj_module_t
{
mp_obj_base_t
base
;
qstr
name
;
struct
_mp_map_t
*
globals
;
}
mp_obj_module_t
;
extern
const
mp_obj_type_t
mp_type_module
;
struct
_mp_map_t
*
mp_obj_module_get_globals
(
mp_obj_t
self_in
);
// staticmethod and classmethod types; defined here so we can make const versions
extern
const
mp_obj_type_t
mp_type_staticmethod
;
extern
const
mp_obj_type_t
mp_type_classmethod
;
// this structure is used for instances of both staticmethod and classmethod
typedef
struct
_mp_obj_static_class_method_t
{
mp_obj_base_t
base
;
...
...
py/objdict.c
View file @
3e1a5c10
...
...
@@ -105,7 +105,7 @@ mp_obj_t dict_it_iternext(mp_obj_t self_in) {
}
}
STATIC
const
mp_obj_type_t
dict_it
_type
=
{
STATIC
const
mp_obj_type_t
mp_type_
dict_it
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_iterator
,
.
iternext
=
dict_it_iternext
,
...
...
@@ -113,7 +113,7 @@ STATIC const mp_obj_type_t dict_it_type = {
STATIC
mp_obj_t
mp_obj_new_dict_iterator
(
mp_obj_dict_t
*
dict
,
int
cur
)
{
mp_obj_dict_it_t
*
o
=
m_new_obj
(
mp_obj_dict_it_t
);
o
->
base
.
type
=
&
dict_it
_type
;
o
->
base
.
type
=
&
mp_type_
dict_it
;
o
->
dict
=
dict
;
o
->
cur
=
cur
;
return
o
;
...
...
@@ -127,7 +127,7 @@ STATIC mp_obj_t dict_getiter(mp_obj_t o_in) {
/* dict methods */
STATIC
mp_obj_t
dict_clear
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp
_type
_dict
));
mp_obj_dict_t
*
self
=
self_in
;
mp_map_clear
(
&
self
->
map
);
...
...
@@ -137,7 +137,7 @@ STATIC mp_obj_t dict_clear(mp_obj_t self_in) {
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
dict_clear_obj
,
dict_clear
);
STATIC
mp_obj_t
dict_copy
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp
_type
_dict
));
mp_obj_dict_t
*
self
=
self_in
;
mp_obj_dict_t
*
other
=
mp_obj_new_dict
(
self
->
map
.
alloc
);
other
->
map
.
used
=
self
->
map
.
used
;
...
...
@@ -203,7 +203,7 @@ STATIC mp_obj_t dict_get_helper(mp_map_t *self, mp_obj_t key, mp_obj_t deflt, mp
STATIC
mp_obj_t
dict_get
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
assert
(
2
<=
n_args
&&
n_args
<=
3
);
assert
(
MP_OBJ_IS_TYPE
(
args
[
0
],
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
args
[
0
],
&
mp
_type
_dict
));
return
dict_get_helper
(
&
((
mp_obj_dict_t
*
)
args
[
0
])
->
map
,
args
[
1
],
...
...
@@ -214,7 +214,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_get_obj, 2, 3, dict_get);
STATIC
mp_obj_t
dict_pop
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
assert
(
2
<=
n_args
&&
n_args
<=
3
);
assert
(
MP_OBJ_IS_TYPE
(
args
[
0
],
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
args
[
0
],
&
mp
_type
_dict
));
return
dict_get_helper
(
&
((
mp_obj_dict_t
*
)
args
[
0
])
->
map
,
args
[
1
],
...
...
@@ -226,7 +226,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_pop_obj, 2, 3, dict_pop);
STATIC
mp_obj_t
dict_setdefault
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
assert
(
2
<=
n_args
&&
n_args
<=
3
);
assert
(
MP_OBJ_IS_TYPE
(
args
[
0
],
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
args
[
0
],
&
mp
_type
_dict
));
return
dict_get_helper
(
&
((
mp_obj_dict_t
*
)
args
[
0
])
->
map
,
args
[
1
],
...
...
@@ -237,7 +237,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_setdefault_obj, 2, 3, dict_setde
STATIC
mp_obj_t
dict_popitem
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp
_type
_dict
));
mp_obj_dict_t
*
self
=
self_in
;
if
(
self
->
map
.
used
==
0
)
{
nlr_jump
(
mp_obj_new_exception_msg
(
&
mp_type_KeyError
,
"popitem(): dictionary is empty"
));
...
...
@@ -256,7 +256,7 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) {
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
dict_popitem_obj
,
dict_popitem
);
STATIC
mp_obj_t
dict_update
(
mp_obj_t
self_in
,
mp_obj_t
iterable
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp
_type
_dict
));
mp_obj_dict_t
*
self
=
self_in
;
/* TODO: check for the "keys" method */
mp_obj_t
iter
=
rt_getiter
(
iterable
);
...
...
@@ -394,7 +394,7 @@ mp_obj_t mp_obj_new_dict_view(mp_obj_dict_t *dict, mp_dict_view_kind_t kind) {
}
STATIC
mp_obj_t
dict_view
(
mp_obj_t
self_in
,
mp_dict_view_kind_t
kind
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp
_type
_dict
));
mp_obj_dict_t
*
self
=
self_in
;
return
mp_obj_new_dict_view
(
self
,
kind
);
}
...
...
@@ -433,7 +433,7 @@ STATIC const mp_map_elem_t dict_locals_dict_table[] = {
STATIC
MP_DEFINE_CONST_DICT
(
dict_locals_dict
,
dict_locals_dict_table
);
const
mp_obj_type_t
dict
_type
=
{
const
mp_obj_type_t
mp
_type
_dict
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_dict
,
.
print
=
dict_print
,
...
...
@@ -446,7 +446,7 @@ const mp_obj_type_t dict_type = {
mp_obj_t
mp_obj_new_dict
(
int
n_args
)
{
mp_obj_dict_t
*
o
=
m_new_obj
(
mp_obj_dict_t
);
o
->
base
.
type
=
&
dict
_type
;
o
->
base
.
type
=
&
mp
_type
_dict
;
mp_map_init
(
&
o
->
map
,
n_args
);
return
o
;
}
...
...
@@ -456,14 +456,14 @@ uint mp_obj_dict_len(mp_obj_t self_in) {
}
mp_obj_t
mp_obj_dict_store
(
mp_obj_t
self_in
,
mp_obj_t
key
,
mp_obj_t
value
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp
_type
_dict
));
mp_obj_dict_t
*
self
=
self_in
;
mp_map_lookup
(
&
self
->
map
,
key
,
MP_MAP_LOOKUP_ADD_IF_NOT_FOUND
)
->
value
=
value
;
return
self_in
;
}
mp_map_t
*
mp_obj_dict_get_map
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
dict
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp
_type
_dict
));
mp_obj_dict_t
*
self
=
self_in
;
return
&
self
->
map
;
}
py/objenumerate.c
View file @
3e1a5c10
...
...
@@ -20,13 +20,13 @@ STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in);
STATIC
mp_obj_t
enumerate_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
assert
(
n_args
>
0
);
mp_obj_enumerate_t
*
o
=
m_new_obj
(
mp_obj_enumerate_t
);
o
->
base
.
type
=
&
enumerate
_type
;
o
->
base
.
type
=
&
mp_type_
enumerate
;
o
->
iter
=
rt_getiter
(
args
[
0
]);
o
->
cur
=
n_args
>
1
?
mp_obj_get_int
(
args
[
1
])
:
0
;
return
o
;
}
const
mp_obj_type_t
enumerate
_type
=
{
const
mp_obj_type_t
mp_type_
enumerate
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_enumerate
,
.
make_new
=
enumerate_make_new
,
...
...
@@ -35,7 +35,7 @@ const mp_obj_type_t enumerate_type = {
};
STATIC
mp_obj_t
enumerate_iternext
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
enumerate
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp_type_
enumerate
));
mp_obj_enumerate_t
*
self
=
self_in
;
mp_obj_t
next
=
rt_iternext
(
self
->
iter
);
if
(
next
==
MP_OBJ_NULL
)
{
...
...
py/objfilter.c
View file @
3e1a5c10
...
...
@@ -20,14 +20,14 @@ STATIC mp_obj_t filter_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
}
assert
(
n_args
==
2
);
mp_obj_filter_t
*
o
=
m_new_obj
(
mp_obj_filter_t
);
o
->
base
.
type
=
&
filter
_type
;
o
->
base
.
type
=
&
mp_type_
filter
;
o
->
fun
=
args
[
0
];
o
->
iter
=
rt_getiter
(
args
[
1
]);
return
o
;
}
STATIC
mp_obj_t
filter_iternext
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
filter
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp_type_
filter
));
mp_obj_filter_t
*
self
=
self_in
;
mp_obj_t
next
;
while
((
next
=
rt_iternext
(
self
->
iter
))
!=
MP_OBJ_NULL
)
{
...
...
@@ -44,7 +44,7 @@ STATIC mp_obj_t filter_iternext(mp_obj_t self_in) {
return
MP_OBJ_NULL
;
}
const
mp_obj_type_t
filter
_type
=
{
const
mp_obj_type_t
mp_type_
filter
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_filter
,
.
make_new
=
filter_make_new
,
...
...
py/objfun.c
View file @
3e1a5c10
...
...
@@ -55,7 +55,7 @@ void rt_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args
}
STATIC
mp_obj_t
fun_native_call
(
mp_obj_t
self_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
fun_native
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp_type_
fun_native
));
mp_obj_fun_native_t
*
self
=
self_in
;
// check number of arguments
...
...
@@ -99,7 +99,7 @@ STATIC mp_obj_t fun_native_call(mp_obj_t self_in, uint n_args, uint n_kw, const
}
}
const
mp_obj_type_t
fun_native
_type
=
{
const
mp_obj_type_t
mp_type_
fun_native
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_function
,
.
call
=
fun_native_call
,
...
...
@@ -108,7 +108,7 @@ const mp_obj_type_t fun_native_type = {
// fun must have the correct signature for n_args fixed arguments
mp_obj_t
rt_make_function_n
(
int
n_args
,
void
*
fun
)
{
mp_obj_fun_native_t
*
o
=
m_new_obj
(
mp_obj_fun_native_t
);
o
->
base
.
type
=
&
fun_native
_type
;
o
->
base
.
type
=
&
mp_type_
fun_native
;
o
->
is_kw
=
false
;
o
->
n_args_min
=
n_args
;
o
->
n_args_max
=
n_args
;
...
...
@@ -118,7 +118,7 @@ mp_obj_t rt_make_function_n(int n_args, void *fun) {
mp_obj_t
rt_make_function_var
(
int
n_args_min
,
mp_fun_var_t
fun
)
{
mp_obj_fun_native_t
*
o
=
m_new_obj
(
mp_obj_fun_native_t
);
o
->
base
.
type
=
&
fun_native
_type
;
o
->
base
.
type
=
&
mp_type_
fun_native
;
o
->
is_kw
=
false
;
o
->
n_args_min
=
n_args_min
;
o
->
n_args_max
=
MP_OBJ_FUN_ARGS_MAX
;
...
...
@@ -129,7 +129,7 @@ mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun) {
// min and max are inclusive
mp_obj_t
rt_make_function_var_between
(
int
n_args_min
,
int
n_args_max
,
mp_fun_var_t
fun
)
{
mp_obj_fun_native_t
*
o
=
m_new_obj
(
mp_obj_fun_native_t
);
o
->
base
.
type
=
&
fun_native
_type
;
o
->
base
.
type
=
&
mp_type_
fun_native
;
o
->
is_kw
=
false
;
o
->
n_args_min
=
n_args_min
;
o
->
n_args_max
=
n_args_max
;
...
...
@@ -297,7 +297,7 @@ arg_error:
nlr_jump
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"function takes %d positional arguments but %d were given"
,
self
->
n_args
,
n_args
));
}
const
mp_obj_type_t
fun_bc
_type
=
{
const
mp_obj_type_t
mp_type_
fun_bc
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_function
,
.
call
=
fun_bc_call
,
...
...
@@ -318,7 +318,7 @@ mp_obj_t mp_obj_new_fun_bc(uint scope_flags, qstr *args, uint n_args, mp_obj_t d
n_extra_args
+=
1
;
}
mp_obj_fun_bc_t
*
o
=
m_new_obj_var
(
mp_obj_fun_bc_t
,
mp_obj_t
,
n_extra_args
);
o
->
base
.
type
=
&
fun_bc
_type
;
o
->
base
.
type
=
&
mp_type_
fun_bc
;
o
->
globals
=
rt_globals_get
();
o
->
args
=
args
;
o
->
n_args
=
n_args
;
...
...
@@ -333,7 +333,7 @@ mp_obj_t mp_obj_new_fun_bc(uint scope_flags, qstr *args, uint n_args, mp_obj_t d
}
void
mp_obj_fun_bc_get
(
mp_obj_t
self_in
,
int
*
n_args
,
const
byte
**
code
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
fun_bc
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp_type_
fun_bc
));
mp_obj_fun_bc_t
*
self
=
self_in
;
*
n_args
=
self
->
n_args
;
*
code
=
self
->
bytecode
;
...
...
@@ -379,7 +379,7 @@ STATIC machine_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
mp_obj_t
*
items
;
mp_obj_tuple_get
(
obj
,
&
len
,
&
items
);
return
(
machine_uint_t
)
items
;
}
else
if
(
MP_OBJ_IS_TYPE
(
obj
,
&
list
_type
))
{
}
else
if
(
MP_OBJ_IS_TYPE
(
obj
,
&
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
;
...
...
@@ -423,7 +423,7 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_
return
convert_val_from_inline_asm
(
ret
);
}
STATIC
const
mp_obj_type_t
fun_asm
_type
=
{
STATIC
const
mp_obj_type_t
mp_type_
fun_asm
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_function
,
.
call
=
fun_asm_call
,
...
...
@@ -431,7 +431,7 @@ STATIC const mp_obj_type_t fun_asm_type = {
mp_obj_t
mp_obj_new_fun_asm
(
uint
n_args
,
void
*
fun
)
{
mp_obj_fun_asm_t
*
o
=
m_new_obj
(
mp_obj_fun_asm_t
);
o
->
base
.
type
=
&
fun_asm
_type
;
o
->
base
.
type
=
&
mp_type_
fun_asm
;
o
->
n_args
=
n_args
;
o
->
fun
=
fun
;
return
o
;
...
...
py/objgenerator.c
View file @
3e1a5c10
...
...
@@ -22,7 +22,7 @@ typedef struct _mp_obj_gen_wrap_t {
STATIC
mp_obj_t
gen_wrap_call
(
mp_obj_t
self_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
mp_obj_gen_wrap_t
*
self
=
self_in
;
mp_obj_t
self_fun
=
self
->
fun
;
assert
(
MP_OBJ_IS_TYPE
(
self_fun
,
&
fun_bc
_type
));
assert
(
MP_OBJ_IS_TYPE
(
self_fun
,
&
mp_type_
fun_bc
));
int
bc_n_args
;
const
byte
*
bc_code
;
mp_obj_fun_bc_get
(
self_fun
,
&
bc_n_args
,
&
bc_code
);
...
...
@@ -36,7 +36,7 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp
return
mp_obj_new_gen_instance
(
bc_code
,
n_args
,
args
);
}
const
mp_obj_type_t
gen_wrap
_type
=
{
const
mp_obj_type_t
mp_type_
gen_wrap
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_generator
,
.
call
=
gen_wrap_call
,
...
...
@@ -44,7 +44,7 @@ const mp_obj_type_t gen_wrap_type = {
mp_obj_t
mp_obj_new_gen_wrap
(
mp_obj_t
fun
)
{
mp_obj_gen_wrap_t
*
o
=
m_new_obj
(
mp_obj_gen_wrap_t
);
o
->
base
.
type
=
&
gen_wrap
_type
;
o
->
base
.
type
=
&
mp_type_
gen_wrap
;
o
->
fun
=
fun
;
return
o
;
}
...
...
@@ -200,7 +200,7 @@ STATIC const mp_map_elem_t gen_instance_locals_dict_table[] = {
STATIC
MP_DEFINE_CONST_DICT
(
gen_instance_locals_dict
,
gen_instance_locals_dict_table
);
const
mp_obj_type_t
gen_instance
_type
=
{
const
mp_obj_type_t
mp_type_
gen_instance
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_generator
,
.
print
=
gen_instance_print
,
...
...
@@ -227,7 +227,7 @@ mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, int n_args, const mp_obj_
bytecode
+=
1
;
mp_obj_gen_instance_t
*
o
=
m_new_obj_var
(
mp_obj_gen_instance_t
,
byte
,
n_state
*
sizeof
(
mp_obj_t
)
+
n_exc_stack
*
sizeof
(
mp_exc_stack
));
o
->
base
.
type
=
&
gen_instance
_type
;
o
->
base
.
type
=
&
mp_type_
gen_instance
;
o
->
code_info
=
bytecode
;
o
->
ip
=
bytecode
;
o
->
sp
=
&
o
->
state
[
0
]
-
1
;
// sp points to top of stack, which starts off 1 below the state
...
...