Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python data types #2

Open
kdschlosser opened this issue Feb 23, 2025 · 1 comment
Open

Python data types #2

kdschlosser opened this issue Feb 23, 2025 · 1 comment

Comments

@kdschlosser
Copy link
Collaborator

I am going to create a list of all the different python data types with their associated MicroPython functions/types. Using those we can then list the matching CPython API functions/types so we have an idea of what we are dealing with.

@kdschlosser
Copy link
Collaborator Author

BOOL
mp_obj_new_bool(b)
bool mp_obj_is_true(mp_obj_t arg);
mp_obj_is_bool(o)

SMALL INT
mp_obj_new_int(i)
mp_int_t mp_obj_get_int(mp_const_obj_t arg);
mp_obj_is_int(o)
mp_obj_new_int_from_float(mp_float_t val)
mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in); // Will raise exception if value doesn't fit into mp_int_t
bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value);
bool mp_obj_is_integer(mp_const_obj_t o) // returns true if o is bool, small int or long int
bool mp_obj_is_small_int(mp_const_obj_t o)

UNSIGNED INT
mp_obj_new_int_from_uint(i)
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in); // For long int, returns value truncated to mp_int_t
mp_uint_t mp_obj_int_get_uint_checked(mp_const_obj_t self_in); // Will raise exception if value is negative or doesn't fit into mp_uint_t

LONG LONG
mp_obj_new_int_from_ll

UNSIGNED LONG LONG
mp_obj_new_int_from_ull

STR
mp_obj_new_str(data, len)
mp_obj_new_str_from_cstr(const char *str) // null terminated string
mp_obj_str_get_str(s)
mp_obj_is_str(o)
bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2);
qstr mp_obj_str_get_qstr(mp_obj_t self_in);
const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated
const char *mp_obj_str_get_data(mp_obj_t self_in, size_t *len);
mp_obj_t mp_obj_str_intern(mp_obj_t str);
mp_obj_t mp_obj_str_intern_checked(mp_obj_t obj);

BYTES
mp_obj_new_bytes(data, len)
mp_obj_is_str_or_bytes(o)

BYTEARRAY
mp_obj_new_bytearray(data, len)

BUFFER
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)

TUPLE
c type to py type: mp_obj_new_tuple(n, items)
void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
void mp_obj_tuple_del(mp_obj_t self_in);

FLOAT
mp_obj_t mp_obj_new_float(mp_float_t f)
mp_float_t mp_obj_float_get(mp_const_obj_t o)
mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t rhs);
mp_int_t mp_float_hash(mp_float_t val);
mp_obj_t mp_obj_new_float_from_f(float o)
float mp_obj_get_float_to_f(mp_obj_t o)
mp_obj_t mp_obj_new_float_from_d(double o)
double mp_obj_get_float_to_d(mp_obj_t o)
mp_float_t mp_obj_get_float(mp_obj_t self_in);
bool mp_obj_get_float_maybe(mp_obj_t arg, mp_float_t *value);
mp_obj_is_float(mp_const_obj_t o)

LIST
mp_obj_new_list(n, items)
mp_obj_list_append(list, item)
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value);
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
void mp_obj_list_set_len(mp_obj_t self_in, size_t len);
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(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);

SLICE
mp_obj_t mp_obj_new_slice(mp_obj_t start, mp_obj_t stop, mp_obj_t step);
void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *result);

MODULE
mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t module)

PROPERTY
const mp_obj_t *mp_obj_property_get(mp_obj_t self_in);

FUNCTION
qstr mp_obj_fun_get_name(mp_const_obj_t fun);
mp_obj_is_fun(o)
bool mp_obj_is_callable(mp_obj_t o_in);

COMPLEX
mp_obj_new_complex(mp_float_t real, mp_float_t imag)
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(mp_binary_op_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in);
void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
bool mp_obj_get_complex_maybe(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);

