node_t -> ast_node_t
Clearer to understand the intent of node_t as a direct result of parsing source code.
This commit is contained in:
@@ -73,7 +73,7 @@ void asm_translate_nodes(vec_t *asm_buffer, struct PResult nodes,
|
|||||||
// Second pass: Translating to assembly
|
// Second pass: Translating to assembly
|
||||||
for (size_t i = 0; i < nodes.size; ++i)
|
for (size_t i = 0; i < nodes.size; ++i)
|
||||||
{
|
{
|
||||||
node_t node = nodes.nodes[i];
|
ast_node_t node = nodes.nodes[i];
|
||||||
// Something we can compile with only the information at hand
|
// Something we can compile with only the information at hand
|
||||||
if (!(node.type == LIN || node.type == LOUT))
|
if (!(node.type == LIN || node.type == LOUT))
|
||||||
{
|
{
|
||||||
|
|||||||
4
obi.c
4
obi.c
@@ -25,11 +25,11 @@ typedef struct
|
|||||||
#endif
|
#endif
|
||||||
} machine_t;
|
} machine_t;
|
||||||
|
|
||||||
void interpret(machine_t *cpu, node_t *ast, size_t num)
|
void interpret(machine_t *cpu, ast_node_t *ast, size_t num)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < num; ++i)
|
for (size_t i = 0; i < num; ++i)
|
||||||
{
|
{
|
||||||
node_t node = ast[i];
|
ast_node_t node = ast[i];
|
||||||
switch (node.type)
|
switch (node.type)
|
||||||
{
|
{
|
||||||
case NEXT:
|
case NEXT:
|
||||||
|
|||||||
10
parser.c
10
parser.c
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "./parser.h"
|
#include "./parser.h"
|
||||||
|
|
||||||
char *ast_to_str(node_t *ast, size_t size)
|
char *ast_to_str(ast_node_t *ast, size_t size)
|
||||||
{
|
{
|
||||||
char *out = calloc(size + 1, 1);
|
char *out = calloc(size + 1, 1);
|
||||||
if (!out)
|
if (!out)
|
||||||
@@ -54,7 +54,7 @@ char *ast_to_str(node_t *ast, size_t size)
|
|||||||
|
|
||||||
struct PResult parse_buffer(buffer_t *buffer)
|
struct PResult parse_buffer(buffer_t *buffer)
|
||||||
{
|
{
|
||||||
node_t *nodes = NULL;
|
ast_node_t *nodes = NULL;
|
||||||
size_t usable = 0, loops = 0, loop_ends = 0;
|
size_t usable = 0, loops = 0, loop_ends = 0;
|
||||||
|
|
||||||
// First pass: Compute |nodes|
|
// First pass: Compute |nodes|
|
||||||
@@ -161,11 +161,11 @@ struct PResult parse_buffer(buffer_t *buffer)
|
|||||||
size_t stackptr = 0;
|
size_t stackptr = 0;
|
||||||
if (loops)
|
if (loops)
|
||||||
{
|
{
|
||||||
node_t *stack[loops];
|
ast_node_t *stack[loops];
|
||||||
memset(stack, 0, loops);
|
memset(stack, 0, loops);
|
||||||
for (size_t i = 0; i < usable; ++i)
|
for (size_t i = 0; i < usable; ++i)
|
||||||
{
|
{
|
||||||
node_t *node = nodes + i;
|
ast_node_t *node = nodes + i;
|
||||||
if (node->type == LIN)
|
if (node->type == LIN)
|
||||||
stack[stackptr++] = node;
|
stack[stackptr++] = node;
|
||||||
else if (node->type == LOUT)
|
else if (node->type == LOUT)
|
||||||
@@ -180,7 +180,7 @@ struct PResult parse_buffer(buffer_t *buffer)
|
|||||||
|
|
||||||
if (stackptr > 0)
|
if (stackptr > 0)
|
||||||
{
|
{
|
||||||
node_t *node = nodes + usable - 1;
|
ast_node_t *node = nodes + usable - 1;
|
||||||
print_error(buffer->name, node->row, node->col,
|
print_error(buffer->name, node->row, node->col,
|
||||||
"ERROR: Unbalanced square brackets!");
|
"ERROR: Unbalanced square brackets!");
|
||||||
goto error;
|
goto error;
|
||||||
|
|||||||
6
parser.h
6
parser.h
@@ -20,16 +20,16 @@ typedef struct
|
|||||||
size_t col, row;
|
size_t col, row;
|
||||||
node_type_t type;
|
node_type_t type;
|
||||||
int loop_ref;
|
int loop_ref;
|
||||||
} node_t;
|
} ast_node_t;
|
||||||
|
|
||||||
struct PResult
|
struct PResult
|
||||||
{
|
{
|
||||||
node_t *nodes;
|
ast_node_t *nodes;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t labels;
|
size_t labels;
|
||||||
};
|
};
|
||||||
|
|
||||||
char *ast_to_str(node_t *ast, size_t size);
|
char *ast_to_str(ast_node_t *ast, size_t size);
|
||||||
struct PResult parse_buffer(buffer_t *buffer);
|
struct PResult parse_buffer(buffer_t *buffer);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user