run() can now take a maxCycles argument
This commit is contained in:
parent
d2a97cebb2
commit
4853e42992
|
@ -25,7 +25,6 @@ TODO
|
||||||
* Make VM use a Proxied object that gives out 0 for nonexistent elements for
|
* Make VM use a Proxied object that gives out 0 for nonexistent elements for
|
||||||
its memory
|
its memory
|
||||||
* Implement UTF-8 I/O
|
* Implement UTF-8 I/O
|
||||||
* Allow cycle maximum to be passed to `run()`
|
|
||||||
* Keep a cache of compiled programs in `run()`
|
* Keep a cache of compiled programs in `run()`
|
||||||
|
|
||||||
### gir.html
|
### gir.html
|
||||||
|
|
16
gir.js
16
gir.js
|
@ -598,11 +598,19 @@ function compile(program) {
|
||||||
return optimize(parse(program));
|
return optimize(parse(program));
|
||||||
}
|
}
|
||||||
|
|
||||||
// (string, string) → string
|
// (string, string, bool) → string
|
||||||
function run(program, input) {
|
function run(program, input, maxCycles = null) {
|
||||||
// TODO: Allow setting cycle maximum
|
|
||||||
// TODO; Cache programs
|
// TODO; Cache programs
|
||||||
let compiled = compile(program);
|
let compiled = compile(program);
|
||||||
let vm = newVM(compiled, input);
|
let vm = newVM(compiled, input);
|
||||||
return runVM(vm).state.output;
|
|
||||||
|
let result = runVM(vm, maxCycles);
|
||||||
|
let output = result.state.output;
|
||||||
|
|
||||||
|
// If didn't complete, mark it in the output
|
||||||
|
if(!result.complete) {
|
||||||
|
output += '«TLE»';
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue