aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorc2023-12-24 10:28:00 -0500
committerc2023-12-24 10:28:00 -0500
commite39267c83a8af189a624891813ebd6014543b01a (patch)
treec6ad5a39246e4560f6efd77b9d2e4383394bbbf9 /src/include
parent1494ecaeba2307e489b1df210abb3c63415419ed (diff)
Proper tests.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/main.h14
-rw-r--r--src/include/stack.h23
-rw-r--r--src/include/test.h27
-rw-r--r--src/include/tree.h24
4 files changed, 52 insertions, 36 deletions
diff --git a/src/include/main.h b/src/include/main.h
new file mode 100644
index 0000000..63dd15c
--- /dev/null
+++ b/src/include/main.h
@@ -0,0 +1,14 @@
+#ifndef MAIN_H
+#define MAIN_H
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "util.h"
+#include "source.h"
+#include "token.h"
+#include "pp.h"
+#include "lexer.h"
+#include "parser.h"
+
+#endif
diff --git a/src/include/stack.h b/src/include/stack.h
new file mode 100644
index 0000000..7a16366
--- /dev/null
+++ b/src/include/stack.h
@@ -0,0 +1,23 @@
+#ifndef STACK_H
+#define STACK_H
+
+#include <stdlib.h>
+#include "util.h"
+
+#define STACK_MAXLEN 256
+
+typedef struct STACK {
+ int sp; /* Index of first unused element of val. */
+ void* val[STACK_MAXLEN];
+} stack_t;
+
+stack_t* stack_init();
+void stack_destroy(stack_t*);
+
+void stack_push(stack_t* stack, void* val);
+void* stack_pop(stack_t* stack);
+size_t stack_len(stack_t* stack);
+
+void stack_print(stack_t* stack);
+
+#endif
diff --git a/src/include/test.h b/src/include/test.h
deleted file mode 100644
index e862467..0000000
--- a/src/include/test.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef TEST_H
-#define TEST_H
-
-#include "util.h"
-
-#ifdef TEST
-
-unsigned int TESTS_RUN = 0;
-unsigned int TESTS_PASSED = 0;
-
-#define ASSERT(EXPR) \
- TESTS_RUN++; \
- (EXPR && ++TESTS_PASSED) ? \
- log_yay("Assertion passed!") : \
- log_err("%s:%d: Assertion failed:\n\t%s", __FILE__, __LINE__, #EXPR);
-
-#define TEST_REPORT \
- (TESTS_RUN == TESTS_PASSED) ? \
- log_yay("All %d tests passed!", TESTS_RUN) : \
- log_err("%d/%d tests failed.", TESTS_RUN - TESTS_PASSED, TESTS_RUN);
-
-#else
-#define ASSERT(EXPR) NULL;
-#define TEST_REPORT NULL;
-#endif
-
-#endif
diff --git a/src/include/tree.h b/src/include/tree.h
index 20d97be..8b8e14a 100644
--- a/src/include/tree.h
+++ b/src/include/tree.h
@@ -4,15 +4,15 @@
#include "util.h"
typedef enum TREE_TYPE {
- TREE_TYPE_BLOCK,
- TREE_TYPE_EXPR,
- TREE_TYPE_LINT,
- TREE_TYPE_LSTR,
- TREE_TYPE_TAG,
- TREE_TYPE_DARG,
- TREE_TYPE_CARG,
- TREE_TYPE_DEF,
- TREE_TYPE_CALL,
+ TREE_TYPE_BLOCK,
+ TREE_TYPE_EXPR,
+ TREE_TYPE_LINT,
+ TREE_TYPE_LSTR,
+ TREE_TYPE_TAG,
+ TREE_TYPE_DARG,
+ TREE_TYPE_CARG,
+ TREE_TYPE_DEF,
+ TREE_TYPE_CALL,
} tree_type_t;
/* The Abstract Syntax Tree (AST) structure. */
@@ -86,6 +86,12 @@ tree_t* tree_init(int type);
/* Destroy the AST. */
void tree_destroy(tree_t* tree);
+/*
+ Compare two trees. For testing.
+ Returns 1 if the same, otherwise 0.
+*/
+int tree_cmp(tree_t* tree_0, tree_t* tree_1);
+
/* Print a tree. */
void tree_print(tree_t* tree, int nest);