mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-16 11:15:06 +00:00
(uxnasm)Optimize tail-call for subroutines too
This commit is contained in:
parent
3c06af41c3
commit
18b73f4861
1 changed files with 9 additions and 3 deletions
12
src/uxnasm.c
12
src/uxnasm.c
|
@ -208,12 +208,18 @@ static int
|
||||||
writeopcode(char *w)
|
writeopcode(char *w)
|
||||||
{
|
{
|
||||||
Uint8 res;
|
Uint8 res;
|
||||||
if(jsrlast && scmp(w, "JMP2r", 5)) { /* combine JSR2 JMP2r */
|
/* tail-call optimization */
|
||||||
p.data[p.ptr - 1] = findopcode("JMP2");
|
if(scmp(w, "JMP2r", 5)) {
|
||||||
return jsrlast--;
|
if(jsrlast) {
|
||||||
|
p.data[p.ptr - 1] = jsrlast == 2 ? findopcode("JMP2") : findopcode("JMP");
|
||||||
|
jsrlast = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
res = writebyte(findopcode(w));
|
res = writebyte(findopcode(w));
|
||||||
if(scmp(w, "JSR2", 4))
|
if(scmp(w, "JSR2", 4))
|
||||||
|
jsrlast = 2;
|
||||||
|
else if(scmp(w, "JSR", 3))
|
||||||
jsrlast = 1;
|
jsrlast = 1;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue