diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-15 00:24:21 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-15 00:24:21 +0200 |
commit | 1d2f07f27aa0862e88ee44c85930284932742fa0 (patch) | |
tree | 856071b41364fac0ea8bb6e64e4c18305d70ae2e /src | |
parent | d14873524d41f4c1537d29392f3e4bb234bd6785 (diff) | |
download | bdl-1d2f07f27aa0862e88ee44c85930284932742fa0.tar.gz bdl-1d2f07f27aa0862e88ee44c85930284932742fa0.zip |
Fix some __VA_ARGS__ macro issues (ugh)
Diffstat (limited to 'src')
-rw-r--r-- | src/badlib.h | 26 | ||||
-rw-r--r-- | src/main.c | 31 |
2 files changed, 29 insertions, 28 deletions
diff --git a/src/badlib.h b/src/badlib.h index 837d377..496f106 100644 --- a/src/badlib.h +++ b/src/badlib.h | |||
@@ -16,22 +16,16 @@ | |||
16 | // thing or at least a small range). | 16 | // thing or at least a small range). |
17 | // | 17 | // |
18 | 18 | ||
19 | #include <stdarg.h> | ||
19 | #include <stdbool.h> | 20 | #include <stdbool.h> |
20 | #include <stddef.h> | 21 | #include <stddef.h> |
21 | #include <stdint.h> | 22 | #include <stdint.h> |
22 | #include <stdio.h> | 23 | #include <stdio.h> |
23 | #include <stdlib.h> | 24 | #include <stdlib.h> |
24 | #include <strings.h> | 25 | #include <strings.h> |
25 | #define printstr(s) \ | ||
26 | if (s) printf("%.*s", (int)(s)->size, (s)->mem); | ||
27 | #define printstrln(s) \ | ||
28 | if (s) printf("%.*s\n", (int)(s)->size, (s)->mem); | ||
29 | 26 | ||
30 | // | 27 | // |
31 | // This simple header just typedefs the basic C define types to a shorter name, | 28 | // Basic types. |
32 | // loads the quality of life bool macro for _Bool and defines shorthand macros | ||
33 | // for byte sizes. We need that the targeted architecture uses the floating | ||
34 | // point representation as described on the IEEE-754 standard. | ||
35 | // | 29 | // |
36 | 30 | ||
37 | _Static_assert(sizeof(double) == 8, "no support for IEEE-754"); | 31 | _Static_assert(sizeof(double) == 8, "no support for IEEE-754"); |
@@ -1119,8 +1113,6 @@ log_float(Logger *l, f64 num, sz precision) { | |||
1119 | log_int(l, fractional); | 1113 | log_int(l, fractional); |
1120 | } | 1114 | } |
1121 | 1115 | ||
1122 | #include <stdarg.h> | ||
1123 | |||
1124 | void | 1116 | void |
1125 | log_print(Logger *l, Str format, ...) { | 1117 | log_print(Logger *l, Str format, ...) { |
1126 | assert(l); | 1118 | assert(l); |
@@ -1287,12 +1279,18 @@ log_init(sz memsize, FILE *dest, Arena arena) { | |||
1287 | 1279 | ||
1288 | // Default loggers and convenience macros for printing. | 1280 | // Default loggers and convenience macros for printing. |
1289 | Logger logger_inf, logger_err; | 1281 | Logger logger_inf, logger_err; |
1290 | #define print(format, ...) \ | 1282 | |
1283 | #define _print(format, ...) \ | ||
1291 | log_print(&logger_inf, (Str){(u8 *)(format), LEN(format) - 1}, __VA_ARGS__) | 1284 | log_print(&logger_inf, (Str){(u8 *)(format), LEN(format) - 1}, __VA_ARGS__) |
1292 | #define println(format, ...) print(format "\n", __VA_ARGS__) | 1285 | #define _println(format, ...) print(format "\n", __VA_ARGS__) |
1293 | #define printerr(format, ...) \ | 1286 | #define print(...) _print(__VA_ARGS__, "") |
1287 | #define println(...) _println(__VA_ARGS__, "") | ||
1288 | |||
1289 | #define _printerr(format, ...) \ | ||
1294 | log_print(&logger_err, (Str){(u8 *)(format), LEN(format) - 1}, __VA_ARGS__) | 1290 | log_print(&logger_err, (Str){(u8 *)(format), LEN(format) - 1}, __VA_ARGS__) |
1295 | #define printerrln(format, ...) printerr(format "\n", __VA_ARGS__) | 1291 | #define _printerrln(format, ...) printerr(format "\n", __VA_ARGS__) |
1292 | #define printerr(...) _printerr(__VA_ARGS__, "") | ||
1293 | #define printerrln(...) _printerrln(__VA_ARGS__, "") | ||
1296 | 1294 | ||
1297 | void | 1295 | void |
1298 | log_func_register(Logger *l, LogFuncMap map) { | 1296 | log_func_register(Logger *l, LogFuncMap map) { |
@@ -17,29 +17,30 @@ static ExecMode mode = RUN_NORMAL; | |||
17 | #define LEXER_MEM GB(2) | 17 | #define LEXER_MEM GB(2) |
18 | 18 | ||
19 | void | 19 | void |
20 | init(void) { | ||
21 | log_init_default(); | ||
22 | } | ||
23 | |||
24 | void | ||
20 | process_file(Str path) { | 25 | process_file(Str path) { |
21 | printf("processing: "); | 26 | println("processing: "); |
22 | printstrln(&path); | 27 | println("%s", path); |
23 | printf("initialing memory...\n"); | 28 | println("initialing memory..."); |
24 | Arena lexer_arena = arena_create(LEXER_MEM, os_allocator); | 29 | Arena lexer_arena = arena_create(LEXER_MEM, os_allocator); |
25 | printf("reading file...\n"); | 30 | println("reading file..."); |
26 | FileContents file = platform_read_file(path, &lexer_arena); | 31 | FileContents file = platform_read_file(path, &lexer_arena); |
27 | 32 | ||
28 | Str scanner = file.data; | 33 | Str scanner = file.data; |
29 | Str line = str_split(&scanner, cstr("\n")); | ||
30 | printf("%04d ", 1); | ||
31 | printstrln(&line); | ||
32 | // NOTE: Testing file read line by line. | 34 | // NOTE: Testing file read line by line. |
33 | // for (sz i = 0; scanner.size != 0; i++) { | 35 | for (sz i = 0; scanner.size != 0; i++) { |
34 | // Str line = str_split(&scanner, cstr("\n")); | 36 | Str line = str_split(&scanner, cstr("\n")); |
35 | // printf("%04ld ", i + 1); | 37 | println("%x{4} %s", i + 1, line); |
36 | // printstrln(&line); | 38 | } |
37 | // } | ||
38 | 39 | ||
39 | log_init_default(); | ||
40 | println("<<< %x{4} %b{4} %f{2} %s %{Arena} >>>", 123, 3, 1.345, | 40 | println("<<< %x{4} %b{4} %f{2} %s %{Arena} >>>", 123, 3, 1.345, |
41 | cstr("BOOM!"), &logger_inf.storage); | 41 | cstr("BOOM!"), &logger_inf.storage); |
42 | printerrln("%s:%d:%d: %s", path, 1, 1, cstr("error: testing string logger")); | 42 | printerrln("%s:%d:%d: %s", path, 1, 1, |
43 | cstr("error: testing string logger")); | ||
43 | 44 | ||
44 | // TODO: run lexer. | 45 | // TODO: run lexer. |
45 | } | 46 | } |
@@ -89,6 +90,8 @@ main(int argc, char *argv[]) { | |||
89 | } | 90 | } |
90 | } | 91 | } |
91 | 92 | ||
93 | init(); | ||
94 | |||
92 | // Run from stdin. | 95 | // Run from stdin. |
93 | if (optind == argc) { | 96 | if (optind == argc) { |
94 | // TODO: REPL | 97 | // TODO: REPL |