py: Small comments, name changes, use of machine_int_t.
This commit is contained in:
parent
b3a50f0f3e
commit
e04a44e2f6
|
@ -173,7 +173,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable);
|
||||||
|
|
||||||
STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
|
STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
|
||||||
#if MICROPY_PY_BUILTINS_STR_UNICODE
|
#if MICROPY_PY_BUILTINS_STR_UNICODE
|
||||||
int c = mp_obj_get_int(o_in);
|
machine_int_t c = mp_obj_get_int(o_in);
|
||||||
char str[4];
|
char str[4];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
if (c < 0x80) {
|
if (c < 0x80) {
|
||||||
|
@ -198,7 +198,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
|
||||||
}
|
}
|
||||||
return mp_obj_new_str(str, len, true);
|
return mp_obj_new_str(str, len, true);
|
||||||
#else
|
#else
|
||||||
int ord = mp_obj_get_int(o_in);
|
machine_int_t ord = mp_obj_get_int(o_in);
|
||||||
if (0 <= ord && ord <= 0x10ffff) {
|
if (0 <= ord && ord <= 0x10ffff) {
|
||||||
char str[1] = {ord};
|
char str[1] = {ord};
|
||||||
return mp_obj_new_str(str, 1, true);
|
return mp_obj_new_str(str, 1, true);
|
||||||
|
|
|
@ -100,7 +100,7 @@ bool unichar_isupper(unichar c);
|
||||||
bool unichar_islower(unichar c);
|
bool unichar_islower(unichar c);
|
||||||
unichar unichar_tolower(unichar c);
|
unichar unichar_tolower(unichar c);
|
||||||
unichar unichar_toupper(unichar c);
|
unichar unichar_toupper(unichar c);
|
||||||
uint unichar_charlen(const char *str, uint len);
|
uint unichar_charlen(const char *str, uint len); // TODO this should return machine_uint_t
|
||||||
#define UTF8_IS_NONASCII(ch) ((ch) & 0x80)
|
#define UTF8_IS_NONASCII(ch) ((ch) & 0x80)
|
||||||
#define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80)
|
#define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80)
|
||||||
|
|
||||||
|
@ -169,6 +169,7 @@ extern uint mp_verbose_flag;
|
||||||
// This is useful for unicode handling. Some CPU archs has
|
// This is useful for unicode handling. Some CPU archs has
|
||||||
// special instructions for efficient implentation of this
|
// special instructions for efficient implentation of this
|
||||||
// function (e.g. CLZ on ARM).
|
// function (e.g. CLZ on ARM).
|
||||||
|
// NOTE: this function is unused at the moment
|
||||||
#ifndef count_lead_ones
|
#ifndef count_lead_ones
|
||||||
static inline uint count_lead_ones(byte val) {
|
static inline uint count_lead_ones(byte val) {
|
||||||
uint c = 0;
|
uint c = 0;
|
||||||
|
|
13
py/objstr.c
13
py/objstr.c
|
@ -251,7 +251,7 @@ STATIC const byte *find_subbytes(const byte *haystack, machine_uint_t hlen, cons
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
mp_obj_t mp_obj_str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||||
GET_STR_DATA_LEN(lhs_in, lhs_data, lhs_len);
|
GET_STR_DATA_LEN(lhs_in, lhs_data, lhs_len);
|
||||||
mp_obj_type_t *lhs_type = mp_obj_get_type(lhs_in);
|
mp_obj_type_t *lhs_type = mp_obj_get_type(lhs_in);
|
||||||
mp_obj_type_t *rhs_type = mp_obj_get_type(rhs_in);
|
mp_obj_type_t *rhs_type = mp_obj_get_type(rhs_in);
|
||||||
|
@ -566,7 +566,6 @@ STATIC mp_obj_t str_rsplit(uint n_args, const mp_obj_t *args) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
STATIC mp_obj_t str_finder(uint n_args, const mp_obj_t *args, machine_int_t direction, bool is_index) {
|
STATIC mp_obj_t str_finder(uint n_args, const mp_obj_t *args, machine_int_t direction, bool is_index) {
|
||||||
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
|
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
|
||||||
assert(2 <= n_args && n_args <= 4);
|
assert(2 <= n_args && n_args <= 4);
|
||||||
|
@ -1610,7 +1609,7 @@ STATIC mp_obj_t str_encode(uint n_args, const mp_obj_t *args) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
machine_int_t str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags) {
|
machine_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags) {
|
||||||
if (flags == MP_BUFFER_READ) {
|
if (flags == MP_BUFFER_READ) {
|
||||||
GET_STR_DATA_LEN(self_in, str_data, str_len);
|
GET_STR_DATA_LEN(self_in, str_data, str_len);
|
||||||
bufinfo->buf = (void*)str_data;
|
bufinfo->buf = (void*)str_data;
|
||||||
|
@ -1701,10 +1700,10 @@ const mp_obj_type_t mp_type_str = {
|
||||||
.name = MP_QSTR_str,
|
.name = MP_QSTR_str,
|
||||||
.print = str_print,
|
.print = str_print,
|
||||||
.make_new = str_make_new,
|
.make_new = str_make_new,
|
||||||
.binary_op = str_binary_op,
|
.binary_op = mp_obj_str_binary_op,
|
||||||
.subscr = str_subscr,
|
.subscr = str_subscr,
|
||||||
.getiter = mp_obj_new_str_iterator,
|
.getiter = mp_obj_new_str_iterator,
|
||||||
.buffer_p = { .get_buffer = str_get_buffer },
|
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
|
||||||
.locals_dict = (mp_obj_t)&str_locals_dict,
|
.locals_dict = (mp_obj_t)&str_locals_dict,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1715,10 +1714,10 @@ const mp_obj_type_t mp_type_bytes = {
|
||||||
.name = MP_QSTR_bytes,
|
.name = MP_QSTR_bytes,
|
||||||
.print = str_print,
|
.print = str_print,
|
||||||
.make_new = bytes_make_new,
|
.make_new = bytes_make_new,
|
||||||
.binary_op = str_binary_op,
|
.binary_op = mp_obj_str_binary_op,
|
||||||
.subscr = str_subscr,
|
.subscr = str_subscr,
|
||||||
.getiter = mp_obj_new_bytes_iterator,
|
.getiter = mp_obj_new_bytes_iterator,
|
||||||
.buffer_p = { .get_buffer = str_get_buffer },
|
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
|
||||||
.locals_dict = (mp_obj_t)&str_locals_dict,
|
.locals_dict = (mp_obj_t)&str_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,8 @@ typedef struct _mp_obj_str_t {
|
||||||
mp_obj_t mp_obj_str_format(uint n_args, const mp_obj_t *args);
|
mp_obj_t mp_obj_str_format(uint n_args, const mp_obj_t *args);
|
||||||
mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, uint len);
|
mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, uint len);
|
||||||
|
|
||||||
mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in);
|
mp_obj_t mp_obj_str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in);
|
||||||
machine_int_t str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags);
|
machine_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags);
|
||||||
|
|
||||||
const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, uint self_len,
|
const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, uint self_len,
|
||||||
mp_obj_t index, bool is_slice);
|
mp_obj_t index, bool is_slice);
|
||||||
|
|
|
@ -106,7 +106,7 @@ STATIC mp_obj_t uni_unary_op(int op, mp_obj_t self_in) {
|
||||||
case MP_UNARY_OP_BOOL:
|
case MP_UNARY_OP_BOOL:
|
||||||
return MP_BOOL(str_len != 0);
|
return MP_BOOL(str_len != 0);
|
||||||
case MP_UNARY_OP_LEN:
|
case MP_UNARY_OP_LEN:
|
||||||
return MP_OBJ_NEW_SMALL_INT(unichar_charlen((const char *)str_data, str_len));
|
return MP_OBJ_NEW_SMALL_INT((machine_int_t)unichar_charlen((const char *)str_data, str_len));
|
||||||
default:
|
default:
|
||||||
return MP_OBJ_NULL; // op not supported
|
return MP_OBJ_NULL; // op not supported
|
||||||
}
|
}
|
||||||
|
@ -311,10 +311,10 @@ const mp_obj_type_t mp_type_str = {
|
||||||
.print = uni_print,
|
.print = uni_print,
|
||||||
.make_new = str_make_new,
|
.make_new = str_make_new,
|
||||||
.unary_op = uni_unary_op,
|
.unary_op = uni_unary_op,
|
||||||
.binary_op = str_binary_op,
|
.binary_op = mp_obj_str_binary_op,
|
||||||
.subscr = str_subscr,
|
.subscr = str_subscr,
|
||||||
.getiter = mp_obj_new_str_iterator,
|
.getiter = mp_obj_new_str_iterator,
|
||||||
.buffer_p = { .get_buffer = str_get_buffer },
|
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
|
||||||
.locals_dict = (mp_obj_t)&str_locals_dict,
|
.locals_dict = (mp_obj_t)&str_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,7 @@ machine_uint_t utf8_ptr_to_index(const char *s, const char *ptr) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Rename to str_charlen; return machine_uint_t
|
||||||
uint unichar_charlen(const char *str, uint len)
|
uint unichar_charlen(const char *str, uint len)
|
||||||
{
|
{
|
||||||
#if MICROPY_PY_BUILTINS_STR_UNICODE
|
#if MICROPY_PY_BUILTINS_STR_UNICODE
|
||||||
|
|
Loading…
Reference in New Issue