From aa1d34eadcbb11bf405a18cde2be344c7c1ac830 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Fri, 25 Feb 2011 16:21:20 -0500 Subject: [PATCH] adjusting the output so I can grab the val register from the machine. --- assemble.rkt | 2 +- browser-evaluate.rkt | 77 +++++++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/assemble.rkt b/assemble.rkt index 0633d40..7e4cd7b 100644 --- a/assemble.rkt +++ b/assemble.rkt @@ -17,7 +17,7 @@ (displayln (assemble-basic-block basic-block) op) (newline op)) basic-blocks) - (fprintf op "MACHINE.cont = success;\n") + (fprintf op "MACHINE.cont = function() {success(MACHINE.val)};\n") (fprintf op "MACHINE.params.currentErrorHandler = function(e) { fail(e); };\n") (fprintf op #< void ;; Produce a JavaScript evaluator that cooperates with a browser. ;; The JavaScript-compiler is expected to write out a thunk. When invoked, @@ -79,37 +80,51 @@ #:port port #:servlet-path "/eval")))) + + (define *alarm-timeout* 30000) + (define (handle-comet req) - ;; FIXME: how do we handle timeouts? (let/ec return - (let ([program (sync ch)] - [op (open-output-bytes)]) - (with-handlers ([exn:fail? (lambda (exn) - (let ([sentinel - (format - #<bytes/utf-8 sentinel))))))]) - (javascript-compiler program op)) - - (response/full 200 #"Okay" - (current-seconds) - #"text/plain; charset=utf-8" - empty - (list #"" (get-output-bytes op)))))) + (exn-message exn))]) + + (return + (response/full 200 #"Okay" + (current-seconds) + #"text/plain; charset=utf-8" + empty + (list #"" (string->bytes/utf-8 sentinel))))))]) + (javascript-compiler program op)) + + (response/full 200 #"Okay" + (current-seconds) + #"text/plain; charset=utf-8" + empty + (list #"" (get-output-bytes op)))])))) + + (define (try-again-response) + (response/full 200 #"Try again" + (current-seconds) + #"text/plain; charset=utf-8" + empty + (list #"" #""))) (define (ok-response) (response/full 200 #"Okay" @@ -147,7 +162,7 @@ EOF // XMLHttpRequest wrapper. Transparently restarts the request // if a timeout occurs. function sendRequest(url,callback,postData) { - var req = createXMLHTTPObject(), method, TIMEOUT = 5000, stillInProgress = true, timeoutId; + var req = createXMLHTTPObject(), method; if (!req) return; method = (postData) ? "POST" : "GET"; @@ -160,21 +175,15 @@ function sendRequest(url,callback,postData) { if (req.status !== 200 && req.status !== 304) { return; } - stillInProgress = false; - if (timeoutId) { clearTimeout(timeoutId); timeoutId = undefined; } + if (req.status === 200 && req.statusText === 'Try again') { + req.abort(); + setTimeout(function() { sendRequest(url, callback, postData); }, 0); + return; + } callback(req); } if (req.readyState == 4) return; req.send(postData); -/* - timeoutId = setTimeout(function() { if(stillInProgress) { - req.abort(); - // Reschedule - setTimeout(function() { sendRequest(url, callback, postData);}, 0); - } - }, - TIMEOUT); -*/ } var XMLHttpFactories = [