Remove mp_obj_type_t.methods entry and use .locals_dict instead.
Originally, .methods was used for methods in a ROM class, and locals_dict for methods in a user-created class. That distinction is unnecessary, and we can use locals_dict for ROM classes now that we have ROMable maps. This removes an entry in the bloated mp_obj_type_t struct, saving a word for each ROM object and each RAM object. ROM objects that have a methods table (now a locals_dict) need an extra word in total (removed the methods pointer (1 word), no longer need the sentinel (2 words), but now need an mp_obj_dict_t wrapper (4 words)). But RAM objects save a word because they never used the methods entry. Overall the ROM usage is down by a few hundred bytes, and RAM usage is down 1 word per user-defined type/class. There is less code (no need to check 2 tables), and now consistent with the way ROM modules have their tables initialised. Efficiency is very close to equivaluent.
This commit is contained in:
parent
c12b2213c1
commit
9b196cddab
10
py/builtin.c
10
py/builtin.c
@ -152,7 +152,6 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
|
||||
// TODO make this function more general and less of a hack
|
||||
|
||||
mp_map_t *map = NULL;
|
||||
const mp_method_t *meth = NULL;
|
||||
if (n_args == 0) {
|
||||
// make a list of names in the local name space
|
||||
map = rt_locals_get();
|
||||
@ -164,9 +163,6 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
|
||||
} else if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)) {
|
||||
map = mp_obj_dict_get_map(type->locals_dict);
|
||||
}
|
||||
if (type->methods != NULL) {
|
||||
meth = type->methods;
|
||||
}
|
||||
}
|
||||
|
||||
mp_obj_t dir = mp_obj_new_list(0, NULL);
|
||||
@ -177,11 +173,7 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meth != NULL) {
|
||||
for (; meth->name != MP_QSTR_NULL; meth++) {
|
||||
mp_obj_list_append(dir, MP_OBJ_NEW_QSTR(meth->name));
|
||||
}
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
5
py/map.h
5
py/map.h
@ -24,6 +24,11 @@ typedef enum _mp_map_lookup_kind_t {
|
||||
MP_MAP_LOOKUP_FIRST = 4,
|
||||
} mp_map_lookup_kind_t;
|
||||
|
||||
typedef struct _mp_obj_dict_t {
|
||||
mp_obj_base_t base;
|
||||
mp_map_t map;
|
||||
} mp_obj_dict_t;
|
||||
|
||||
int get_doubling_prime_greater_or_equal_to(int x);
|
||||
void mp_map_init(mp_map_t *map, int n);
|
||||
void mp_map_init_fixed_table(mp_map_t *map, int n, const mp_obj_t *table);
|
||||
|
17
py/obj.h
17
py/obj.h
@ -59,6 +59,21 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, n_args_min, n_args_max, (mp_fun_var_t)fun_name)
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, true, n_args_min, MP_OBJ_FUN_ARGS_MAX, (mp_fun_kw_t)fun_name)
|
||||
|
||||
// This macro is used to define constant dict objects
|
||||
// You can put "static" in front of the definition to make it local
|
||||
|
||||
#define MP_DEFINE_CONST_DICT(dict_name, table_name) \
|
||||
const mp_obj_dict_t dict_name = { \
|
||||
.base = {&dict_type}, \
|
||||
.map = { \
|
||||
.all_keys_are_qstrs = 1, \
|
||||
.table_is_fixed_array = 1, \
|
||||
.used = sizeof(table_name) / sizeof(mp_map_elem_t), \
|
||||
.alloc = sizeof(table_name) / sizeof(mp_map_elem_t), \
|
||||
.table = (mp_map_elem_t*)table_name, \
|
||||
}, \
|
||||
}
|
||||
|
||||
// These macros are used to declare and define constant staticmethond and classmethod objects
|
||||
// You can put "static" in front of the definitions to make them local
|
||||
|
||||
@ -160,8 +175,6 @@ struct _mp_obj_type_t {
|
||||
mp_buffer_p_t buffer_p;
|
||||
mp_stream_p_t stream_p;
|
||||
|
||||
const mp_method_t *methods;
|
||||
|
||||
// these are for dynamically created types (classes)
|
||||
mp_obj_t bases_tuple;
|
||||
mp_obj_t locals_dict;
|
||||
|
@ -149,11 +149,12 @@ STATIC machine_int_t array_get_buffer(mp_obj_t o_in, buffer_info_t *bufinfo, int
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC const mp_method_t array_type_methods[] = {
|
||||
{ MP_QSTR_append, &array_append_obj },
|
||||
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
|
||||
STATIC const mp_map_elem_t array_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_append), (mp_obj_t)&array_append_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(array_locals_dict, array_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t mp_type_array = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_array,
|
||||
@ -163,8 +164,8 @@ const mp_obj_type_t mp_type_array = {
|
||||
.unary_op = array_unary_op,
|
||||
.binary_op = array_binary_op,
|
||||
.store_item = array_store_item,
|
||||
.methods = array_type_methods,
|
||||
.buffer_p = { .get_buffer = array_get_buffer },
|
||||
.locals_dict = (mp_obj_t)&array_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_array_t *array_new(char typecode, uint n) {
|
||||
|
37
py/objdict.c
37
py/objdict.c
@ -7,14 +7,9 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime0.h"
|
||||
#include "runtime.h"
|
||||
#include "map.h"
|
||||
|
||||
typedef struct _mp_obj_dict_t {
|
||||
mp_obj_base_t base;
|
||||
mp_map_t map;
|
||||
} mp_obj_dict_t;
|
||||
|
||||
STATIC mp_obj_t mp_obj_new_dict_iterator(mp_obj_dict_t *dict, int cur);
|
||||
STATIC mp_map_elem_t *dict_it_iternext_elem(mp_obj_t self_in);
|
||||
@ -343,7 +338,6 @@ STATIC const mp_obj_type_t dict_view_it_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_iterator,
|
||||
.iternext = dict_view_it_iternext,
|
||||
.methods = NULL, /* set operations still to come */
|
||||
};
|
||||
|
||||
STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in) {
|
||||
@ -423,21 +417,22 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_values_obj, dict_values);
|
||||
/******************************************************************************/
|
||||
/* dict constructors & public C API */
|
||||
|
||||
STATIC const mp_method_t dict_type_methods[] = {
|
||||
{ MP_QSTR_clear, &dict_clear_obj },
|
||||
{ MP_QSTR_copy, &dict_copy_obj },
|
||||
{ MP_QSTR_fromkeys, &dict_fromkeys_obj },
|
||||
{ MP_QSTR_get, &dict_get_obj },
|
||||
{ MP_QSTR_items, &dict_items_obj },
|
||||
{ MP_QSTR_keys, &dict_keys_obj },
|
||||
{ MP_QSTR_pop, &dict_pop_obj },
|
||||
{ MP_QSTR_popitem, &dict_popitem_obj },
|
||||
{ MP_QSTR_setdefault, &dict_setdefault_obj },
|
||||
{ MP_QSTR_update, &dict_update_obj },
|
||||
{ MP_QSTR_values, &dict_values_obj },
|
||||
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
|
||||
STATIC const mp_map_elem_t dict_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_clear), (mp_obj_t)&dict_clear_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_copy), (mp_obj_t)&dict_copy_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_fromkeys), (mp_obj_t)&dict_fromkeys_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_get), (mp_obj_t)&dict_get_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_items), (mp_obj_t)&dict_items_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_keys), (mp_obj_t)&dict_keys_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pop), (mp_obj_t)&dict_pop_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_popitem), (mp_obj_t)&dict_popitem_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_setdefault), (mp_obj_t)&dict_setdefault_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_update), (mp_obj_t)&dict_update_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_values), (mp_obj_t)&dict_values_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t dict_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_dict,
|
||||
@ -446,7 +441,7 @@ const mp_obj_type_t dict_type = {
|
||||
.unary_op = dict_unary_op,
|
||||
.binary_op = dict_binary_op,
|
||||
.getiter = dict_getiter,
|
||||
.methods = dict_type_methods,
|
||||
.locals_dict = (mp_obj_t)&dict_locals_dict,
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_dict(int n_args) {
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "bc.h"
|
||||
#include "objgenerator.h"
|
||||
@ -192,20 +193,21 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) {
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_close_obj, gen_instance_close);
|
||||
|
||||
STATIC const mp_method_t gen_type_methods[] = {
|
||||
{ MP_QSTR_close, &gen_instance_close_obj },
|
||||
{ MP_QSTR_send, &gen_instance_send_obj },
|
||||
{ MP_QSTR_throw, &gen_instance_throw_obj },
|
||||
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
|
||||
STATIC const mp_map_elem_t gen_instance_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&gen_instance_close_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&gen_instance_send_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_throw), (mp_obj_t)&gen_instance_throw_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t gen_instance_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_generator,
|
||||
.print = gen_instance_print,
|
||||
.getiter = gen_instance_getiter,
|
||||
.iternext = gen_instance_iternext,
|
||||
.methods = gen_type_methods,
|
||||
.locals_dict = (mp_obj_t)&gen_instance_locals_dict,
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, uint n_state, int n_args, const mp_obj_t *args) {
|
||||
|
29
py/objlist.c
29
py/objlist.c
@ -328,21 +328,22 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, list_remove);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 0, mp_obj_list_sort);
|
||||
|
||||
STATIC const mp_method_t list_type_methods[] = {
|
||||
{ MP_QSTR_append, &list_append_obj },
|
||||
{ MP_QSTR_clear, &list_clear_obj },
|
||||
{ MP_QSTR_copy, &list_copy_obj },
|
||||
{ MP_QSTR_count, &list_count_obj },
|
||||
{ MP_QSTR_extend, &list_extend_obj },
|
||||
{ MP_QSTR_index, &list_index_obj },
|
||||
{ MP_QSTR_insert, &list_insert_obj },
|
||||
{ MP_QSTR_pop, &list_pop_obj },
|
||||
{ MP_QSTR_remove, &list_remove_obj },
|
||||
{ MP_QSTR_reverse, &list_reverse_obj },
|
||||
{ MP_QSTR_sort, &list_sort_obj },
|
||||
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
|
||||
STATIC const mp_map_elem_t list_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_append), (mp_obj_t)&list_append_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_clear), (mp_obj_t)&list_clear_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_copy), (mp_obj_t)&list_copy_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_count), (mp_obj_t)&list_count_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_extend), (mp_obj_t)&list_extend_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_index), (mp_obj_t)&list_index_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_insert), (mp_obj_t)&list_insert_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pop), (mp_obj_t)&list_pop_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_remove), (mp_obj_t)&list_remove_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_reverse), (mp_obj_t)&list_reverse_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_sort), (mp_obj_t)&list_sort_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t list_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_list,
|
||||
@ -351,7 +352,7 @@ const mp_obj_type_t list_type = {
|
||||
.unary_op = list_unary_op,
|
||||
.binary_op = list_binary_op,
|
||||
.getiter = list_getiter,
|
||||
.methods = list_type_methods,
|
||||
.locals_dict = (mp_obj_t)&list_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_list_t *list_new(uint n) {
|
||||
|
41
py/objset.c
41
py/objset.c
@ -423,27 +423,28 @@ STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
|
||||
/* set constructors & public C API */
|
||||
|
||||
|
||||
STATIC const mp_method_t set_type_methods[] = {
|
||||
{ MP_QSTR_add, &set_add_obj },
|
||||
{ MP_QSTR_clear, &set_clear_obj },
|
||||
{ MP_QSTR_copy, &set_copy_obj },
|
||||
{ MP_QSTR_discard, &set_discard_obj },
|
||||
{ MP_QSTR_difference, &set_diff_obj },
|
||||
{ MP_QSTR_difference_update, &set_diff_update_obj },
|
||||
{ MP_QSTR_intersection, &set_intersect_obj },
|
||||
{ MP_QSTR_intersection_update, &set_intersect_update_obj },
|
||||
{ MP_QSTR_isdisjoint, &set_isdisjoint_obj },
|
||||
{ MP_QSTR_issubset, &set_issubset_obj },
|
||||
{ MP_QSTR_issuperset, &set_issuperset_obj },
|
||||
{ MP_QSTR_pop, &set_pop_obj },
|
||||
{ MP_QSTR_remove, &set_remove_obj },
|
||||
{ MP_QSTR_symmetric_difference, &set_symmetric_difference_obj },
|
||||
{ MP_QSTR_symmetric_difference_update, &set_symmetric_difference_update_obj },
|
||||
{ MP_QSTR_union, &set_union_obj },
|
||||
{ MP_QSTR_update, &set_update_obj },
|
||||
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
|
||||
STATIC const mp_map_elem_t set_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_add), (mp_obj_t)&set_add_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_clear), (mp_obj_t)&set_clear_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_copy), (mp_obj_t)&set_copy_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_discard), (mp_obj_t)&set_discard_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_difference), (mp_obj_t)&set_diff_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_difference_update), (mp_obj_t)&set_diff_update_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_intersection), (mp_obj_t)&set_intersect_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_intersection_update), (mp_obj_t)&set_intersect_update_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_isdisjoint), (mp_obj_t)&set_isdisjoint_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_issubset), (mp_obj_t)&set_issubset_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_issuperset), (mp_obj_t)&set_issuperset_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pop), (mp_obj_t)&set_pop_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_remove), (mp_obj_t)&set_remove_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_symmetric_difference), (mp_obj_t)&set_symmetric_difference_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_symmetric_difference_update), (mp_obj_t)&set_symmetric_difference_update_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_union), (mp_obj_t)&set_union_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_update), (mp_obj_t)&set_update_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t set_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_set,
|
||||
@ -451,7 +452,7 @@ const mp_obj_type_t set_type = {
|
||||
.make_new = set_make_new,
|
||||
.binary_op = set_binary_op,
|
||||
.getiter = set_getiter,
|
||||
.methods = set_type_methods,
|
||||
.locals_dict = (mp_obj_t)&set_locals_dict,
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) {
|
||||
|
32
py/objstr.c
32
py/objstr.c
@ -7,6 +7,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime0.h"
|
||||
#include "runtime.h"
|
||||
|
||||
@ -693,21 +694,22 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_count_obj, 2, 4, str_count);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(str_partition_obj, str_partition);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(str_rpartition_obj, str_rpartition);
|
||||
|
||||
STATIC const mp_method_t str_type_methods[] = {
|
||||
{ MP_QSTR_find, &str_find_obj },
|
||||
{ MP_QSTR_rfind, &str_rfind_obj },
|
||||
{ MP_QSTR_join, &str_join_obj },
|
||||
{ MP_QSTR_split, &str_split_obj },
|
||||
{ MP_QSTR_startswith, &str_startswith_obj },
|
||||
{ MP_QSTR_strip, &str_strip_obj },
|
||||
{ MP_QSTR_format, &str_format_obj },
|
||||
{ MP_QSTR_replace, &str_replace_obj },
|
||||
{ MP_QSTR_count, &str_count_obj },
|
||||
{ MP_QSTR_partition, &str_partition_obj },
|
||||
{ MP_QSTR_rpartition, &str_rpartition_obj },
|
||||
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
|
||||
STATIC const mp_map_elem_t str_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_find), (mp_obj_t)&str_find_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_rfind), (mp_obj_t)&str_rfind_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_join), (mp_obj_t)&str_join_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_split), (mp_obj_t)&str_split_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_startswith), (mp_obj_t)&str_startswith_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_strip), (mp_obj_t)&str_strip_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_format), (mp_obj_t)&str_format_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_replace), (mp_obj_t)&str_replace_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_count), (mp_obj_t)&str_count_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_partition), (mp_obj_t)&str_partition_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_rpartition), (mp_obj_t)&str_rpartition_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(str_locals_dict, str_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t str_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_str,
|
||||
@ -715,8 +717,8 @@ const mp_obj_type_t str_type = {
|
||||
.make_new = str_make_new,
|
||||
.binary_op = str_binary_op,
|
||||
.getiter = mp_obj_new_str_iterator,
|
||||
.methods = str_type_methods,
|
||||
.buffer_p = { .get_buffer = str_get_buffer },
|
||||
.locals_dict = (mp_obj_t)&str_locals_dict,
|
||||
};
|
||||
|
||||
// Reuses most of methods from str
|
||||
@ -727,7 +729,7 @@ const mp_obj_type_t bytes_type = {
|
||||
.make_new = bytes_make_new,
|
||||
.binary_op = str_binary_op,
|
||||
.getiter = mp_obj_new_bytes_iterator,
|
||||
.methods = str_type_methods,
|
||||
.locals_dict = (mp_obj_t)&str_locals_dict,
|
||||
};
|
||||
|
||||
// the zero-length bytes
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime0.h"
|
||||
#include "runtime.h"
|
||||
#include "objtuple.h"
|
||||
@ -165,12 +166,13 @@ STATIC mp_obj_t tuple_index(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index);
|
||||
|
||||
STATIC const mp_method_t tuple_type_methods[] = {
|
||||
{ MP_QSTR_count, &tuple_count_obj },
|
||||
{ MP_QSTR_index, &tuple_index_obj },
|
||||
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
|
||||
STATIC const mp_map_elem_t tuple_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_count), (mp_obj_t)&tuple_count_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_index), (mp_obj_t)&tuple_index_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(tuple_locals_dict, tuple_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t tuple_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_tuple,
|
||||
@ -179,7 +181,7 @@ const mp_obj_type_t tuple_type = {
|
||||
.unary_op = tuple_unary_op,
|
||||
.binary_op = tuple_binary_op,
|
||||
.getiter = tuple_getiter,
|
||||
.methods = tuple_type_methods,
|
||||
.locals_dict = (mp_obj_t)&tuple_locals_dict,
|
||||
};
|
||||
|
||||
// the zero-length tuple
|
||||
|
@ -38,6 +38,7 @@ STATIC mp_obj_t mp_obj_class_lookup(const mp_obj_type_t *type, qstr attr) {
|
||||
if (elem != NULL) {
|
||||
return elem->value;
|
||||
}
|
||||
/*
|
||||
} else if (type->methods != NULL) {
|
||||
// search methods (the const set of methods)
|
||||
|
||||
@ -46,6 +47,7 @@ STATIC mp_obj_t mp_obj_class_lookup(const mp_obj_type_t *type, qstr attr) {
|
||||
return (mp_obj_t)meth->fun;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// attribute not found, keep searching base classes
|
||||
|
37
py/runtime.c
37
py/runtime.c
@ -845,25 +845,24 @@ STATIC void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
|
||||
} else if (type->load_attr == NULL) {
|
||||
// generic method lookup if type didn't provide a specific one
|
||||
// this is a lookup in the object (ie not class or type)
|
||||
const mp_method_t *meth = type->methods;
|
||||
if (meth != NULL) {
|
||||
for (; meth->name != MP_QSTR_NULL; meth++) {
|
||||
if (meth->name == attr) {
|
||||
// check if the methods are functions, static or class methods
|
||||
// see http://docs.python.org/3.3/howto/descriptor.html
|
||||
if (MP_OBJ_IS_TYPE(meth->fun, &mp_type_staticmethod)) {
|
||||
// return just the function
|
||||
dest[0] = ((mp_obj_static_class_method_t*)meth->fun)->fun;
|
||||
} else if (MP_OBJ_IS_TYPE(meth->fun, &mp_type_classmethod)) {
|
||||
// return a bound method, with self being the type of this object
|
||||
dest[0] = ((mp_obj_static_class_method_t*)meth->fun)->fun;
|
||||
dest[1] = mp_obj_get_type(base);
|
||||
} else {
|
||||
// return a bound method, with self being this object
|
||||
dest[0] = (mp_obj_t)meth->fun;
|
||||
dest[1] = base;
|
||||
}
|
||||
break;
|
||||
if (type->locals_dict != NULL) {
|
||||
assert(MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)); // Micro Python restriction, for now
|
||||
mp_map_t *locals_map = mp_obj_dict_get_map(type->locals_dict);
|
||||
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
|
||||
if (elem != NULL) {
|
||||
// check if the methods are functions, static or class methods
|
||||
// see http://docs.python.org/3.3/howto/descriptor.html
|
||||
if (MP_OBJ_IS_TYPE(elem->value, &mp_type_staticmethod)) {
|
||||
// return just the function
|
||||
dest[0] = ((mp_obj_static_class_method_t*)elem->value)->fun;
|
||||
} else if (MP_OBJ_IS_TYPE(elem->value, &mp_type_classmethod)) {
|
||||
// return a bound method, with self being the type of this object
|
||||
dest[0] = ((mp_obj_static_class_method_t*)elem->value)->fun;
|
||||
dest[1] = mp_obj_get_type(base);
|
||||
} else {
|
||||
// return a bound method, with self being this object
|
||||
dest[0] = (mp_obj_t)elem->value;
|
||||
dest[1] = base;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
stm/adc.c
25
stm/adc.c
@ -6,6 +6,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "adc.h"
|
||||
|
||||
/* ADC defintions */
|
||||
@ -323,19 +324,20 @@ static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_temp_obj, adc_all_read_core_t
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vbat_obj, adc_all_read_core_vbat);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vref_obj, adc_all_read_core_vref);
|
||||
|
||||
static const mp_method_t adc_all_methods[] = {
|
||||
{ MP_QSTR_read_channel, &adc_all_read_channel_obj},
|
||||
{ MP_QSTR_read_core_temp, &adc_all_read_core_temp_obj},
|
||||
{ MP_QSTR_read_core_vbat, &adc_all_read_core_vbat_obj},
|
||||
{ MP_QSTR_read_core_vref, &adc_all_read_core_vref_obj},
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t adc_all_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read_channel), (mp_obj_t) &adc_all_read_channel_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read_core_temp), (mp_obj_t)&adc_all_read_core_temp_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read_core_vbat), (mp_obj_t)&adc_all_read_core_vbat_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read_core_vref), (mp_obj_t)&adc_all_read_core_vref_obj},
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(adc_all_locals_dict, adc_all_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t adc_all_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_ADC,
|
||||
.print = adc_all_print,
|
||||
.methods = adc_all_methods,
|
||||
.locals_dict = (mp_obj_t)&adc_all_locals_dict,
|
||||
};
|
||||
|
||||
mp_obj_t pyb_ADC_all(mp_obj_t resolution) {
|
||||
@ -380,16 +382,17 @@ static mp_obj_t adc_read(mp_obj_t self_in) {
|
||||
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read);
|
||||
|
||||
static const mp_method_t adc_methods[] = {
|
||||
{ MP_QSTR_read, &adc_read_obj},
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t adc_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&adc_read_obj},
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t adc_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_ADC,
|
||||
.print = adc_print,
|
||||
.methods = adc_methods,
|
||||
.locals_dict = (mp_obj_t)&adc_locals_dict,
|
||||
};
|
||||
|
||||
mp_obj_t pyb_ADC(mp_obj_t pin_name_obj) {
|
||||
|
15
stm/audio.c
15
stm/audio.c
@ -193,18 +193,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_audio_triangle_obj, pyb_audio_triangle);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_audio_dac_obj, pyb_audio_dac);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_audio_dma_obj, 3, pyb_audio_dma);
|
||||
|
||||
STATIC const mp_method_t pyb_audio_methods[] = {
|
||||
{ MP_QSTR_noise, &pyb_audio_noise_obj },
|
||||
{ MP_QSTR_triangle, &pyb_audio_triangle_obj },
|
||||
{ MP_QSTR_dac, &pyb_audio_dac_obj },
|
||||
{ MP_QSTR_dma, &pyb_audio_dma_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t pyb_audio_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_noise), (mp_obj_t)&pyb_audio_noise_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_triangle), (mp_obj_t)&pyb_audio_triangle_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_dac), (mp_obj_t)&pyb_audio_dac_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_dma), (mp_obj_t)&pyb_audio_dma_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_audio_locals_dict, pyb_audio_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t pyb_audio_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_,
|
||||
.methods = pyb_audio_methods,
|
||||
.locals_dict = (mp_obj_t)&pyb_audio_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const pyb_audio_t pyb_audio_channel_1 = {{&pyb_audio_type}, DAC_Channel_1, DMA1_Stream5};
|
||||
|
16
stm/exti.c
16
stm/exti.c
@ -9,6 +9,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "nlr.h"
|
||||
|
||||
@ -226,14 +227,15 @@ static MP_DEFINE_CONST_FUN_OBJ_1(exti_obj_enable_obj, exti_obj_enable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(exti_obj_disable_obj, exti_obj_disable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(exti_obj_swint_obj, exti_obj_swint);
|
||||
|
||||
static const mp_method_t exti_methods[] = {
|
||||
{ MP_QSTR_line, &exti_obj_line_obj },
|
||||
{ MP_QSTR_enable, &exti_obj_enable_obj },
|
||||
{ MP_QSTR_disable, &exti_obj_disable_obj },
|
||||
{ MP_QSTR_swint, &exti_obj_swint_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t exti_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_line), (mp_obj_t) &exti_obj_line_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t) &exti_obj_enable_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t) &exti_obj_disable_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_swint), (mp_obj_t) &exti_obj_swint_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(exti_locals_dict, exti_locals_dict_table);
|
||||
|
||||
static mp_obj_t exti_regs(void) {
|
||||
printf("EXTI_IMR %08lx\n", EXTI->IMR);
|
||||
printf("EXTI_EMR %08lx\n", EXTI->EMR);
|
||||
@ -317,7 +319,7 @@ const mp_obj_type_t exti_obj_type = {
|
||||
{ &exti_meta_obj_type },
|
||||
.name = MP_QSTR_Exti,
|
||||
.print = exti_obj_print,
|
||||
.methods = exti_methods,
|
||||
.locals_dict = (mp_obj_t)&exti_locals_dict,
|
||||
};
|
||||
|
||||
void exti_init(void) {
|
||||
|
14
stm/file.c
14
stm/file.c
@ -5,6 +5,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "file.h"
|
||||
#include "ff.h"
|
||||
|
||||
@ -52,18 +53,19 @@ static MP_DEFINE_CONST_FUN_OBJ_1(file_obj_close_obj, file_obj_close);
|
||||
|
||||
// TODO gc hook to close the file if not already closed
|
||||
|
||||
static const mp_method_t file_methods[] = {
|
||||
{ MP_QSTR_read, &file_obj_read_obj },
|
||||
{ MP_QSTR_write, &file_obj_write_obj },
|
||||
{ MP_QSTR_close, &file_obj_close_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t file_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&file_obj_read_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&file_obj_write_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&file_obj_close_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(file_locals_dict, file_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t file_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_File,
|
||||
.print = file_obj_print,
|
||||
.methods = file_methods,
|
||||
.locals_dict = (mp_obj_t)&file_locals_dict,
|
||||
};
|
||||
|
||||
mp_obj_t pyb_io_open(mp_obj_t o_filename, mp_obj_t o_mode) {
|
||||
|
18
stm/i2c.c
18
stm/i2c.c
@ -7,6 +7,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
|
||||
typedef enum {
|
||||
PYB_I2C_1 = 0,
|
||||
@ -325,20 +326,21 @@ static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_read_obj, i2c_obj_read);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_readAndStop_obj, i2c_obj_readAndStop);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_stop_obj, i2c_obj_stop);
|
||||
|
||||
static const mp_method_t i2c_methods[] = {
|
||||
{ MP_QSTR_start, &i2c_obj_start_obj },
|
||||
{ MP_QSTR_write, &i2c_obj_write_obj },
|
||||
{ MP_QSTR_read, &i2c_obj_read_obj },
|
||||
{ MP_QSTR_readAndStop, &i2c_obj_readAndStop_obj },
|
||||
{ MP_QSTR_stop, &i2c_obj_stop_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t i2c_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_start), (mp_obj_t)&i2c_obj_start_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&i2c_obj_write_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&i2c_obj_read_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_readAndStop), (mp_obj_t)&i2c_obj_readAndStop_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_stop), (mp_obj_t)&i2c_obj_stop_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(i2c_locals_dict, i2c_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t i2c_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_I2C,
|
||||
.print = i2c_obj_print,
|
||||
.methods = i2c_methods,
|
||||
.locals_dict = (mp_obj_t)&i2c_locals_dict,
|
||||
};
|
||||
|
||||
// create the I2C object
|
||||
|
14
stm/led.c
14
stm/led.c
@ -6,6 +6,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "led.h"
|
||||
#include "pin.h"
|
||||
#include "build/pins.h"
|
||||
@ -109,18 +110,19 @@ static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle);
|
||||
|
||||
static const mp_method_t led_methods[] = {
|
||||
{ MP_QSTR_on, &led_obj_on_obj },
|
||||
{ MP_QSTR_off, &led_obj_off_obj },
|
||||
{ MP_QSTR_toggle, &led_obj_toggle_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t led_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&led_obj_on_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&led_obj_off_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&led_obj_toggle_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t led_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Led,
|
||||
.print = led_obj_print,
|
||||
.methods = led_methods,
|
||||
.locals_dict = (mp_obj_t)&led_locals_dict,
|
||||
};
|
||||
|
||||
static mp_obj_t pyb_Led(mp_obj_t led_id) {
|
||||
|
14
stm/pin.c
14
stm/pin.c
@ -7,6 +7,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
|
||||
#include "pin.h"
|
||||
|
||||
@ -34,18 +35,19 @@ static MP_DEFINE_CONST_FUN_OBJ_1(pin_obj_name_obj, pin_obj_name);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_obj_port_obj, pin_obj_port);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_obj_pin_obj, pin_obj_pin);
|
||||
|
||||
static const mp_method_t pin_methods[] = {
|
||||
{ MP_QSTR_name, &pin_obj_name_obj },
|
||||
{ MP_QSTR_port, &pin_obj_port_obj },
|
||||
{ MP_QSTR_pin, &pin_obj_pin_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t pin_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&pin_obj_name_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_port), (mp_obj_t)&pin_obj_port_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin), (mp_obj_t)&pin_obj_pin_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pin_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Pin,
|
||||
.print = pin_obj_print,
|
||||
.methods = pin_methods,
|
||||
.locals_dict = (mp_obj_t)&pin_locals_dict,
|
||||
};
|
||||
|
||||
void pin_af_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
|
14
stm/sdcard.c
14
stm/sdcard.c
@ -9,6 +9,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "sdcard.h"
|
||||
|
||||
@ -194,17 +195,18 @@ static mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) {
|
||||
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(sd_read_obj, sd_read);
|
||||
|
||||
static const mp_method_t sdcard_methods[] = {
|
||||
{ MP_QSTR_present, &sd_present_obj },
|
||||
{ MP_QSTR_power, &sd_power_obj },
|
||||
{ MP_QSTR_read, &sd_read_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t sdcard_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_present), (mp_obj_t)&sd_present_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_power), (mp_obj_t)&sd_power_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&sd_read_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(sdcard_locals_dict, sdcard_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t sdcard_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_SDcard,
|
||||
.methods = sdcard_methods,
|
||||
.locals_dict = (mp_obj_t)&sdcard_locals_dict,
|
||||
};
|
||||
|
||||
const mp_obj_base_t pyb_sdcard_obj = {&sdcard_type};
|
||||
|
10
stm/servo.c
10
stm/servo.c
@ -8,6 +8,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "servo.h"
|
||||
|
||||
// PWM
|
||||
@ -146,16 +147,17 @@ STATIC mp_obj_t servo_obj_angle(mp_obj_t self_in, mp_obj_t angle) {
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(servo_obj_angle_obj, servo_obj_angle);
|
||||
|
||||
STATIC const mp_method_t servo_methods[] = {
|
||||
{ MP_QSTR_angle, &servo_obj_angle_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t servo_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_angle), (mp_obj_t)&servo_obj_angle_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(servo_locals_dict, servo_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t servo_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Servo,
|
||||
.print = servo_obj_print,
|
||||
.methods = servo_methods,
|
||||
.locals_dict = (mp_obj_t)&servo_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t pyb_Servo(mp_obj_t servo_id) {
|
||||
|
16
stm/usart.c
16
stm/usart.c
@ -7,6 +7,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "usart.h"
|
||||
|
||||
pyb_usart_t pyb_usart_global_debug = PYB_USART_NONE;
|
||||
@ -235,19 +236,20 @@ static MP_DEFINE_CONST_FUN_OBJ_1(usart_obj_rx_char_obj, usart_obj_rx_char);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(usart_obj_tx_char_obj, usart_obj_tx_char);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(usart_obj_tx_str_obj, usart_obj_tx_str);
|
||||
|
||||
STATIC const mp_method_t usart_methods[] = {
|
||||
{ MP_QSTR_status, &usart_obj_status_obj },
|
||||
{ MP_QSTR_recv_chr, &usart_obj_rx_char_obj },
|
||||
{ MP_QSTR_send_chr, &usart_obj_tx_char_obj },
|
||||
{ MP_QSTR_send, &usart_obj_tx_str_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t usart_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&usart_obj_status_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_recv_chr), (mp_obj_t)&usart_obj_rx_char_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_send_chr), (mp_obj_t)&usart_obj_tx_char_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&usart_obj_tx_str_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(usart_locals_dict, usart_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t usart_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Usart,
|
||||
.print = usart_obj_print,
|
||||
.methods = usart_methods,
|
||||
.locals_dict = (mp_obj_t)&usart_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t pyb_Usart(mp_obj_t usart_id, mp_obj_t baudrate) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "i2c.h"
|
||||
#include "accel.h"
|
||||
@ -158,20 +159,21 @@ STATIC mp_obj_t pyb_accel_write(mp_obj_t self_in, mp_obj_t reg, mp_obj_t val) {
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(pyb_accel_write_obj, pyb_accel_write);
|
||||
|
||||
STATIC const mp_method_t pyb_accel_methods[] = {
|
||||
{ MP_QSTR_x, &pyb_accel_x_obj },
|
||||
{ MP_QSTR_y, &pyb_accel_y_obj },
|
||||
{ MP_QSTR_z, &pyb_accel_z_obj },
|
||||
{ MP_QSTR_tilt, &pyb_accel_tilt_obj },
|
||||
{ MP_QSTR_filtered_xyz, &pyb_accel_filtered_xyz_obj },
|
||||
{ MP_QSTR_read, &pyb_accel_read_obj },
|
||||
{ MP_QSTR_write, &pyb_accel_write_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t pyb_accel_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_x), (mp_obj_t)&pyb_accel_x_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_y), (mp_obj_t)&pyb_accel_y_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_z), (mp_obj_t)&pyb_accel_z_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_tilt), (mp_obj_t)&pyb_accel_tilt_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_filtered_xyz), (mp_obj_t)&pyb_accel_filtered_xyz_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&pyb_accel_read_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&pyb_accel_write_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_accel_locals_dict, pyb_accel_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pyb_accel_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Accel,
|
||||
.make_new = pyb_accel_make_new,
|
||||
.methods = pyb_accel_methods,
|
||||
.locals_dict = (mp_obj_t)&pyb_accel_locals_dict,
|
||||
};
|
||||
|
25
stmhal/adc.c
25
stmhal/adc.c
@ -7,6 +7,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "adc.h"
|
||||
#include "pin.h"
|
||||
#include "build/pins.h"
|
||||
@ -163,17 +164,18 @@ STATIC mp_obj_t adc_read(mp_obj_t self_in) {
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read);
|
||||
|
||||
STATIC const mp_method_t adc_methods[] = {
|
||||
{ MP_QSTR_read, &adc_read_obj},
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t adc_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&adc_read_obj},
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pyb_adc_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_ADC,
|
||||
.print = adc_print,
|
||||
.make_new = adc_make_new,
|
||||
.methods = adc_methods,
|
||||
.locals_dict = (mp_obj_t)&adc_locals_dict,
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
@ -320,19 +322,20 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_temp_obj, adc_all_read_core_t
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vbat_obj, adc_all_read_core_vbat);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vref_obj, adc_all_read_core_vref);
|
||||
|
||||
STATIC const mp_method_t adc_all_methods[] = {
|
||||
{ MP_QSTR_read_channel, &adc_all_read_channel_obj},
|
||||
{ MP_QSTR_read_core_temp, &adc_all_read_core_temp_obj},
|
||||
{ MP_QSTR_read_core_vbat, &adc_all_read_core_vbat_obj},
|
||||
{ MP_QSTR_read_core_vref, &adc_all_read_core_vref_obj},
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t adc_all_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read_channel), (mp_obj_t) &adc_all_read_channel_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read_core_temp), (mp_obj_t)&adc_all_read_core_temp_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read_core_vbat), (mp_obj_t)&adc_all_read_core_vbat_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read_core_vref), (mp_obj_t)&adc_all_read_core_vref_obj},
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(adc_all_locals_dict, adc_all_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t adc_all_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_ADC,
|
||||
.print = adc_all_print,
|
||||
.methods = adc_all_methods,
|
||||
.locals_dict = (mp_obj_t)&adc_all_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t pyb_ADC_all(mp_obj_t resolution) {
|
||||
|
15
stmhal/dac.c
15
stmhal/dac.c
@ -260,20 +260,21 @@ mp_obj_t pyb_dac_dma(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_dma_obj, 3, pyb_dac_dma);
|
||||
|
||||
STATIC const mp_method_t pyb_dac_methods[] = {
|
||||
{ MP_QSTR_noise, &pyb_dac_noise_obj },
|
||||
{ MP_QSTR_triangle, &pyb_dac_triangle_obj },
|
||||
{ MP_QSTR_write, &pyb_dac_write_obj },
|
||||
{ MP_QSTR_dma, &pyb_dac_dma_obj },
|
||||
STATIC const mp_map_elem_t pyb_dac_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_noise), (mp_obj_t)&pyb_dac_noise_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_triangle), (mp_obj_t)&pyb_dac_triangle_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&pyb_dac_write_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_dma), (mp_obj_t)&pyb_dac_dma_obj },
|
||||
// TODO add function that does double buffering:
|
||||
// dma2(freq, buf1, buf2, callback)
|
||||
// where callback is called when the buffer has been drained
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_dac_locals_dict, pyb_dac_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pyb_dac_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_DAC,
|
||||
.make_new = pyb_dac_make_new,
|
||||
.methods = pyb_dac_methods,
|
||||
.locals_dict = (mp_obj_t)&pyb_dac_locals_dict,
|
||||
};
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "nlr.h"
|
||||
|
||||
@ -228,14 +229,15 @@ static MP_DEFINE_CONST_FUN_OBJ_1(exti_obj_enable_obj, exti_obj_enable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(exti_obj_disable_obj, exti_obj_disable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(exti_obj_swint_obj, exti_obj_swint);
|
||||
|
||||
static const mp_method_t exti_methods[] = {
|
||||
{ MP_QSTR_line, &exti_obj_line_obj },
|
||||
{ MP_QSTR_enable, &exti_obj_enable_obj },
|
||||
{ MP_QSTR_disable, &exti_obj_disable_obj },
|
||||
{ MP_QSTR_swint, &exti_obj_swint_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t exti_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_line), (mp_obj_t) &exti_obj_line_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t) &exti_obj_enable_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t) &exti_obj_disable_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_swint), (mp_obj_t) &exti_obj_swint_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(exti_locals_dict, exti_locals_dict_table);
|
||||
|
||||
static mp_obj_t exti_regs(void) {
|
||||
printf("EXTI_IMR %08lx\n", EXTI->IMR);
|
||||
printf("EXTI_EMR %08lx\n", EXTI->EMR);
|
||||
@ -320,7 +322,7 @@ const mp_obj_type_t exti_obj_type = {
|
||||
{ &exti_meta_obj_type },
|
||||
.name = MP_QSTR_Exti,
|
||||
.print = exti_obj_print,
|
||||
.methods = exti_methods,
|
||||
.locals_dict = (mp_obj_t)&exti_locals_dict,
|
||||
};
|
||||
|
||||
void exti_init(void) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "file.h"
|
||||
#include "ff.h"
|
||||
|
||||
@ -51,18 +52,19 @@ static MP_DEFINE_CONST_FUN_OBJ_1(file_obj_close_obj, file_obj_close);
|
||||
|
||||
// TODO gc hook to close the file if not already closed
|
||||
|
||||
static const mp_method_t file_methods[] = {
|
||||
{ MP_QSTR_read, &file_obj_read_obj },
|
||||
{ MP_QSTR_write, &file_obj_write_obj },
|
||||
{ MP_QSTR_close, &file_obj_close_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t file_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&file_obj_read_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&file_obj_write_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&file_obj_close_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(file_locals_dict, file_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t file_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_File,
|
||||
.print = file_obj_print,
|
||||
.methods = file_methods,
|
||||
.locals_dict = (mp_obj_t)&file_locals_dict,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t pyb_io_open(mp_obj_t o_filename, mp_obj_t o_mode) {
|
||||
|
@ -72,12 +72,6 @@ STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type->methods != NULL) {
|
||||
for (const mp_method_t *meth = type->methods; meth->name != MP_QSTR_NULL; meth++) {
|
||||
pyb_help_print_info_about_object(MP_OBJ_NEW_QSTR(meth->name), (mp_obj_t)meth->fun);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
|
14
stmhal/i2c.c
14
stmhal/i2c.c
@ -8,6 +8,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "i2c.h"
|
||||
|
||||
@ -169,16 +170,17 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args) {
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_i2c_mem_write_obj, 4, 4, pyb_i2c_mem_write);
|
||||
|
||||
STATIC const mp_method_t pyb_i2c_methods[] = {
|
||||
{ MP_QSTR_is_ready, &pyb_i2c_is_ready_obj },
|
||||
{ MP_QSTR_mem_read, &pyb_i2c_mem_read_obj },
|
||||
{ MP_QSTR_mem_write, &pyb_i2c_mem_write_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t pyb_i2c_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_is_ready), (mp_obj_t)&pyb_i2c_is_ready_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem_read), (mp_obj_t)&pyb_i2c_mem_read_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem_write), (mp_obj_t)&pyb_i2c_mem_write_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pyb_i2c_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_I2C,
|
||||
.make_new = pyb_i2c_make_new,
|
||||
.methods = pyb_i2c_methods,
|
||||
.locals_dict = (mp_obj_t)&pyb_i2c_locals_dict,
|
||||
};
|
||||
|
16
stmhal/led.c
16
stmhal/led.c
@ -8,6 +8,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "led.h"
|
||||
#include "pin.h"
|
||||
@ -256,18 +257,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(led_obj_intensity_obj, 1, 2, led_obj_intensity);
|
||||
|
||||
STATIC const mp_method_t led_methods[] = {
|
||||
{ MP_QSTR_on, &led_obj_on_obj },
|
||||
{ MP_QSTR_off, &led_obj_off_obj },
|
||||
{ MP_QSTR_toggle, &led_obj_toggle_obj },
|
||||
{ MP_QSTR_intensity, &led_obj_intensity_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t led_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&led_obj_on_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&led_obj_off_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&led_obj_toggle_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_intensity), (mp_obj_t)&led_obj_intensity_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pyb_led_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Led,
|
||||
.print = led_obj_print,
|
||||
.make_new = led_obj_make_new,
|
||||
.methods = led_methods,
|
||||
.locals_dict = (mp_obj_t)&led_locals_dict,
|
||||
};
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "sdcard.h"
|
||||
|
||||
@ -232,17 +233,18 @@ static mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) {
|
||||
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(sd_read_obj, sd_read);
|
||||
|
||||
static const mp_method_t sdcard_methods[] = {
|
||||
{ MP_QSTR_present, &sd_present_obj },
|
||||
{ MP_QSTR_power, &sd_power_obj },
|
||||
{ MP_QSTR_read, &sd_read_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t sdcard_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_present), (mp_obj_t)&sd_present_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_power), (mp_obj_t)&sd_power_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&sd_read_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(sdcard_locals_dict, sdcard_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t sdcard_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_SDcard,
|
||||
.methods = sdcard_methods,
|
||||
.locals_dict = (mp_obj_t)&sdcard_locals_dict,
|
||||
};
|
||||
|
||||
const mp_obj_base_t pyb_sdcard_obj = {&sdcard_type};
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "servo.h"
|
||||
|
||||
// this servo driver uses hardware PWM to drive servos on PA0, PA1, PA2, PA3 = X1, X2, X3, X4
|
||||
@ -205,15 +206,16 @@ STATIC mp_obj_t pyb_servo_angle(uint n_args, const mp_obj_t *args) {
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_angle);
|
||||
|
||||
STATIC const mp_method_t pyb_servo_methods[] = {
|
||||
{ MP_QSTR_angle, &pyb_servo_angle_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t pyb_servo_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_angle), (mp_obj_t)&pyb_servo_angle_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_servo_locals_dict, pyb_servo_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pyb_servo_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Servo,
|
||||
.print = pyb_servo_print,
|
||||
.make_new = pyb_servo_make_new,
|
||||
.methods = pyb_servo_methods,
|
||||
.locals_dict = (mp_obj_t)&pyb_servo_locals_dict,
|
||||
};
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "usart.h"
|
||||
|
||||
struct _pyb_usart_obj_t {
|
||||
@ -209,18 +210,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(usart_obj_rx_char_obj, usart_obj_rx_char);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(usart_obj_tx_char_obj, usart_obj_tx_char);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(usart_obj_tx_str_obj, usart_obj_tx_str);
|
||||
|
||||
STATIC const mp_method_t usart_methods[] = {
|
||||
{ MP_QSTR_status, &usart_obj_status_obj },
|
||||
{ MP_QSTR_recv_chr, &usart_obj_rx_char_obj },
|
||||
{ MP_QSTR_send_chr, &usart_obj_tx_char_obj },
|
||||
{ MP_QSTR_send, &usart_obj_tx_str_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t usart_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&usart_obj_status_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_recv_chr), (mp_obj_t)&usart_obj_rx_char_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_send_chr), (mp_obj_t)&usart_obj_tx_char_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&usart_obj_tx_str_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(usart_locals_dict, usart_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t pyb_usart_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Usart,
|
||||
.print = usart_obj_print,
|
||||
.make_new = usart_obj_make_new,
|
||||
.methods = usart_methods,
|
||||
.locals_dict = (mp_obj_t)&usart_locals_dict,
|
||||
};
|
||||
|
14
unix/ffi.c
14
unix/ffi.c
@ -9,6 +9,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "binary.h"
|
||||
|
||||
@ -216,19 +217,20 @@ static mp_obj_t ffimod_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
return o;
|
||||
}
|
||||
|
||||
static const mp_method_t ffimod_type_methods[] = {
|
||||
{ "func", &ffimod_func_obj },
|
||||
{ "var", &ffimod_var_obj },
|
||||
{ "close", &ffimod_close_obj },
|
||||
{ NULL, NULL },
|
||||
static const mp_map_elem_t ffimod_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_func), (mp_obj_t) &ffimod_func_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_var), (mp_obj_t) &ffimod_var_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t) &ffimod_close_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ffimod_locals_dict, ffimod_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t ffimod_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_ffimod,
|
||||
.print = ffimod_print,
|
||||
.make_new = ffimod_make_new,
|
||||
.methods = ffimod_type_methods,
|
||||
.locals_dict = (mp_obj_t)&ffimod_locals_dict,
|
||||
};
|
||||
|
||||
// FFI function
|
||||
|
20
unix/file.c
20
unix/file.c
@ -9,6 +9,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "runtime.h"
|
||||
#include "stream.h"
|
||||
|
||||
@ -105,16 +106,17 @@ static mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
return fdfile_new(fd);
|
||||
}
|
||||
|
||||
static const mp_method_t rawfile_type_methods[] = {
|
||||
{ MP_QSTR_fileno, &fdfile_fileno_obj },
|
||||
{ MP_QSTR_read, &mp_stream_read_obj },
|
||||
{ MP_QSTR_readall, &mp_stream_readall_obj },
|
||||
{ MP_QSTR_readline, &mp_stream_unbuffered_readline_obj},
|
||||
{ MP_QSTR_write, &mp_stream_write_obj },
|
||||
{ MP_QSTR_close, &fdfile_close_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
STATIC const mp_map_elem_t rawfile_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_fileno), (mp_obj_t)&fdfile_fileno_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_readall), (mp_obj_t)&mp_stream_readall_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&fdfile_close_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t rawfile_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_io_dot_FileIO,
|
||||
@ -126,7 +128,7 @@ static const mp_obj_type_t rawfile_type = {
|
||||
.read = fdfile_read,
|
||||
.write = fdfile_write,
|
||||
},
|
||||
.methods = rawfile_type_methods,
|
||||
.locals_dict = (mp_obj_t)&rawfile_locals_dict,
|
||||
};
|
||||
|
||||
// Factory function for I/O stream classes
|
||||
|
12
unix/main.c
12
unix/main.c
@ -15,6 +15,7 @@
|
||||
#include "lexerunix.h"
|
||||
#include "parse.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "parsehelper.h"
|
||||
#include "compile.h"
|
||||
#include "runtime0.h"
|
||||
@ -191,17 +192,18 @@ static mp_obj_t test_set(mp_obj_t self_in, mp_obj_t arg) {
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(test_get_obj, test_get);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(test_set_obj, test_set);
|
||||
|
||||
static const mp_method_t test_methods[] = {
|
||||
{ MP_QSTR_get, &test_get_obj },
|
||||
{ MP_QSTR_set, &test_set_obj },
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
static const mp_map_elem_t test_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_get), (mp_obj_t)&test_get_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_set), (mp_obj_t)&test_set_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(test_locals_dict, test_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t test_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Test,
|
||||
.print = test_print,
|
||||
.methods = test_methods,
|
||||
.locals_dict = (mp_obj_t)&test_locals_dict,
|
||||
};
|
||||
|
||||
mp_obj_t test_obj_new(int value) {
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "mpconfig.h"
|
||||
#include "qstr.h"
|
||||
#include "obj.h"
|
||||
#include "map.h"
|
||||
#include "objtuple.h"
|
||||
#include "objarray.h"
|
||||
#include "runtime.h"
|
||||
@ -217,28 +218,29 @@ static mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||
return socket_new(fd);
|
||||
}
|
||||
|
||||
static const mp_method_t microsocket_type_methods[] = {
|
||||
{ MP_QSTR_fileno, &socket_fileno_obj },
|
||||
{ MP_QSTR_makefile, &mp_identity_obj },
|
||||
{ MP_QSTR_read, &mp_stream_read_obj },
|
||||
{ MP_QSTR_readall, &mp_stream_readall_obj },
|
||||
{ MP_QSTR_readline, &mp_stream_unbuffered_readline_obj},
|
||||
{ MP_QSTR_write, &mp_stream_write_obj },
|
||||
{ MP_QSTR_connect, &socket_connect_obj },
|
||||
{ MP_QSTR_bind, &socket_bind_obj },
|
||||
{ MP_QSTR_listen, &socket_listen_obj },
|
||||
{ MP_QSTR_accept, &socket_accept_obj },
|
||||
{ MP_QSTR_recv, &socket_recv_obj },
|
||||
{ MP_QSTR_send, &socket_send_obj },
|
||||
{ MP_QSTR_setsockopt, &socket_setsockopt_obj },
|
||||
{ MP_QSTR_close, &socket_close_obj },
|
||||
static const mp_map_elem_t microsocket_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_fileno), (mp_obj_t)&socket_fileno_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&mp_identity_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_readall), (mp_obj_t)&mp_stream_readall_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&socket_connect_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_bind), (mp_obj_t)&socket_bind_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_listen), (mp_obj_t)&socket_listen_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_accept), (mp_obj_t)&socket_accept_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&socket_recv_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&socket_send_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_setsockopt), (mp_obj_t)&socket_setsockopt_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&socket_close_obj },
|
||||
#if MICROPY_SOCKET_EXTRA
|
||||
{ MP_QSTR_recv, &mp_stream_read_obj },
|
||||
{ MP_QSTR_send, &mp_stream_write_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&mp_stream_read_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&mp_stream_write_obj },
|
||||
#endif
|
||||
{ MP_QSTR_NULL, NULL },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(microsocket_locals_dict, microsocket_locals_dict_table);
|
||||
|
||||
static const mp_obj_type_t microsocket_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_socket,
|
||||
@ -250,7 +252,7 @@ static const mp_obj_type_t microsocket_type = {
|
||||
.read = socket_read,
|
||||
.write = socket_write,
|
||||
},
|
||||
.methods = microsocket_type_methods,
|
||||
.locals_dict = (mp_obj_t)µsocket_locals_dict,
|
||||
};
|
||||
|
||||
static mp_obj_t mod_socket_htons(mp_obj_t arg) {
|
||||
|
Loading…
Reference in New Issue
Block a user