Quicker location of Branch Labels for GOTO etc.
Posted: Tue Nov 03, 2015 7:21 am
When running the blinker program I noticed it was a lot more on than off. Looks like the program is slow when doing branching. Looking at the source it looks like a full scan of the entire program is done to resolve the line that has the branch label. I put a couple of extra goto's in the loop like this
.....
goto [here1]
[here1]
goto [here2]
[here2]
IF X <= noofblinks goto {...}
and you can really notice the delay while searching for the label.
As a quick improvement a BREAK when the correct line is found would help speed it up.
Not sure how other basics do it but the population of an array with all the labels and there line number at start up, and then resolving the line number by looking up the array would be a lot faster.
Regards
Gerry
.....
goto [here1]
[here1]
goto [here2]
[here2]
IF X <= noofblinks goto {...}
and you can really notice the delay while searching for the label.
As a quick improvement a BREAK when the correct line is found would help speed it up.
Not sure how other basics do it but the population of an array with all the labels and there line number at start up, and then resolving the line number by looking up the array would be a lot faster.
Code: Select all
//branching commands
if (Param0 == "goto")
{
for (int i = 0; i <= TotalNumberOfLines; i++) {
String gotoTest = BasicProgram(i);
gotoTest.trim();
if (gotoTest == Param1 | String(gotoTest + ":") == Param1)
{
RunningProgramCurrentLine = i - 1;
BREAK;
}
}
return;
}
Regards
Gerry