adjusting the output so I can grab the val register from the machine.

This commit is contained in:
Danny Yoo 2011-02-25 16:21:20 -05:00
parent 5ab3ae1a89
commit aa1d34eadc
2 changed files with 44 additions and 35 deletions

View File

@ -17,7 +17,7 @@
(displayln (assemble-basic-block basic-block) op) (displayln (assemble-basic-block basic-block) op)
(newline op)) (newline op))
basic-blocks) 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 "MACHINE.params.currentErrorHandler = function(e) { fail(e); };\n")
(fprintf op #<<EOF (fprintf op #<<EOF
for (param in params) { for (param in params) {

View File

@ -23,6 +23,7 @@
(define-struct evaluated (stdout value t) #:transparent) (define-struct evaluated (stdout value t) #:transparent)
;; make-evaluate: (Any output-port) -> void ;; make-evaluate: (Any output-port) -> void
;; Produce a JavaScript evaluator that cooperates with a browser. ;; Produce a JavaScript evaluator that cooperates with a browser.
;; The JavaScript-compiler is expected to write out a thunk. When invoked, ;; The JavaScript-compiler is expected to write out a thunk. When invoked,
@ -79,11 +80,18 @@
#:port port #:port port
#:servlet-path "/eval")))) #:servlet-path "/eval"))))
(define *alarm-timeout* 30000)
(define (handle-comet req) (define (handle-comet req)
;; FIXME: how do we handle timeouts?
(let/ec return (let/ec return
(let ([program (sync ch)] (let* ([alarm (alarm-evt (+ (current-inexact-milliseconds) *alarm-timeout*))]
[program (sync ch alarm)]
[op (open-output-bytes)]) [op (open-output-bytes)])
(cond
[(eq? program alarm)
(try-again-response)]
[else
(with-handlers ([exn:fail? (lambda (exn) (with-handlers ([exn:fail? (lambda (exn)
(let ([sentinel (let ([sentinel
(format (format
@ -108,9 +116,16 @@ EOF
(current-seconds) (current-seconds)
#"text/plain; charset=utf-8" #"text/plain; charset=utf-8"
empty empty
(list #"" (get-output-bytes op)))))) (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) (define (ok-response)
(response/full 200 #"Okay" (response/full 200 #"Okay"
(current-seconds) (current-seconds)
@ -147,7 +162,7 @@ EOF
// XMLHttpRequest wrapper. Transparently restarts the request // XMLHttpRequest wrapper. Transparently restarts the request
// if a timeout occurs. // if a timeout occurs.
function sendRequest(url,callback,postData) { function sendRequest(url,callback,postData) {
var req = createXMLHTTPObject(), method, TIMEOUT = 5000, stillInProgress = true, timeoutId; var req = createXMLHTTPObject(), method;
if (!req) return; if (!req) return;
method = (postData) ? "POST" : "GET"; method = (postData) ? "POST" : "GET";
@ -160,21 +175,15 @@ function sendRequest(url,callback,postData) {
if (req.status !== 200 && req.status !== 304) { if (req.status !== 200 && req.status !== 304) {
return; return;
} }
stillInProgress = false; if (req.status === 200 && req.statusText === 'Try again') {
if (timeoutId) { clearTimeout(timeoutId); timeoutId = undefined; } req.abort();
setTimeout(function() { sendRequest(url, callback, postData); }, 0);
return;
}
callback(req); callback(req);
} }
if (req.readyState == 4) return; if (req.readyState == 4) return;
req.send(postData); req.send(postData);
/*
timeoutId = setTimeout(function() { if(stillInProgress) {
req.abort();
// Reschedule
setTimeout(function() { sendRequest(url, callback, postData);}, 0);
}
},
TIMEOUT);
*/
} }
var XMLHttpFactories = [ var XMLHttpFactories = [