run() can now take a maxCycles argument

This commit is contained in:
Juhani Krekelä 2018-05-24 23:36:24 +03:00
parent d2a97cebb2
commit 4853e42992
2 changed files with 12 additions and 5 deletions

View File

@ -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
View File

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