From 73e088bfc92e84e9046f333e8b0d08545c62b65d Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 14 Nov 2023 18:33:08 +0100 Subject: [PATCH] WIP: int expressions --- include/ulas.h | 3 +++ src/ulas.c | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/ulas.h b/include/ulas.h index a3d5135..cb5b5c9 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -344,4 +344,7 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, int ulas_asmnext(FILE *dst, FILE *src, char *buf, int n); int ulas_asm(FILE *dst, FILE *src); +// parses and executes a 32 bit signed int math expressions +int ulas_intexpr(const char **line, size_t n, int *rc); + #endif diff --git a/src/ulas.c b/src/ulas.c index cea0eb7..8ef3730 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -27,6 +27,10 @@ void ulas_init(struct ulas_config cfg) { memset(&ulas, 0, sizeof(ulas)); ulas.tok = ulas_str(8); + + if (cfg.argc) { + ulas.filename = cfg.argv[0]; + } } void ulas_free(void) { ulas_strfree(&ulas.tok); } @@ -712,8 +716,10 @@ fail: * Assembly step */ +int ulas_intexpr(const char **line, size_t n, int *rc) { return -1; } + int ulas_asmline(FILE *dst, FILE *src, const char *line, size_t n) { - // const char *start = line; + const char *start = line; int rc = 0; fprintf(dst, "%s", line); @@ -744,6 +750,21 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, size_t n) { goto fail; } + switch (dir) { + case ULAS_ASMDIR_NONE: + case ULAS_ASMDIR_ORG: + ulas.address = ulas_intexpr(&line, strnlen(start, n), &rc); + break; + case ULAS_ASMDIR_SET: + case ULAS_ASMDIR_BYTE: + case ULAS_ASMDIR_STR: + case ULAS_ASMDIR_FILL: + case ULAS_ASMDIR_PAD: + case ULAS_ASMDIR_INCBIN: + ULASPANIC("asmdir not implemented\n"); + break; + } + } else { // is regular line in form of [label:] instruction ; comment } -- 2.30.2