(uxnasm) Better parent label reference counting

This commit is contained in:
Devine Lu Linvega 2022-06-06 09:42:26 -07:00
parent bf81d07113
commit 0fafd652f1
1 changed files with 10 additions and 3 deletions

View File

@ -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 */