From 902804cf2fd78e18b4e2ae4e7d13ad6e3800c25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sat, 26 May 2018 22:33:55 +0300 Subject: [PATCH] Make the memory dump in ircbotRun() better at determining tape head location --- gir.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/gir.js b/gir.js index bd2b3d8..80893c5 100644 --- a/gir.js +++ b/gir.js @@ -403,6 +403,17 @@ function addOffsetProperties(parsed) { offsetted.push({type: readInt, offset: offset}); } else if(command.type == breakPoint) { + // A breakpoint should have the tape head + // where it would be without the offsets + // If offset is not 0, add a moveHead + if(offset != 0) { + offsetted.push({type: moveHead, + value: offset}); + // Mark we've moved the head + headChange += offset; + } + offset = 0; + // Add the breakpoint offsetted.push({type: breakPoint}); } else { @@ -926,6 +937,10 @@ function ircbotRun(program, input, maxCycles = 400000) { let result = runVM(vm, maxCycles); let output = decodeUTF8(result.state.output); + // Did we run into maxCycles? + let executedTooLong = maxCycles != null && + result.cycles >= maxCycles; + // If there was either no output or a breakpoint triggered, dump // tape to output instead if(output.length == 0 || result.breakPointReached) { @@ -935,10 +950,12 @@ function ircbotRun(program, input, maxCycles = 400000) { } // Get the tape head we should have here - // Since commands in the virtual machine can act at offsets, - // what we want is the last offset accessed, unless that is - // null - let tapeHead = result.lastIndex || result.state.tapeHead; + // Both the program completing succesfully and a breakpoint + // will leave the tape head "where it should be". The cycle + // limit can however stop a program at any point. Therefore + // in such cases more useful is the last index that was + // accessed + let tapeHead = executedTooLong ? result.lastIndex : result.state.tapeHead; // Find min and max of the existant array indinces, since // there is no good way to easily get them and we need them @@ -993,8 +1010,8 @@ function ircbotRun(program, input, maxCycles = 400000) { output += `{${min}…${max}}(${start > min ? '… ' : ''}${cells.join(' ')}${end < max ? ' …' : ''})` } - // Did we run into maxCycles? - if(maxCycles != null && result.cycles >= maxCycles) { + // Add «TLE» to signify execution taking too long + if(executedTooLong) { output += '«TLE»'; }