From 4853e429923e20893d592159716c294e1f43877e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Thu, 24 May 2018 23:36:24 +0300 Subject: [PATCH] run() can now take a maxCycles argument --- README.md | 1 - gir.js | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ad3986d..09d3be7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/gir.js b/gir.js index 4ccf113..2296f16 100644 --- a/gir.js +++ b/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; }