diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-07-26 19:38:36 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-07-26 19:38:36 +0200 |
| commit | 0f06ef7127b669207fd8f09b88ecb660b38eb971 (patch) | |
| tree | d01a688f33f446b3da809f9a154a8748cb5e6506 /asm.c | |
| parent | 29465804bb9f3bc0eb0f538ec450e9177c0c4767 (diff) | |
| download | tis100-0f06ef7127b669207fd8f09b88ecb660b38eb971.tar.gz tis100-0f06ef7127b669207fd8f09b88ecb660b38eb971.zip | |
Fix more issues caused by negative literals
Diffstat (limited to 'asm.c')
| -rw-r--r-- | asm.c | 32 |
1 files changed, 16 insertions, 16 deletions
@@ -71,18 +71,6 @@ static const char *tok_reprs[] = { }; static bool -is_lit(const char *str) -{ - const char *c; - - c = str; - if (*c == '-') c++; - else if (*c == '+') c++; - for (; *c && isdigit(*c); c++); - return !*c; -} - -static bool is_int(const char *str) { char *end; @@ -95,8 +83,20 @@ is_int(const char *str) return true; } -static int -str_to_lit(const char *str) +bool +asm_is_lit(const char *str) +{ + const char *c; + + c = str; + if (*c == '-') c++; + else if (*c == '+') c++; + for (; *c && isdigit(*c); c++); + return !*c; +} + +int +asm_str_to_lit(const char *str) { int m, v, b, i, o; @@ -147,7 +147,7 @@ tok_to_op(struct asm_tokenizer *tokenizer, enum asm_tok tok) op.type = tok_to_optype(tok); if (op.type == OP_LIT) { - op.val.lit = str_to_lit(tokenizer->tokstr); + op.val.lit = asm_str_to_lit(tokenizer->tokstr); } else if (op.type == OP_LABEL) { op.val.label = strdup(tokenizer->tokstr); if (!op.val.label) die("strdup:"); @@ -231,7 +231,7 @@ tok_next(struct asm_tokenizer *tok) return (enum asm_tok) i; } - if (is_lit(s)) { + if (asm_is_lit(s)) { return TOK_LIT; } else if (*s == '#') { tok->off += strlen(tok->linebuf + tok->off); |
