Compare commits
2 Commits
64e58902cc
...
46f7854d13
Author | SHA1 | Date |
---|---|---|
Juhani Krekelä | 46f7854d13 | |
Juhani Krekelä | 902804cf2f |
|
@ -24,7 +24,6 @@ TODO
|
|||
* Make VM and transformMultiplyLoops use a Proxied object that gives out 0
|
||||
for nonexistent elements for tape and allows using [] interface
|
||||
* Keep a cache of compiled programs in `ircbotRun()`
|
||||
* Replace non-IRC low bytes with their U+2400 versions in `ircbotRun()`
|
||||
* Support for other types of EOF?
|
||||
|
||||
### gir.html
|
||||
|
|
41
gir.js
41
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,22 @@ function ircbotRun(program, input, maxCycles = 400000) {
|
|||
let result = runVM(vm, maxCycles);
|
||||
let output = decodeUTF8(result.state.output);
|
||||
|
||||
// Replace all characters < 0x20 except for IRC formatting codes
|
||||
// with their graphical representations at U+24xx
|
||||
let formattingChars = [0x02, 0x03, 0x0f, 0x12, 0x15];
|
||||
output = Array.from(output).map(c => {
|
||||
let codePoint = c.codePointAt(0);
|
||||
if(codePoint < 0x20 && !formattingChars.includes(codePoint)) {
|
||||
return String.fromCodePoint(0x2400 + codePoint);
|
||||
} else {
|
||||
return c;
|
||||
}
|
||||
}).join('');
|
||||
|
||||
// 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 +962,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 +1022,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»';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue