mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-23 22:35:11 +00:00
Implemented includes in uxnasm (no asma support yet)
This commit is contained in:
parent
41e18c16b1
commit
28569d118e
1 changed files with 23 additions and 1 deletions
24
src/uxnasm.c
24
src/uxnasm.c
|
@ -157,7 +157,7 @@ makemacro(char *name, FILE *f)
|
||||||
return error("Macro name is invalid", name);
|
return error("Macro name is invalid", name);
|
||||||
m = &p.macros[p.mlen++];
|
m = &p.macros[p.mlen++];
|
||||||
scpy(name, m->name, 64);
|
scpy(name, m->name, 64);
|
||||||
while(fscanf(f, "%63s", word)) {
|
while(fscanf(f, "%63s", word) == 1) {
|
||||||
if(word[0] == '{') continue;
|
if(word[0] == '{') continue;
|
||||||
if(word[0] == '}') break;
|
if(word[0] == '}') break;
|
||||||
if(m->len > 64)
|
if(m->len > 64)
|
||||||
|
@ -284,6 +284,21 @@ parsetoken(char *w)
|
||||||
return error("Invalid token", w);
|
return error("Invalid token", w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
doinclude(FILE *f, int (*pass)(FILE *))
|
||||||
|
{
|
||||||
|
char word[64];
|
||||||
|
FILE *finc;
|
||||||
|
int ret;
|
||||||
|
if(fscanf(f, "%63s", word) != 1)
|
||||||
|
return error("End of input", "include");
|
||||||
|
if(!(finc = fopen(word, "r")))
|
||||||
|
return error("Include failed to open", word);
|
||||||
|
ret = pass(finc);
|
||||||
|
fclose(finc);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pass1(FILE *f)
|
pass1(FILE *f)
|
||||||
{
|
{
|
||||||
|
@ -308,6 +323,9 @@ pass1(FILE *f)
|
||||||
} else if(w[0] == '&') {
|
} else if(w[0] == '&') {
|
||||||
if(!makelabel(sublabel(subw, scope, w + 1), addr))
|
if(!makelabel(sublabel(subw, scope, w + 1), addr))
|
||||||
return error("Pass 1 - Invalid sublabel", w);
|
return error("Pass 1 - Invalid sublabel", w);
|
||||||
|
} else if(scmp(w, "include", 8)) {
|
||||||
|
if(!doinclude(f, pass1))
|
||||||
|
return 0;
|
||||||
} else if(sihx(w))
|
} else if(sihx(w))
|
||||||
addr += slen(w) / 2;
|
addr += slen(w) / 2;
|
||||||
else
|
else
|
||||||
|
@ -340,6 +358,10 @@ pass2(FILE *f)
|
||||||
} else if(w[0] == '@') {
|
} else if(w[0] == '@') {
|
||||||
scpy(w + 1, scope, 64);
|
scpy(w + 1, scope, 64);
|
||||||
continue;
|
continue;
|
||||||
|
} else if(scmp(w, "include", 8)) {
|
||||||
|
if(!doinclude(f, pass2))
|
||||||
|
return 0;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if(w[1] == '&')
|
if(w[1] == '&')
|
||||||
scpy(sublabel(subw, scope, w + 2), w + 1, 64);
|
scpy(sublabel(subw, scope, w + 2), w + 1, 64);
|
||||||
|
|
Loading…
Reference in a new issue