Fix ON GOTO and ON GOSUB - Should resolve #11

This commit is contained in:
Sigurdur Sveinn Halldorsson 2016-07-20 19:49:51 +02:00
parent 26bb151874
commit 29e8b8ec70
1 changed files with 15 additions and 11 deletions

View File

@ -523,13 +523,15 @@ this.basic = (function() {
},
'on_goto': function ON_GOTO(index /* , ...lines */) {
if (index < 0 || index > 255) {
runtime_error(ERRORS.ILLEGAL_QUANTITY);
}
index = (index - 1) >> 0;
var lines = Array.prototype.slice.call(arguments, 1);
if (index < 0 || index >= lines.length) {
runtime_error(ERRORS.ILLEGAL_QUANTITY);
if (index >= 0 && index < lines.length) {
throw new GoToLine(lines[index]);
}
throw new GoToLine(lines[index]);
},
'gosub': function GOSUB(line) {
@ -541,16 +543,18 @@ this.basic = (function() {
},
'on_gosub': function ON_GOSUB(index /* , ...lines */) {
index = (index - 1) >> 0;
var lines = Array.prototype.slice.call(arguments, 1);
if (index < 0 || index >= lines.length) {
if (index < 0 || index > 255) {
runtime_error(ERRORS.ILLEGAL_QUANTITY);
}
state.stack.push({
gosub_return: state.stmt_index,
line_number: state.line_number
});
throw new GoToLine(lines[index]);
index = (index - 1) >> 0;
var lines = Array.prototype.slice.call(arguments, 1);
if (index >= 0 && index < lines.length) {
state.stack.push({
gosub_return: state.stmt_index,
line_number: state.line_number
});
throw new GoToLine(lines[index]);
}
},
'return': function RETURN() {