Yes, 'run' is generally just used to test and prove that the interpreter is working, it's not safe.
Repeated calls to 'step' can be done in several ways. One approach is to call 'step' indefinitely, and let the user kill it whenever they wish though some sort of a reset button (this is what Blockly Games does):
var stepPid;
function nextStep() {
if (myInterpreter.step()) {
stepPid = setTimeout(nextStep, 10);
}
}
nextStep();
function stop() {
clearTimeout(stepPid);
}
This won't lock up the browser since there's a 10ms pause between each step. So it's safe to execute without limit.
Another approach is to put a step limit on the program:
var steps = 10000;
function nextStep() {
if (myInterpreter.step() && steps-- !== 0) {
setTimeout(nextStep, 10);
}
}
nextStep();
It will execute until either the program ends or 'steps' counts down from 10,000 to 0.
Another approach is to put a time limit on the program:
var endTime = Date.now() + 1000 * 15;
function nextStep() {
if (myInterpreter.step() && Date.now() < endTime) {
setTimeout(nextStep, 10);
}
}
nextStep();
It will execute until either the program ends or 15 seconds have elapsed.
These are a few ideas to get you started. Hope this helps!