compile.c: Extract common ilist put code into macro
This commit is contained in:
parent
2c04e57a0c
commit
4b9170969b
1 changed files with 15 additions and 36 deletions
|
|
@ -56,60 +56,39 @@ ilist_ensure_cap(struct compiler *compiler, struct instruction_list *ilist, size
|
|||
));
|
||||
}
|
||||
|
||||
#define ILIST_PUT(ilist, member, data, dbgfmt, ...) \
|
||||
assert(ilist->cap > 0); \
|
||||
assert(ilist->len < ilist->cap); \
|
||||
\
|
||||
ilist->instructions[ilist->len] = (union instruction_or_arg) { \
|
||||
.member = data, \
|
||||
}; \
|
||||
ilist->len++; \
|
||||
\
|
||||
DEBUG_LOG("ilist %p " dbgfmt "\n", (void *)ilist, __VA_ARGS__);
|
||||
|
||||
static void
|
||||
ilist_put_insn(struct instruction_list *ilist, enum instruction instruction)
|
||||
{
|
||||
assert(ilist->cap > 0);
|
||||
assert(ilist->len < ilist->cap);
|
||||
|
||||
ilist->instructions[ilist->len] = (union instruction_or_arg) {
|
||||
.instruction = instruction,
|
||||
};
|
||||
ilist->len++;
|
||||
|
||||
DEBUG_LOG("put_insn: %s\n", apfl_instruction_to_string(instruction));
|
||||
ILIST_PUT(ilist, instruction, instruction, "put_insn: %s", apfl_instruction_to_string(instruction))
|
||||
}
|
||||
|
||||
static void
|
||||
ilist_put_number(struct instruction_list *ilist, apfl_number number)
|
||||
{
|
||||
assert(ilist->cap > 0);
|
||||
assert(ilist->len < ilist->cap);
|
||||
|
||||
ilist->instructions[ilist->len] = (union instruction_or_arg) {
|
||||
.number = number
|
||||
};
|
||||
ilist->len++;
|
||||
|
||||
DEBUG_LOG("put_number: %lf\n", number);
|
||||
ILIST_PUT(ilist, number, number, "put_number: %lf", number)
|
||||
}
|
||||
|
||||
static void
|
||||
ilist_put_count(struct instruction_list *ilist, size_t count)
|
||||
{
|
||||
assert(ilist->cap > 0);
|
||||
assert(ilist->len < ilist->cap);
|
||||
|
||||
ilist->instructions[ilist->len] = (union instruction_or_arg) {
|
||||
.count = count
|
||||
};
|
||||
ilist->len++;
|
||||
|
||||
DEBUG_LOG("put_count: %d\n", (int)count);
|
||||
ILIST_PUT(ilist, count, count, "put_count: %d", (int)count)
|
||||
}
|
||||
|
||||
static void
|
||||
ilist_put_string(struct instruction_list *ilist, struct apfl_string *string)
|
||||
{
|
||||
assert(ilist->cap > 0);
|
||||
assert(ilist->len < ilist->cap);
|
||||
|
||||
ilist->instructions[ilist->len] = (union instruction_or_arg) {
|
||||
.string = string
|
||||
};
|
||||
ilist->len++;
|
||||
|
||||
DEBUG_LOG("put_string: " APFL_STR_FMT "\n", APFL_STR_FMT_ARGS(*string));
|
||||
ILIST_PUT(ilist, string, string, "put_string: " APFL_STR_FMT, APFL_STR_FMT_ARGS(*string))
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
|||
Loading…
Reference in a new issue