Make the memory dump in ircbotRun() better at determining tape head location
This commit is contained in:
parent
64e58902cc
commit
902804cf2f
29
gir.js
29
gir.js
|
@ -403,6 +403,17 @@ function addOffsetProperties(parsed) {
|
||||||
offsetted.push({type: readInt,
|
offsetted.push({type: readInt,
|
||||||
offset: offset});
|
offset: offset});
|
||||||
} else if(command.type == breakPoint) {
|
} 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
|
// Add the breakpoint
|
||||||
offsetted.push({type: breakPoint});
|
offsetted.push({type: breakPoint});
|
||||||
} else {
|
} else {
|
||||||
|
@ -926,6 +937,10 @@ function ircbotRun(program, input, maxCycles = 400000) {
|
||||||
let result = runVM(vm, maxCycles);
|
let result = runVM(vm, maxCycles);
|
||||||
let output = decodeUTF8(result.state.output);
|
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
|
// If there was either no output or a breakpoint triggered, dump
|
||||||
// tape to output instead
|
// tape to output instead
|
||||||
if(output.length == 0 || result.breakPointReached) {
|
if(output.length == 0 || result.breakPointReached) {
|
||||||
|
@ -935,10 +950,12 @@ function ircbotRun(program, input, maxCycles = 400000) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the tape head we should have here
|
// Get the tape head we should have here
|
||||||
// Since commands in the virtual machine can act at offsets,
|
// Both the program completing succesfully and a breakpoint
|
||||||
// what we want is the last offset accessed, unless that is
|
// will leave the tape head "where it should be". The cycle
|
||||||
// null
|
// limit can however stop a program at any point. Therefore
|
||||||
let tapeHead = result.lastIndex || result.state.tapeHead;
|
// 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
|
// Find min and max of the existant array indinces, since
|
||||||
// there is no good way to easily get them and we need them
|
// 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 ? ' …' : ''})`
|
output += `{${min}…${max}}(${start > min ? '… ' : ''}${cells.join(' ')}${end < max ? ' …' : ''})`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Did we run into maxCycles?
|
// Add «TLE» to signify execution taking too long
|
||||||
if(maxCycles != null && result.cycles >= maxCycles) {
|
if(executedTooLong) {
|
||||||
output += '«TLE»';
|
output += '«TLE»';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue