summaryrefslogtreecommitdiffstatshomepage
path: root/py/lexer.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-07-18 12:44:44 +1000
committerDamien George <damien@micropython.org>2024-07-18 12:44:44 +1000
commit96007e7de55810b20134b050c80cbc7a6d1d5a57 (patch)
tree5e6869f5f9e742494f98499152e4108b8732a898 /py/lexer.c
parente00d80d9e27552760603b507c77aad6f5705174f (diff)
downloadmicropython-96007e7de55810b20134b050c80cbc7a6d1d5a57.tar.gz
micropython-96007e7de55810b20134b050c80cbc7a6d1d5a57.zip
py/lexer: Add static assert that token enum values all fit in a byte.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/lexer.c')
-rw-r--r--py/lexer.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/py/lexer.c b/py/lexer.c
index 48497663c5..98a10c87b2 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -228,7 +228,6 @@ static const char *const tok_enc =
"=e=" // = ==
"!."; // start of special cases: != . ...
-// TODO static assert that number of tokens is less than 256 so we can safely make this table with byte sized entries
static const uint8_t tok_enc_kind[] = {
MP_TOKEN_DEL_PAREN_OPEN, MP_TOKEN_DEL_PAREN_CLOSE,
MP_TOKEN_DEL_BRACKET_OPEN, MP_TOKEN_DEL_BRACKET_CLOSE,
@@ -774,6 +773,9 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
} else {
// search for encoded delimiter or operator
+ // assert that the token enum value fits in a byte, so they all fit in tok_enc_kind
+ MP_STATIC_ASSERT(MP_TOKEN_NUMBER_OF <= 256);
+
const char *t = tok_enc;
size_t tok_enc_index = 0;
for (; *t != 0 && !is_char(lex, *t); t += 1) {