Skip to content

Commit

Permalink
preparing node
Browse files Browse the repository at this point in the history
  • Loading branch information
omdxp committed Mar 16, 2024
1 parent e229185 commit 58521d9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OBJECTS= ./build/compiler.o ./build/cprocess.o ./build/lexer.o ./build/token.o ./build/lex_process.o ./build/parser.o ./build/helpers/buffer.o ./build/helpers/vector.o
OBJECTS= ./build/compiler.o ./build/cprocess.o ./build/lexer.o ./build/token.o ./build/lex_process.o ./build/parser.o ./build/node.o ./build/helpers/buffer.o ./build/helpers/vector.o
INCLUDES= -I./

all: ${OBJECTS}
Expand All @@ -22,6 +22,9 @@ all: ${OBJECTS}
./build/parser.o: ./parser.c
gcc ./parser.c ${INCLUDES} -o ./build/parser.o -g -c

./build/node.o: ./node.c
gcc ./node.c ${INCLUDES} -o ./build/node.o -g -c

./build/helpers/buffer.o: ./helpers/buffer.c
gcc ./helpers/buffer.c ${INCLUDES} -o ./build/helpers/buffer.o -g -c

Expand Down
42 changes: 42 additions & 0 deletions node.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "compiler.h"
#include "helpers/vector.h"
#include <assert.h>

struct vector *node_vector = NULL;
struct vector *node_vector_root = NULL;

void node_set_vector(struct vector *vec, struct vector *root_vec)
{
node_vector = vec;
node_vector_root = root_vec;
}

void node_push(struct node *node)
{
vector_push(node_vector, &node);
}

struct node *node_peek_or_null()
{
return vector_back_ptr_or_null(node_vector);
}

struct node *node_peek()
{
return *(struct node **)(vector_back(node_vector));
}

struct node *node_pop()
{
struct node *last_node = vector_back_ptr(node_vector);
struct node *last_node_root = vector_empty(node_vector) ? NULL : vector_back_ptr(node_vector_root);

vector_pop(node_vector);

if (last_node == last_node_root)
{
vector_pop(node_vector_root);
}

return last_node;
}

0 comments on commit 58521d9

Please sign in to comment.