@@ -50,25 +50,25 @@ struct _mp_lexer_t {
5050
5151 unichar chr0 , chr1 , chr2 ; // current cached characters from source
5252
53- uint line ; // source line
54- uint column ; // source column
53+ mp_uint_t line ; // source line
54+ mp_uint_t column ; // source column
5555
56- int emit_dent ; // non-zero when there are INDENT/DEDENT tokens to emit
57- int nested_bracket_level ; // >0 when there are nested brackets over multiple lines
56+ mp_int_t emit_dent ; // non-zero when there are INDENT/DEDENT tokens to emit
57+ mp_int_t nested_bracket_level ; // >0 when there are nested brackets over multiple lines
5858
59- uint alloc_indent_level ;
60- uint num_indent_level ;
59+ mp_uint_t alloc_indent_level ;
60+ mp_uint_t num_indent_level ;
6161 uint16_t * indent_level ;
6262
6363 vstr_t vstr ;
6464 mp_token_t tok_cur ;
6565};
6666
67- uint mp_optimise_value ;
67+ mp_uint_t mp_optimise_value ;
6868
6969// TODO replace with a call to a standard function
70- bool str_strn_equal (const char * str , const char * strn , int len ) {
71- uint i = 0 ;
70+ bool str_strn_equal (const char * str , const char * strn , mp_uint_t len ) {
71+ mp_uint_t i = 0 ;
7272
7373 while (i < len && * str == * strn ) {
7474 ++ i ;
@@ -81,7 +81,7 @@ bool str_strn_equal(const char *str, const char *strn, int len) {
8181
8282#ifdef MICROPY_DEBUG_PRINTERS
8383void mp_token_show (const mp_token_t * tok ) {
84- printf ("(%d:%d ) kind:%d str:%p len:%d" , tok -> src_line , tok -> src_column , tok -> kind , tok -> str , tok -> len );
84+ printf ("(" UINT_FMT ":" UINT_FMT " ) kind:%u str:%p len:" UINT_FMT , tok -> src_line , tok -> src_column , tok -> kind , tok -> str , tok -> len );
8585 if (tok -> str != NULL && tok -> len > 0 ) {
8686 const byte * i = (const byte * )tok -> str ;
8787 const byte * j = (const byte * )i + tok -> len ;
@@ -175,7 +175,7 @@ STATIC void next_char(mp_lexer_t *lex) {
175175 return ;
176176 }
177177
178- int advance = 1 ;
178+ mp_uint_t advance = 1 ;
179179
180180 if (lex -> chr0 == '\n' ) {
181181 // LF is a new line
@@ -210,7 +210,7 @@ STATIC void next_char(mp_lexer_t *lex) {
210210 }
211211}
212212
213- void indent_push (mp_lexer_t * lex , uint indent ) {
213+ void indent_push (mp_lexer_t * lex , mp_uint_t indent ) {
214214 if (lex -> num_indent_level >= lex -> alloc_indent_level ) {
215215 // TODO use m_renew_maybe and somehow indicate an error if it fails... probably by using MP_TOKEN_MEMORY_ERROR
216216 lex -> indent_level = m_renew (uint16_t , lex -> indent_level , lex -> alloc_indent_level , lex -> alloc_indent_level + MICROPY_ALLOC_LEXEL_INDENT_INC );
@@ -219,7 +219,7 @@ void indent_push(mp_lexer_t *lex, uint indent) {
219219 lex -> indent_level [lex -> num_indent_level ++ ] = indent ;
220220}
221221
222- uint indent_top (mp_lexer_t * lex ) {
222+ mp_uint_t indent_top (mp_lexer_t * lex ) {
223223 return lex -> indent_level [lex -> num_indent_level - 1 ];
224224}
225225
@@ -308,9 +308,9 @@ STATIC const char *tok_kw[] = {
308308 "__debug__" ,
309309};
310310
311- STATIC int hex_digit (unichar c ) {
311+ STATIC mp_uint_t hex_digit (unichar c ) {
312312 // c is assumed to be hex digit
313- int n = c - '0' ;
313+ mp_uint_t n = c - '0' ;
314314 if (n > 9 ) {
315315 n &= ~('a' - 'A' );
316316 n -= ('A' - ('9' + 1 ));
@@ -320,8 +320,9 @@ STATIC int hex_digit(unichar c) {
320320
321321// This is called with CUR_CHAR() before first hex digit, and should return with
322322// it pointing to last hex digit
323- STATIC bool get_hex (mp_lexer_t * lex , int num_digits , uint * result ) {
324- uint num = 0 ;
323+ // num_digits must be greater than zero
324+ STATIC bool get_hex (mp_lexer_t * lex , mp_uint_t num_digits , mp_uint_t * result ) {
325+ mp_uint_t num = 0 ;
325326 while (num_digits -- != 0 ) {
326327 next_char (lex );
327328 unichar c = CUR_CHAR (lex );
@@ -394,7 +395,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
394395 } else if (had_physical_newline && lex -> nested_bracket_level == 0 ) {
395396 tok -> kind = MP_TOKEN_NEWLINE ;
396397
397- uint num_spaces = lex -> column - 1 ;
398+ mp_uint_t num_spaces = lex -> column - 1 ;
398399 lex -> emit_dent = 0 ;
399400 if (num_spaces == indent_top (lex )) {
400401 } else if (num_spaces > indent_top (lex )) {
@@ -463,7 +464,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
463464 next_char (lex );
464465
465466 // work out if it's a single or triple quoted literal
466- int num_quotes ;
467+ mp_uint_t num_quotes ;
467468 if (is_char_and (lex , quote_char , quote_char )) {
468469 // triple quotes
469470 next_char (lex );
@@ -475,7 +476,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
475476 }
476477
477478 // parse the literal
478- int n_closing = 0 ;
479+ mp_uint_t n_closing = 0 ;
479480 while (!is_end (lex ) && (num_quotes > 1 || !is_char (lex , '\n' )) && n_closing < num_quotes ) {
480481 if (is_char (lex , quote_char )) {
481482 n_closing += 1 ;
@@ -512,7 +513,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
512513 // Otherwise fall through.
513514 case 'x' :
514515 {
515- uint num = 0 ;
516+ mp_uint_t num = 0 ;
516517 if (!get_hex (lex , (c == 'x' ? 2 : c == 'u' ? 4 : 8 ), & num )) {
517518 // TODO error message
518519 assert (0 );
@@ -531,8 +532,8 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
531532 default :
532533 if (c >= '0' && c <= '7' ) {
533534 // Octal sequence, 1-3 chars
534- int digits = 3 ;
535- int num = c - '0' ;
535+ mp_uint_t digits = 3 ;
536+ mp_uint_t num = c - '0' ;
536537 while (is_following_odigit (lex ) && -- digits != 0 ) {
537538 next_char (lex );
538539 num = num * 8 + (CUR_CHAR (lex ) - '0' );
@@ -627,7 +628,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
627628 // search for encoded delimiter or operator
628629
629630 const char * t = tok_enc ;
630- uint tok_enc_index = 0 ;
631+ mp_uint_t tok_enc_index = 0 ;
631632 for (; * t != 0 && !is_char (lex , * t ); t += 1 ) {
632633 if (* t == 'e' || * t == 'c' ) {
633634 t += 1 ;
@@ -649,7 +650,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
649650
650651 // get the maximum characters for a valid token
651652 t += 1 ;
652- uint t_index = tok_enc_index ;
653+ mp_uint_t t_index = tok_enc_index ;
653654 for (;;) {
654655 for (; * t == 'e' ; t += 1 ) {
655656 t += 1 ;
@@ -712,8 +713,8 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
712713 // the parser gives a syntax error on, eg, x.__debug__. Otherwise, we
713714 // need to check for this special token in many places in the compiler.
714715 // TODO improve speed of these string comparisons
715- //for (int i = 0; tok_kw[i] != NULL; i++) {
716- for (int i = 0 ; i < MP_ARRAY_SIZE (tok_kw ); i ++ ) {
716+ //for (mp_int_t i = 0; tok_kw[i] != NULL; i++) {
717+ for (mp_int_t i = 0 ; i < MP_ARRAY_SIZE (tok_kw ); i ++ ) {
717718 if (str_strn_equal (tok_kw [i ], tok -> str , tok -> len )) {
718719 if (i == MP_ARRAY_SIZE (tok_kw ) - 1 ) {
719720 // tok_kw[MP_ARRAY_SIZE(tok_kw) - 1] == "__debug__"
0 commit comments