From 8553fecc05c95d71c330ca706b515ffbfa75e277 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 27 Nov 2023 18:17:59 +0100 Subject: [PATCH] WIP: symbol resolver --- include/ulas.h | 9 ++++++--- src/ulas.c | 13 +++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/ulas.h b/include/ulas.h index 2a7d5a2..5703201 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -368,7 +368,9 @@ 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); +// and sets rc to -1 if eunresolve is 1 +// if eunresolve is 0 rc will be set to 1 if the symbol is not resolved +struct ulas_tok *ulas_symbolresolve(const char *name, int eunresolve, int *rc); // tokenisze according to pre-defined rules // returns the amount of bytes of line that were @@ -445,9 +447,10 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, */ // convert literal to its int value -int ulas_valint(struct ulas_tok *lit, int *rc); +// retunrs -1 on error, 0 on success and 1 if there is an unresolved symbol +int ulas_valint(struct ulas_tok *lit, int eunresolve, int *rc); // convert literal to its char value -char *ulas_valstr(struct ulas_tok *lit, int *rc); +char *ulas_valstr(struct ulas_tok *lit, int eunresolve, int *rc); struct ulas_tokbuf ulas_tokbuf(void); diff --git a/src/ulas.c b/src/ulas.c index a07be33..7cc5d0f 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -161,7 +161,7 @@ int ulas_isname(const char *tok, unsigned long n) { return 1; } -struct ulas_tok *ulas_symbolresolve(const char *name) { +struct ulas_tok *ulas_symbolresolve(const char *name, int eunresolve, int *rc) { // TODO: implement return NULL; } @@ -931,7 +931,12 @@ fail: * Literals, tokens and expressions */ -int ulas_valint(struct ulas_tok *lit, int *rc) { +int ulas_valint(struct ulas_tok *lit, int eunresolve, int *rc) { + if (lit->type == ULAS_SYMBOL) { + struct ulas_tok *stok = ulas_symbolresolve(lit->val.strv, eunresolve, rc); + return ulas_valint(stok, eunresolve, rc); + } + if (!lit || lit->type != ULAS_INT) { ULASERR("Expected int\n"); *rc = -1; @@ -941,7 +946,7 @@ int ulas_valint(struct ulas_tok *lit, int *rc) { return lit->val.intv; } -char *ulas_valstr(struct ulas_tok *lit, int *rc) { +char *ulas_valstr(struct ulas_tok *lit, int eunresolve, int *rc) { if (!lit || lit->type != ULAS_STR) { ULASERR("Expected str\n"); *rc = -1; @@ -1329,7 +1334,7 @@ int ulas_intexpreval(int i, int *rc) { } case ULAS_EXPPRIM: { struct ulas_tok *t = ulas_tokbufget(&ulas.toks, e->val.prim.tok); - return ulas_valint(t, rc); + return ulas_valint(t, 0, rc); } } -- 2.30.2