From: Lukas Krickl Date: Sun, 19 Nov 2023 05:32:44 +0000 (+0100) Subject: Added sessions to gitignore X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=c7604748f1483d09bfeb583b10b8cd931b33546f;p=ulas%2F.git Added sessions to gitignore --- diff --git a/.gitignore b/.gitignore index cbd3711..383f6c3 100644 --- a/.gitignore +++ b/.gitignore @@ -61,4 +61,4 @@ compile_commands.json .cache/ .clang_complete .clangd - +.session diff --git a/include/ulas.h b/include/ulas.h index ac48b3f..950711c 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -7,6 +7,7 @@ #define ULAS_PATHMAX 4096 #define ULAS_LINEMAX 4096 +#define ULAS_MACROPARAMMAX 9 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) @@ -91,12 +92,7 @@ struct ulas_str { // any token before 256 is just the literal char value // primitive data types -enum ulas_type { - - ULAS_SYMBOL = 256, - ULAS_INT, - ULAS_STR -}; +enum ulas_type { ULAS_SYMBOL = 256, ULAS_INT, ULAS_STR }; // data type value union ulas_val { @@ -177,8 +173,6 @@ struct ulas_ppdef { int undef; }; -#define ULAS_MACROPARAMMAX 9 - struct ulas_preproc { struct ulas_ppdef *defs; unsigned long defslen; @@ -279,6 +273,10 @@ int ulas_main(struct ulas_config cfg); char *ulas_strndup(const char *src, unsigned long n); +// resolve a symbol until an actual literal token (str, int) is found +// returns NULL if the symbol cannot be resolved +struct ulas_tok *ulas_symbolresolve(const char *name); + // tokenisze according to pre-defined rules // returns the amount of bytes of line that were // consumed or -1 on error diff --git a/src/test.c b/src/test.c index 65589b9..61b83ce 100644 --- a/src/test.c +++ b/src/test.c @@ -147,8 +147,8 @@ void test_preproc(void) { int rc = 0; \ struct ulas_tok tok = ulas_totok((token), strlen(token), &rc); \ assert((expected_rc) == rc); \ - assert(tok.type == ULAS_INT); \ - assert(tok.val.intv == (expected_val)); \ + assert(tok.type == ULAS_INT); \ + assert(tok.val.intv == (expected_val)); \ } #define ASSERT_STR_TOTOK(expected_val, expected_rc, token) \ @@ -156,9 +156,9 @@ void test_preproc(void) { int rc = 0; \ struct ulas_tok tok = ulas_totok((token), strlen(token), &rc); \ assert((expected_rc) == rc); \ - assert(tok.type == ULAS_STR); \ - assert(strcmp((expected_val), tok.val.strv) == 0); \ - free(tok.val.strv); \ + assert(tok.type == ULAS_STR); \ + assert(strcmp((expected_val), tok.val.strv) == 0); \ + free(tok.val.strv); \ } #define ASSERT_SYMBOL_TOTOK(expected_val, expected_rc, token) \ @@ -166,9 +166,9 @@ void test_preproc(void) { int rc = 0; \ struct ulas_tok tok = ulas_totok((token), strlen(token), &rc); \ assert((expected_rc) == rc); \ - assert(tok.type == ULAS_SYMBOL); \ - assert(strcmp((expected_val), tok.val.strv) == 0); \ - free(tok.val.strv); \ + assert(tok.type == ULAS_SYMBOL); \ + assert(strcmp((expected_val), tok.val.strv) == 0); \ + free(tok.val.strv); \ } #define ASSERT_UNEXPECTED_TOTOK(expected_rc, token) \ diff --git a/src/ulas.c b/src/ulas.c index 486fc06..e61dbc0 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -124,6 +124,11 @@ int ulas_isname(const char *tok, unsigned long n) { return 1; } +struct ulas_tok *ulas_symbolresolve(const char *name) { + // TODO: implement + return NULL; +} + #define WELD_TOKISTERM write #define WELD_TOKCOND (i < n && write < n && line[i]) @@ -904,8 +909,7 @@ void ulas_tokbufpush(struct ulas_tokbuf *tb, struct ulas_tok tok) { void ulas_tokbufclear(struct ulas_tokbuf *tb) { for (long i = 0; i < tb->len; i++) { struct ulas_tok *t = &tb->buf[i]; - if (t->type == ULAS_SYMBOL || - t->type == ULAS_STR) { + if (t->type == ULAS_SYMBOL || t->type == ULAS_STR) { free(t->val.strv); } }