git » jacl.git » commit 1a2983e

repl stuff

author Alan Dipert
2019-12-22 22:07:32 UTC
committer Alan Dipert
2019-12-22 22:07:32 UTC
parent 3cbb4bf007562c4755df240eceae37c51f1ac662

repl stuff

jacl.js +5 -6
repl-client/jacl-client.R +7 -8

diff --git a/jacl.js b/jacl.js
index 84379bc..076b171 100644
--- a/jacl.js
+++ b/jacl.js
@@ -1828,11 +1828,10 @@ const emitter = (() => {
   };
 });
 
-let replInputStream, replReader;
+let replInputStream = new BufferedStream(),
+    replReader = new Reader(replInputStream);
 
 const startRepl = async () => {
-  replInputStream = new BufferedStream(),
-  replReader = new Reader(replInputStream);
   try {
     for await(const obj of replReader) {
       const node = analyze(emptyEnv, null, obj);
@@ -1844,12 +1843,12 @@ const startRepl = async () => {
     }
   } catch (e) {
     console.error(e);
-    startRepl();
+    replInputStream = new BufferedStream(),
+    replReader = new Reader(replInputStream);
+    setTimeout(startRepl, 0);
   }
 };
 
-const replWrite = str => replInputStream.writeEach(str);
-
 startRepl();
 
 //var buf = new BufferedStream(),
diff --git a/repl-client/jacl-client.R b/repl-client/jacl-client.R
index 72f2a69..8554237 100755
--- a/repl-client/jacl-client.R
+++ b/repl-client/jacl-client.R
@@ -4,15 +4,14 @@ library(chromote)
 library(jsonlite)
 
 muffle <- function(expr) {
-  if (.Platform$OS.type == "unix") {
-    sink("/dev/null")
-  } else {
-    sink("NUL")
-  }
-  force(expr)
-  sink()
+  sink("/dev/null")
+  tryCatch({
+    force(expr)
+    invisible()
+  }, finally = sink())
 }
 
+# TODO figure out how to use Log instead of deprecated Console
 muffle({
   b <- ChromoteSession$new()
   b$Page$navigate("file:///home/alan/github/alandipert/jacl/index.html")
@@ -29,7 +28,7 @@ open(f, blocking = TRUE)
 while(isOpen(f)) {
   ch <- readChar(f, 1)
   json_str <- toJSON(ch, auto_unbox = TRUE)
-  code <- paste0('replWrite(', json_str, ')')
+  code <- paste0('replInputStream.write(', json_str, ')')
   b$Runtime$evaluate(code)
 }