Increased limit of refs

This commit is contained in:
Devine Lu Linvega 2023-01-21 18:25:15 -08:00
parent 7616af7cae
commit df7cdd1ce6
1 changed files with 13 additions and 6 deletions

View File

@ -39,7 +39,7 @@ typedef struct {
Uint16 llen, mlen, rlen; Uint16 llen, mlen, rlen;
Label labels[0x400]; Label labels[0x400];
Macro macros[0x100]; Macro macros[0x100];
Reference refs[0x800]; Reference refs[0x1000];
char scope[0x40]; char scope[0x40];
} Program; } Program;
@ -76,6 +76,10 @@ error(const char *name, const char *msg)
static char * static char *
sublabel(char *src, char *scope, char *name) sublabel(char *src, char *scope, char *name)
{ {
if(slen(scope) + slen(name) >= 0x3f) {
error("Sublabel length too long", name);
return NULL;
}
return scat(scat(scpy(scope, src, 0x40), "/"), name); return scat(scat(scpy(scope, src, 0x40), "/"), name);
} }
@ -175,12 +179,14 @@ makereference(char *scope, char *label, Uint16 addr)
{ {
char subw[0x40], parent[0x40]; char subw[0x40], parent[0x40];
Reference *r; Reference *r;
if(p.rlen == 0x800) if(p.rlen == 0x1000)
return error("References limit exceeded", label); return error("References limit exceeded", label);
r = &p.refs[p.rlen++]; r = &p.refs[p.rlen++];
if(label[1] == '&') if(label[1] == '&') {
scpy(sublabel(subw, scope, label + 2), r->name, 0x40); if(!sublabel(subw, scope, label + 2))
else { return error("Invalid sublabel", label);
scpy(subw, r->name, 0x40);
} else {
int pos = spos(label + 1, '/'); int pos = spos(label + 1, '/');
if(pos > 0) { if(pos > 0) {
Label *l; Label *l;
@ -287,7 +293,7 @@ parse(char *w, FILE *f)
scpy(w + 1, p.scope, 0x40); scpy(w + 1, p.scope, 0x40);
break; break;
case '&': /* sublabel */ case '&': /* sublabel */
if(!makelabel(sublabel(subw, p.scope, w + 1))) if(!sublabel(subw, p.scope, w + 1) || !makelabel(subw))
return error("Invalid sublabel", w); return error("Invalid sublabel", w);
break; break;
case '#': /* literals hex */ case '#': /* literals hex */
@ -408,6 +414,7 @@ static int
assemble(FILE *f) assemble(FILE *f)
{ {
char w[0x40]; char w[0x40];
p.ptr = 0x100;
scpy("on-reset", p.scope, 0x40); scpy("on-reset", p.scope, 0x40);
while(fscanf(f, "%62s", w) == 1) while(fscanf(f, "%62s", w) == 1)
if(slen(w) > 0x3d || !parse(w, f)) if(slen(w) > 0x3d || !parse(w, f))