diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ahoy/main.c | 60 | ||||
-rw-r--r-- | src/c8asm/assembler.c | 8 | ||||
-rw-r--r-- | src/c8asm/common.h | 2 | ||||
-rw-r--r-- | src/c8asm/lexer.c | 2 | ||||
-rw-r--r-- | src/c8asm/parser.c | 52 | ||||
-rw-r--r-- | src/c8asm/parser.h | 2 | ||||
-rw-r--r-- | src/common/cerr.h | 5 | ||||
-rw-r--r-- | src/common/macros.h | 4 |
8 files changed, 67 insertions, 68 deletions
diff --git a/src/ahoy/main.c b/src/ahoy/main.c index f0e9790..df89723 100644 --- a/src/ahoy/main.c +++ b/src/ahoy/main.c @@ -21,19 +21,19 @@ #include "gui.h" #include "macros.h" -#define STRTOX(T, SUF) \ - static T strto##SUF(const char8_t *s, rune *ch) \ - { \ - T n = 0; \ - size_t len = strlen(s); \ - while (u8next(ch, &s, &len)) { \ - if (!(*ch >= '0' && *ch <= '9')) \ - return -1; \ - if (ckd_mul(&n, n, 10) || ckd_add(&n, n, *ch - '0')) \ - return -1; \ - } \ - *ch = '\0'; \ - return n; \ +#define STRTOX(T, SUF) \ + static T strto##SUF(const char8_t *s, rune *ch) \ + { \ + T n = 0; \ + size_t len = strlen(s); \ + while (u8next(ch, &s, &len)) { \ + if (!(*ch >= '0' && *ch <= '9')) \ + return -1; \ + if (ckd_mul(&n, n, 10) || ckd_add(&n, n, *ch - '0')) \ + return -1; \ + } \ + *ch = '\0'; \ + return n; \ } STRTOX(int, i) @@ -58,23 +58,23 @@ usage(void) exit(EXIT_FAILURE); } -#define NUMERIC_ARG(T, M, FMT, F, DST, N) \ - do { \ - rune ch; \ - T n = F(optarg, &ch); \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wtype-limits\""); \ - if (n > M || (ch >= '0' && ch <= '9')) { \ - _Pragma("GCC diagnostic pop"); \ - warnx(N " too high; may not exceed %" FMT, M); \ - usage(); \ - } else if (ch) { \ - char8_t buf[U8_LEN_MAX]; \ - int w = rtou8(buf, ch, sizeof(buf)); \ - warnx("invalid character ‘%.*s’; " N " must be numeric", w, buf); \ - usage(); \ - } \ - cfg.DST = n; \ +#define NUMERIC_ARG(T, M, FMT, F, DST, N) \ + do { \ + rune ch; \ + T n = F(optarg, &ch); \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wtype-limits\""); \ + if (n > M || (ch >= '0' && ch <= '9')) { \ + _Pragma("GCC diagnostic pop"); \ + warnx(N " too high; may not exceed %" FMT, M); \ + usage(); \ + } else if (ch) { \ + char8_t buf[U8_LEN_MAX]; \ + int w = rtou8(buf, ch, sizeof(buf)); \ + warnx("invalid character ‘%.*s’; " N " must be numeric", w, buf); \ + usage(); \ + } \ + cfg.DST = n; \ } while (false) int diff --git a/src/c8asm/assembler.c b/src/c8asm/assembler.c index 9aa356c..df555cc 100644 --- a/src/c8asm/assembler.c +++ b/src/c8asm/assembler.c @@ -68,10 +68,10 @@ pushlabel(struct labels *dst, struct label lbl) void assemble(FILE *stream, struct ast ast) { -#define PUT(X) \ - do { \ - uint16_t __x = htons(X); \ - fwrite(&__x, 1, sizeof(__x), stream); \ +#define PUT(X) \ + do { \ + uint16_t __x = htons(X); \ + fwrite(&__x, 1, sizeof(__x), stream); \ } while (false) bool pad = false; diff --git a/src/c8asm/common.h b/src/c8asm/common.h index aa32b2b..114657a 100644 --- a/src/c8asm/common.h +++ b/src/c8asm/common.h @@ -3,7 +3,7 @@ #include <rune.h> -#define DIE_AT_POS_WITH_CODE(HL, P, ...) \ +#define DIE_AT_POS_WITH_CODE(HL, P, ...) \ die_at_pos_with_code(filename, filebuf, (HL), (P)-baseptr, __VA_ARGS__); extern size_t filesize; diff --git a/src/c8asm/lexer.c b/src/c8asm/lexer.c index 12c96a4..282fd0e 100644 --- a/src/c8asm/lexer.c +++ b/src/c8asm/lexer.c @@ -65,7 +65,7 @@ lexfile(void) return toks; } -#define DIE_AT_POS_WITH_CODE2(HL, ...) \ +#define DIE_AT_POS_WITH_CODE2(HL, ...) \ DIE_AT_POS_WITH_CODE((HL), sv->p - w, __VA_ARGS__) void diff --git a/src/c8asm/parser.c b/src/c8asm/parser.c index 01e13ae..df6f3d0 100644 --- a/src/c8asm/parser.c +++ b/src/c8asm/parser.c @@ -218,33 +218,33 @@ reqnext(const char *want, tokkind msk) #define I(...) ((struct dir){.kind = D_INSTR, .instr = (__VA_ARGS__)}) /* Common implementations of instructions that always take 1 or 2 v-registers */ -#define ONE_VREG(T) \ - do { \ - struct instr ins = {.kind = (T)}; \ - struct token tok = reqnext("v-register", T_IDENT); \ - if (regtype(tok.sv) & ~RT_VX) { \ - DIE_AT_POS_WITH_CODE(tok.sv, tok.sv.p, E_EXPECTED, "v-register", \ - tokrepr(tok.kind)); \ - } \ - ins.args[ins.len++].val = hexval(tok.sv.p[1]); \ - dapush(&ast, I(ins)); \ +#define ONE_VREG(T) \ + do { \ + struct instr ins = {.kind = (T)}; \ + struct token tok = reqnext("v-register", T_IDENT); \ + if (regtype(tok.sv) & ~RT_VX) { \ + DIE_AT_POS_WITH_CODE(tok.sv, tok.sv.p, E_EXPECTED, "v-register", \ + tokrepr(tok.kind)); \ + } \ + ins.args[ins.len++].val = hexval(tok.sv.p[1]); \ + dapush(&ast, I(ins)); \ } while (false) -#define TWO_VREG(T) \ - do { \ - struct instr ins = {.kind = (T)}; \ - struct token lhs = reqnext("v-register", T_IDENT); \ - struct token rhs = reqnext("v-register", T_IDENT); \ - if (regtype(lhs.sv) & ~RT_VX) { \ - DIE_AT_POS_WITH_CODE(lhs.sv, lhs.sv.p, E_EXPECTED, "v-register", \ - tokrepr(lhs.kind)); \ - } \ - if (regtype(rhs.sv) & ~RT_VX) { \ - DIE_AT_POS_WITH_CODE(rhs.sv, rhs.sv.p, E_EXPECTED, "v-register", \ - tokrepr(rhs.kind)); \ - } \ - ins.args[ins.len++].val = hexval(lhs.sv.p[1]); \ - ins.args[ins.len++].val = hexval(rhs.sv.p[1]); \ - dapush(&ast, I(ins)); \ +#define TWO_VREG(T) \ + do { \ + struct instr ins = {.kind = (T)}; \ + struct token lhs = reqnext("v-register", T_IDENT); \ + struct token rhs = reqnext("v-register", T_IDENT); \ + if (regtype(lhs.sv) & ~RT_VX) { \ + DIE_AT_POS_WITH_CODE(lhs.sv, lhs.sv.p, E_EXPECTED, "v-register", \ + tokrepr(lhs.kind)); \ + } \ + if (regtype(rhs.sv) & ~RT_VX) { \ + DIE_AT_POS_WITH_CODE(rhs.sv, rhs.sv.p, E_EXPECTED, "v-register", \ + tokrepr(rhs.kind)); \ + } \ + ins.args[ins.len++].val = hexval(lhs.sv.p[1]); \ + ins.args[ins.len++].val = hexval(rhs.sv.p[1]); \ + dapush(&ast, I(ins)); \ } while (false) void diff --git a/src/c8asm/parser.h b/src/c8asm/parser.h index a8cc03c..259d805 100644 --- a/src/c8asm/parser.h +++ b/src/c8asm/parser.h @@ -20,7 +20,7 @@ typedef enum { I_DRW, I_HEX, I_JP_A, - I_JP_V0_A, + I_JP_V0_ADDR, I_LD_DT, I_LD_I, I_LD_ST, diff --git a/src/common/cerr.h b/src/common/cerr.h index 5476f96..5910c74 100644 --- a/src/common/cerr.h +++ b/src/common/cerr.h @@ -17,8 +17,7 @@ void diex(const char *, ...); void die_with_off(const char *, size_t, const char *, ...); [[noreturn, gnu::nonnull, gnu::format(printf, 5, 6)]] -void -die_at_pos_with_code(const char *, struct u8view, struct u8view, size_t, - const char *, ...); +void die_at_pos_with_code(const char *, struct u8view, struct u8view, size_t, + const char *, ...); #endif /* !AHOY_COMMON_CERR_H */ diff --git a/src/common/macros.h b/src/common/macros.h index 3735af6..f53a508 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -11,8 +11,8 @@ #if DEBUG # include "cerr.h" -# define assume(C) \ - ((C) ? (void)0 \ +# define assume(C) \ + ((C) ? (void)0 \ : diex("%s:%d: %s(): assumption ‘%s’ failed", __FILE__, __LINE__, \ __func__, #C)) #else |