diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-22 16:01:19 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-22 16:01:19 -0400 |
commit | fd0c31d4cfd6e220271e43102fb69301d7ffc664 (patch) | |
tree | 87ade2d6271c48ff9592bdb8cc10a723e1dd885e /usr.bin | |
parent | 7a38e4f8aac5cfe7a4503589a2cf8b953295e04b (diff) |
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 <ian@osmora.org>
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/oasm/lex.c | 14 |
1 files 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 <oasm/lex.h> #include <oasm/log.h> +#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) { |