EXCEPTION
mp_obj_new_exception(const mp_obj_type_t *exc_type)
mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args)
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg)
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...)
mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, va_list arg)
bool mp_obj_is_native_exception_instance(mp_obj_t self_in);
bool mp_obj_is_exception_type(mp_obj_t self_in);
bool mp_obj_is_exception_instance(mp_obj_t self_in);
bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type);
void mp_obj_exception_clear_traceback(mp_obj_t self_in);
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block);
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values);
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in);
void mp_init_emergency_exception_buf(void);
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg)

GENERATOR
mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun);

TUPLE
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items);
void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
void mp_obj_tuple_del(mp_obj_t self_in);
mp_int_t mp_obj_tuple_hash(mp_obj_t self_in);

LIST
mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items);

DICT
mp_obj_t mp_obj_new_dict(size_t n_args);
mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args);
size_t mp_obj_dict_len(mp_obj_t self_in);
mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index);
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key);
mp_obj_t mp_obj_dict_copy(mp_obj_t self_in);
mp_map_t *mp_obj_dict_get_map(mp_obj_t dict)
bool mp_obj_is_dict_or_ordereddict(mp_obj_t o);

MAP
void mp_map_init(mp_map_t *map, size_t n);
void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table);
mp_map_t *mp_map_new(size_t n);
void mp_map_deinit(mp_map_t *map);
void mp_map_free(mp_map_t *map);
mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
void mp_map_clear(mp_map_t *map);
void mp_map_dump(mp_map_t *map);
bool mp_map_slot_is_filled(const mp_map_t *map, size_t pos)

SET
mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items);
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item);
void mp_set_init(mp_set_t *set, size_t n);
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
mp_obj_t mp_set_remove_first(mp_set_t *set);
void mp_set_clear(mp_set_t *set);
bool mp_set_slot_is_filled(const mp_set_t *set, size_t pos)

BOUND METHOD
mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self);

MODULE
mp_obj_t mp_obj_new_module(qstr module_name);

MEMORYVIEW
mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items);

CONSTANT TYPES
mp_const_true
mp_const_false
mp_const_none
mp_const_empty_tuple
mp_const_empty_bytes
mp_const_notimplemented

EXCEPTION TYPES
mp_type_ZeroDivisionError
mp_type_ViperTypeError
mp_type_ValueError
mp_type_UnicodeError
mp_type_TypeError
mp_type_SystemExit
mp_type_SyntaxError
mp_type_StopIteration
mp_type_StopAsyncIteration
mp_type_RuntimeError
mp_type_OverflowError
mp_type_OSError
mp_type_NotImplementedError
mp_type_NameError
mp_type_MemoryError
mp_type_LookupError
mp_type_KeyError
mp_type_KeyboardInterrupt
mp_type_IndexError
mp_type_IndentationError
mp_type_ImportError
mp_type_GeneratorExit
mp_type_Exception
mp_type_EOFError
mp_type_AttributeError
mp_type_AssertionError
mp_type_ArithmeticError
mp_type_BaseException

TYPES
mp_type_polymorph_iter
mp_type_reversed
mp_type_ringio
mp_type_bytesio
mp_type_stringio
mp_type_property
mp_type_bound_meth
mp_type_classmethod
mp_type_staticmethod
mp_type_module
mp_type_fun_asm
mp_type_fun_viper
mp_type_fun_native
mp_type_fun_bc
mp_type_fun_builtin_var
mp_type_fun_builtin_3
mp_type_fun_builtin_2
mp_type_fun_builtin_1
mp_type_fun_builtin_0
mp_type_gen_instance
mp_type_native_gen_wrap
mp_type_gen_wrap
mp_type_super
mp_type_array
mp_type_zip
mp_type_slice
mp_type_frozenset
mp_type_set
mp_type_range
mp_type_ordereddict
mp_type_dict
mp_type_deque
mp_type_filter
mp_type_enumerate
mp_type_map
mp_type_list
mp_type_tuple
mp_type_complex
mp_type_float
mp_type_memoryview
mp_type_bytearray
mp_type_bytes
mp_type_str
mp_type_int
mp_type_bool
mp_type_NoneType
mp_type_object
mp_type_type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant