uxn

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

commit 0fafd652f1f43bf6c5664a4b744ce658404b0f50
parent bf81d071139e978a4642ada6134b81a4ab188c34
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Mon,  6 Jun 2022 09:42:26 -0700

(uxnasm) Better parent label reference counting

Diffstat:
Msrc/uxnasm.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/uxnasm.c b/src/uxnasm.c @@ -60,6 +60,7 @@ static int scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i]) if static int sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return i > 1; } /* string is hexadecimal */ static int shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */ static int slen(char *s) { int i = 0; while(s[i]) i++; return i; } /* string length */ +static int spos(char *s, char c) { Uint8 i = 0, j; while((j = s[i++])) if(j == c) return i; return -1; } /* character position */ static char *scpy(char *src, char *dst, int len) { int i = 0; while((dst[i] = src[i]) && i < len - 2) i++; dst[i + 1] = '\0'; return dst; } /* string copy */ static char *scat(char *dst, const char *src) { char *ptr = dst + slen(dst); while(*src) *ptr++ = *src++; *ptr = '\0'; return dst; } /* string cat */ @@ -174,15 +175,22 @@ makelabel(char *name) static int makereference(char *scope, char *label, Uint16 addr) { - char subw[0x40]; + char subw[0x40], parent[0x40]; Reference *r; if(p.rlen == 0x800) return error("References limit exceeded", label); r = &p.refs[p.rlen++]; if(label[1] == '&') scpy(sublabel(subw, scope, label + 2), r->name, 0x40); - else + else { + int p = spos(label + 1, '/'); + if(p > 0) { + Label *l; + if((l = findlabel(scpy(label + 1, parent, p)))) + l->refs++; + } scpy(label + 1, r->name, 0x40); + } r->rune = label[0]; r->addr = addr; return 1; @@ -308,7 +316,6 @@ parse(char *w, FILE *f) case '&': /* sublabel */ if(!makelabel(sublabel(subw, p.scope, w + 1))) return error("Invalid sublabel", w); - findlabel(p.scope)->refs++; litlast = 0; break; case '#': /* literals hex */