py/lexer: Convert mp_uint_t to size_t where appropriate.
This commit is contained in:
parent
d87c6b6768
commit
5124a94067
16
py/lexer.c
16
py/lexer.c
@ -157,7 +157,7 @@ STATIC void next_char(mp_lexer_t *lex) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void indent_push(mp_lexer_t *lex, mp_uint_t indent) {
|
||||
STATIC void indent_push(mp_lexer_t *lex, size_t indent) {
|
||||
if (lex->num_indent_level >= lex->alloc_indent_level) {
|
||||
// TODO use m_renew_maybe and somehow indicate an error if it fails... probably by using MP_TOKEN_MEMORY_ERROR
|
||||
lex->indent_level = m_renew(uint16_t, lex->indent_level, lex->alloc_indent_level, lex->alloc_indent_level + MICROPY_ALLOC_LEXEL_INDENT_INC);
|
||||
@ -166,7 +166,7 @@ STATIC void indent_push(mp_lexer_t *lex, mp_uint_t indent) {
|
||||
lex->indent_level[lex->num_indent_level++] = indent;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t indent_top(mp_lexer_t *lex) {
|
||||
STATIC size_t indent_top(mp_lexer_t *lex) {
|
||||
return lex->indent_level[lex->num_indent_level - 1];
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ STATIC const char *const tok_kw[] = {
|
||||
// This is called with CUR_CHAR() before first hex digit, and should return with
|
||||
// it pointing to last hex digit
|
||||
// num_digits must be greater than zero
|
||||
STATIC bool get_hex(mp_lexer_t *lex, mp_uint_t num_digits, mp_uint_t *result) {
|
||||
STATIC bool get_hex(mp_lexer_t *lex, size_t num_digits, mp_uint_t *result) {
|
||||
mp_uint_t num = 0;
|
||||
while (num_digits-- != 0) {
|
||||
next_char(lex);
|
||||
@ -354,7 +354,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
|
||||
default:
|
||||
if (c >= '0' && c <= '7') {
|
||||
// Octal sequence, 1-3 chars
|
||||
mp_uint_t digits = 3;
|
||||
size_t digits = 3;
|
||||
mp_uint_t num = c - '0';
|
||||
while (is_following_odigit(lex) && --digits != 0) {
|
||||
next_char(lex);
|
||||
@ -458,7 +458,7 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
|
||||
} else if (had_physical_newline && lex->nested_bracket_level == 0) {
|
||||
lex->tok_kind = MP_TOKEN_NEWLINE;
|
||||
|
||||
mp_uint_t num_spaces = lex->column - 1;
|
||||
size_t num_spaces = lex->column - 1;
|
||||
if (num_spaces == indent_top(lex)) {
|
||||
} else if (num_spaces > indent_top(lex)) {
|
||||
indent_push(lex, num_spaces);
|
||||
@ -622,7 +622,7 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
|
||||
// search for encoded delimiter or operator
|
||||
|
||||
const char *t = tok_enc;
|
||||
mp_uint_t tok_enc_index = 0;
|
||||
size_t tok_enc_index = 0;
|
||||
for (; *t != 0 && !is_char(lex, *t); t += 1) {
|
||||
if (*t == 'e' || *t == 'c') {
|
||||
t += 1;
|
||||
@ -644,7 +644,7 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
|
||||
|
||||
// get the maximum characters for a valid token
|
||||
t += 1;
|
||||
mp_uint_t t_index = tok_enc_index;
|
||||
size_t t_index = tok_enc_index;
|
||||
for (;;) {
|
||||
for (; *t == 'e'; t += 1) {
|
||||
t += 1;
|
||||
@ -762,7 +762,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
|
||||
return lex;
|
||||
}
|
||||
|
||||
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, mp_uint_t len, mp_uint_t free_len) {
|
||||
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, size_t len, size_t free_len) {
|
||||
mp_reader_t reader;
|
||||
if (!mp_reader_new_mem(&reader, (const byte*)str, len, free_len)) {
|
||||
return NULL;
|
||||
|
14
py/lexer.h
14
py/lexer.h
@ -151,24 +151,24 @@ typedef struct _mp_lexer_t {
|
||||
|
||||
unichar chr0, chr1, chr2; // current cached characters from source
|
||||
|
||||
mp_uint_t line; // current source line
|
||||
mp_uint_t column; // current source column
|
||||
size_t line; // current source line
|
||||
size_t column; // current source column
|
||||
|
||||
mp_int_t emit_dent; // non-zero when there are INDENT/DEDENT tokens to emit
|
||||
mp_int_t nested_bracket_level; // >0 when there are nested brackets over multiple lines
|
||||
|
||||
mp_uint_t alloc_indent_level;
|
||||
mp_uint_t num_indent_level;
|
||||
size_t alloc_indent_level;
|
||||
size_t num_indent_level;
|
||||
uint16_t *indent_level;
|
||||
|
||||
mp_uint_t tok_line; // token source line
|
||||
mp_uint_t tok_column; // token source column
|
||||
size_t tok_line; // token source line
|
||||
size_t tok_column; // token source column
|
||||
mp_token_kind_t tok_kind; // token kind
|
||||
vstr_t vstr; // token data
|
||||
} mp_lexer_t;
|
||||
|
||||
mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader);
|
||||
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, mp_uint_t len, mp_uint_t free_len);
|
||||
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, size_t len, size_t free_len);
|
||||
|
||||
void mp_lexer_free(mp_lexer_t *lex);
|
||||
void mp_lexer_to_next(mp_lexer_t *lex);
|
||||
|
Loading…
Reference in New Issue
Block a user