uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit fbbddf50d61a4c9bc3857e9806e60810cdc4336c
parent 4b6efa6fc6c6101dbebbd5d9831905dbfd7898cc
Author: neauoire <aliceffekt@gmail.com>
Date:   Sat, 27 Nov 2021 14:07:25 -0800

(uxnasm) Cleanup

Diffstat:
Msrc/uxnasm.c | 66+++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 31 insertions(+), 35 deletions(-)

diff --git a/src/uxnasm.c b/src/uxnasm.c @@ -14,10 +14,6 @@ WITH REGARD TO THIS SOFTWARE. #define TRIM 0x0100 #define LENGTH 0x10000 -#define REFERENCES 2048 -#define LABELS 512 -#define MACROS 256 - typedef unsigned char Uint8; typedef signed char Sint8; typedef unsigned short Uint16; @@ -40,9 +36,9 @@ typedef struct { typedef struct { Uint8 data[LENGTH]; Uint16 ptr, length, llen, mlen, rlen; - Label labels[LABELS]; - Macro macros[MACROS]; - Reference refs[REFERENCES]; + Label labels[512]; + Macro macros[256]; + Reference refs[2048]; char scope[64]; } Program; @@ -132,7 +128,7 @@ makemacro(char *name, FILE *f) return error("Macro name is hex number", name); if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name)) return error("Macro name is invalid", name); - if(p.mlen == MACROS) + if(p.mlen == 256) return error("Too many macros", name); m = &p.macros[p.mlen++]; scpy(name, m->name, 64); @@ -156,7 +152,7 @@ makelabel(char *name) return error("Label name is hex number", name); if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name)) return error("Label name is invalid", name); - if(p.llen == LABELS) + if(p.llen == 512) return error("Too many labels", name); l = &p.labels[p.llen++]; l->addr = p.ptr; @@ -165,20 +161,6 @@ makelabel(char *name) return 1; } -static int -doinclude(const char *filename) -{ - FILE *f; - char w[64]; - if(!(f = fopen(filename, "r"))) - return error("Include failed to open", filename); - while(fscanf(f, "%63s", w) == 1) - if(!tokenize(w, f)) - return error("Unknown token", w); - fclose(f); - return 1; -} - static void writebyte(Uint8 b, int lit) { @@ -232,6 +214,20 @@ prefill(char *scope, char *label, Uint16 addr) } static int +doinclude(const char *filename) +{ + FILE *f; + char w[64]; + if(!(f = fopen(filename, "r"))) + return error("Include failed to open", filename); + while(fscanf(f, "%63s", w) == 1) + if(!tokenize(w, f)) + return error("Unknown token", w); + fclose(f); + return 1; +} + +static int tokenize(char *w, FILE *f) { int i = 0; @@ -368,18 +364,6 @@ resolve(void) return 1; } -static void -review(char *filename) -{ - int i; - for(i = 0; i < p.llen; ++i) - if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z') - continue; /* Ignore capitalized labels(devices) */ - else if(!p.labels[i].refs) - fprintf(stderr, "--- Unused label: %s\n", p.labels[i].name); - fprintf(stderr, "Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n", filename, p.length - TRIM, p.length / 652.80, p.llen, p.mlen); -} - static int assemble(FILE *f) { @@ -392,6 +376,18 @@ assemble(FILE *f) return 1; } +static void +review(char *filename) +{ + int i; + for(i = 0; i < p.llen; ++i) + if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z') + continue; /* Ignore capitalized labels(devices) */ + else if(!p.labels[i].refs) + fprintf(stderr, "--- Unused label: %s\n", p.labels[i].name); + fprintf(stderr, "Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n", filename, p.length - TRIM, p.length / 652.80, p.llen, p.mlen); +} + int main(int argc, char *argv[]) {