Make the memory dump in ircbotRun() better at determining tape head location

This commit is contained in:
Juhani Krekelä 2018-05-26 22:33:55 +03:00
parent 64e58902cc
commit 902804cf2f
1 changed files with 23 additions and 6 deletions

29
gir.js
View File

@ -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»';
}