Change the values runVM returns that relate to cycle limit
This commit is contained in:
parent
31d5bbbdeb
commit
d2e4da1939
17
gir.js
17
gir.js
|
@ -457,9 +457,9 @@ function newVM(program, input) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// (girVMState, int) → {state: girVMState, reachedLimit: bool}
|
// (girVMState, int) → {state: girVMState, complete: bool, cycles: int}
|
||||||
// reachedLimit is set to true if the program ran for maxCycles and did not
|
// complete is set to true is the program completed its execution
|
||||||
// terminate
|
// cycles is the number of cycles the VM ran
|
||||||
// If maxCycles is null, the program runs until completion
|
// If maxCycles is null, the program runs until completion
|
||||||
function runVM(state, maxCycles = null) {
|
function runVM(state, maxCycles = null) {
|
||||||
let program = state.program;
|
let program = state.program;
|
||||||
|
@ -477,12 +477,13 @@ function runVM(state, maxCycles = null) {
|
||||||
let input = state.input;
|
let input = state.input;
|
||||||
let output = state.output;
|
let output = state.output;
|
||||||
|
|
||||||
let reachedLimit = true;
|
let complete = false;
|
||||||
for(let cycle = 0; maxCycles === null || cycle < maxCycles; cycle++) {
|
let cycle = 0;
|
||||||
|
for(; maxCycles === null || cycle < maxCycles; cycle++) {
|
||||||
// Exit the loop if we run to the end of the program
|
// Exit the loop if we run to the end of the program
|
||||||
if(ip >= program.length) {
|
if(ip >= program.length) {
|
||||||
// Did not reach limit, program finished
|
// Program completed
|
||||||
reachedLimit = false;
|
complete = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,7 +586,7 @@ function runVM(state, maxCycles = null) {
|
||||||
output
|
output
|
||||||
};
|
};
|
||||||
|
|
||||||
return {state: newState, reachedLimit: reachedLimit};
|
return {state: newState, complete: complete, cycles: cycle};
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue