Fix errors due to no loops

This commit is contained in:
2024-12-03 04:13:40 +00:00
parent 0f0862245f
commit 6ad3e61a2b
2 changed files with 27 additions and 21 deletions

View File

@@ -120,12 +120,15 @@ void asm_translate_nodes(buffer_t **asm_buffer, struct PResult nodes,
const char *src_name)
{
// First pass: Setup the ASM label array
struct Label labels[nodes.labels * 2];
struct Label labels[nodes.labels ? nodes.labels * 2 : 1];
if (nodes.labels)
{
u64 label_ptr = 0;
for (size_t i = 0; i < nodes.size; ++i)
if (nodes.nodes[i].type == LIN || nodes.nodes[i].type == LOUT)
labels[label_ptr++] =
(struct Label){.cur = i, .next = nodes.nodes[i].loop_ref};
}
// Second pass: Translating to assembly
for (size_t i = 0; i < nodes.size; ++i)

View File

@@ -121,9 +121,11 @@ struct PResult parse_buffer(buffer_t *buffer)
}
// Third pass: setup loop references
size_t stackptr = 0;
if (loops)
{
node_t *stack[loops];
memset(stack, 0, loops);
size_t stackptr = 0;
for (size_t i = 0; i < usable; ++i)
{
node_t *node = nodes + i;
@@ -143,6 +145,7 @@ struct PResult parse_buffer(buffer_t *buffer)
stack[stackptr]->loop_ref = i;
}
}
}
if (stackptr > 0)
{