From fd0c31d4cfd6e220271e43102fb69301d7ffc664 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 22 Jul 2025 16:01:19 -0400 Subject: oasm: Add support for '!' comments Introduce comments, example usage: -- !! !! Double the X5 register by using the !! MUL instruction. !! mul x5, 2 !! wow -- Signed-off-by: Ian Moffett --- usr.bin/oasm/lex.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c index 3ca9e8d..a33a570 100644 --- a/usr.bin/oasm/lex.c +++ b/usr.bin/oasm/lex.c @@ -34,6 +34,7 @@ #include #include +#define COMMENT '!' #define is_num(c) ((c) >= '0' && (c) <= '9') static char putback = '\0'; @@ -268,6 +269,7 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp) { char *p = NULL; char c = ' '; + short in_comment = 0; int tmp; tt_t tok; @@ -276,13 +278,19 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp) } /* - * Grab characters. If they are skippable, - * don't use them. + * Grab characters. If they are skippable or + * comments, don't use them. */ - while (lex_skippable(state, c) == 0) { + while (lex_skippable(state, c) == 0 || in_comment) { if ((c = lex_cin(state)) == 0) { return -1; } + + if (c == COMMENT) { + in_comment = 1; + } else if (c == '\n') { + in_comment = 0; + } } switch (c) { -- cgit v1.2.3