From d2e4da1939502563ef5f18b47306d2fb280cf62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Thu, 24 May 2018 23:20:52 +0300 Subject: [PATCH] Change the values runVM returns that relate to cycle limit --- gir.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gir.js b/gir.js index 5ba67e5..4ccf113 100644 --- a/gir.js +++ b/gir.js @@ -457,9 +457,9 @@ function newVM(program, input) { }; } -// (girVMState, int) → {state: girVMState, reachedLimit: bool} -// reachedLimit is set to true if the program ran for maxCycles and did not -// terminate +// (girVMState, int) → {state: girVMState, complete: bool, cycles: int} +// complete is set to true is the program completed its execution +// cycles is the number of cycles the VM ran // If maxCycles is null, the program runs until completion function runVM(state, maxCycles = null) { let program = state.program; @@ -477,12 +477,13 @@ function runVM(state, maxCycles = null) { let input = state.input; let output = state.output; - let reachedLimit = true; - for(let cycle = 0; maxCycles === null || cycle < maxCycles; cycle++) { + let complete = false; + let cycle = 0; + for(; maxCycles === null || cycle < maxCycles; cycle++) { // Exit the loop if we run to the end of the program if(ip >= program.length) { - // Did not reach limit, program finished - reachedLimit = false; + // Program completed + complete = true; break; } @@ -585,7 +586,7 @@ function runVM(state, maxCycles = null) { output }; - return {state: newState, reachedLimit: reachedLimit}; + return {state: newState, complete: complete, cycles: cycle}; } // ------------------------------------------------------------------