aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-18 21:27:24 +0200
committerBad Diode <bd@badd10de.dev>2024-06-18 21:27:24 +0200
commitad14773fcebdbd989c1d7c3245b59a1cae666d2f (patch)
treea7eb2ceebfc7c89fd04a143d535b5701de5bfa98
parent3d88e46dd0d1b54bc0a414b5db42ed76ddc08363 (diff)
downloadbdl-ad14773fcebdbd989c1d7c3245b59a1cae666d2f.tar.gz
bdl-ad14773fcebdbd989c1d7c3245b59a1cae666d2f.zip
Add `tests` target to makefile
-rw-r--r--Makefile28
-rw-r--r--src/main.c18
2 files changed, 33 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index b6419fd..5af466c 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,10 @@
4# Source code location and files to watch for changes. 4# Source code location and files to watch for changes.
5SRC_DIR := src 5SRC_DIR := src
6BUILD_DIR := build 6BUILD_DIR := build
7TESTS_DIR := tests
8TEST_FILES := $(wildcard $(TESTS_DIR)/*.bad)
7SRC_MAIN := $(SRC_DIR)/main.c 9SRC_MAIN := $(SRC_DIR)/main.c
8SRC_BAD := tests/conditionals.bad 10SRC_RUN := tests/conditionals.bad
9WATCH_SRC := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h") 11WATCH_SRC := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h")
10INC_DIRS := $(shell find $(SRC_DIR) -type d) 12INC_DIRS := $(shell find $(SRC_DIR) -type d)
11INC_FLAGS := $(addprefix -I,$(INC_DIRS)) 13INC_FLAGS := $(addprefix -I,$(INC_DIRS))
@@ -45,7 +47,7 @@ endif
45 47
46main: $(BIN) 48main: $(BIN)
47 49
48$(BIN): $(SRC_MAIN) $(WATCH_SRC) $(BUILD_DIR) 50$(BIN): $(SRC_MAIN) $(WATCH_SRC) | $(BUILD_DIR)
49 $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(SRC_MAIN) $(LDLIBS) 51 $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(SRC_MAIN) $(LDLIBS)
50 52
51# Create build directory if needed. 53# Create build directory if needed.
@@ -53,22 +55,28 @@ $(BUILD_DIR):
53 mkdir -p $(BUILD_DIR) 55 mkdir -p $(BUILD_DIR)
54 56
55run: $(BIN) 57run: $(BIN)
56 $(BIN) $(SRC_BAD) 58 $(BIN) $(SRC_RUN)
57 59
58graph-tokens: $(BIN) 60graph-tokens: $(BIN)
59 $(BIN) -pl $(SRC_BAD) 61 $(BIN) -pl $(SRC_RUN)
60 62
61graph-parse: $(BIN) 63graph-parse: $(BIN)
62 @echo "parsing tree for: '$(SRC_BAD)'" 64 @echo "parsing tree for: '$(SRC_RUN)'"
63 @$(BIN) -pp $(SRC_BAD) | $(DOT) 65 @$(BIN) -pp $(SRC_RUN) | $(DOT)
64 66
65graph-semantic: $(BIN) 67graph-semantic: $(BIN)
66 @echo "semantic tree for: '$(SRC_BAD)'" 68 @echo "semantic tree for: '$(SRC_RUN)'"
67 @$(BIN) -ps $(SRC_BAD) | $(DOT) 69 @$(BIN) -ps $(SRC_RUN) | $(DOT)
68 70
69graph-symbols: $(BIN) 71graph-symbols: $(BIN)
70 @echo "symbol table for: '$(SRC_BAD)'" 72 @echo "symbol table for: '$(SRC_RUN)'"
71 @$(BIN) -pt $(SRC_BAD) | $(DOT) 73 @$(BIN) -pt $(SRC_RUN) | $(DOT)
74
75tests: $(BIN)
76 @for name in $(TEST_FILES); do\
77 printf "$${name}\r" ;\
78 $(BIN) $${name} && printf "$${name}\tOK!\n";\
79 done
72 80
73# Remove build directory. 81# Remove build directory.
74clean: 82clean:
diff --git a/src/main.c b/src/main.c
index 68ad857..1c0d2e1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -80,6 +80,8 @@ typedef enum NodeKind {
80 NODE_CASE, 80 NODE_CASE,
81 NODE_COND, 81 NODE_COND,
82 NODE_ENUM, 82 NODE_ENUM,
83 NODE_BREAK,
84 NODE_CONTINUE,
83 // Helpers. 85 // Helpers.
84 NODE_SYMBOL_IDX, 86 NODE_SYMBOL_IDX,
85 NODE_TYPE, 87 NODE_TYPE,
@@ -131,6 +133,8 @@ Str node_str[] = {
131 [NODE_CASE] = cstr("CASE"), 133 [NODE_CASE] = cstr("CASE"),
132 [NODE_COND] = cstr("COND"), 134 [NODE_COND] = cstr("COND"),
133 [NODE_ENUM] = cstr("ENUM"), 135 [NODE_ENUM] = cstr("ENUM"),
136 [NODE_BREAK] = cstr("BREAK"),
137 [NODE_CONTINUE] = cstr("CONTINUE"),
134 // Helpers. 138 // Helpers.
135 [NODE_TYPE] = cstr("TYPE"), 139 [NODE_TYPE] = cstr("TYPE"),
136 [NODE_ARR_TYPE] = cstr("TYPE (ARR)"), 140 [NODE_ARR_TYPE] = cstr("TYPE (ARR)"),
@@ -663,6 +667,14 @@ parse_keyword(Parser *parser) {
663 array_push(node->match_cases, tmp, parser->storage); 667 array_push(node->match_cases, tmp, parser->storage);
664 } 668 }
665 } break; 669 } break;
670 case TOK_BREAK: {
671 node = node_alloc(parser, NODE_BREAK, prev);
672 if (!node) return;
673 } break;
674 case TOK_CONTINUE: {
675 node = node_alloc(parser, NODE_CONTINUE, prev);
676 if (!node) return;
677 } break;
666 default: return; // Unreachable. 678 default: return; // Unreachable.
667 } 679 }
668 array_push(parser->nodes, node, parser->storage); 680 array_push(parser->nodes, node, parser->storage);
@@ -966,7 +978,7 @@ process_file(Str path) {
966 FileContents file = platform_read_file(path, &lexer_arena); 978 FileContents file = platform_read_file(path, &lexer_arena);
967 if (file.err) { 979 if (file.err) {
968 eprintln("%s: error: %s", path, cstr("WOT")); 980 eprintln("%s: error: %s", path, cstr("WOT"));
969 return; 981 exit(EXIT_FAILURE);
970 } 982 }
971 sz errors = 0; 983 sz errors = 0;
972 984
@@ -986,7 +998,7 @@ process_file(Str path) {
986 } 998 }
987 // Only proceed if there are no errors. 999 // Only proceed if there are no errors.
988 if (errors) { 1000 if (errors) {
989 goto stop; 1001 exit(EXIT_FAILURE);
990 } 1002 }
991 if (mode == PRINT_LEX) { 1003 if (mode == PRINT_LEX) {
992 print_tokens(path, tokens); 1004 print_tokens(path, tokens);
@@ -1011,7 +1023,7 @@ process_file(Str path) {
1011 } 1023 }
1012 } 1024 }
1013 if (parser.err) { 1025 if (parser.err) {
1014 goto stop; 1026 exit(EXIT_FAILURE);
1015 } 1027 }
1016 if (mode == PRINT_PARSE) { 1028 if (mode == PRINT_PARSE) {
1017 graph_ast(parser.nodes); 1029 graph_ast(parser.nodes);