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
|
||||
its memory
|
||||
* Implement UTF-8 I/O
|
||||
* Allow cycle maximum to be passed to `run()`
|
||||
* Keep a cache of compiled programs in `run()`
|
||||
|
||||
### gir.html
|
||||
|
|
16
gir.js
16
gir.js
|
@ -598,11 +598,19 @@ function compile(program) {
|
|||
return optimize(parse(program));
|
||||
}
|
||||
|
||||
// (string, string) → string
|
||||
function run(program, input) {
|
||||
// TODO: Allow setting cycle maximum
|
||||
// (string, string, bool) → string
|
||||
function run(program, input, maxCycles = null) {
|
||||
// TODO; Cache programs
|
||||
let compiled = compile(program);
|
||||
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