minimal error handling just so failure isn't quiet.
This commit is contained in:
parent
3da2292247
commit
76115cc019
|
@ -78,6 +78,18 @@ $(document).ready(function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// writeErrorMessage: string -> void
|
||||||
|
// Write out an error message.
|
||||||
|
var writeErrorMessage = function(msg) {
|
||||||
|
$("<span/>")
|
||||||
|
.text(''+msg)
|
||||||
|
.css("color", "red")
|
||||||
|
.appendTo(output);
|
||||||
|
$("<br/>").appendTo(output);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Print: Racket value -> void
|
// Print: Racket value -> void
|
||||||
// Prints the racket value out.
|
// Prints the racket value out.
|
||||||
var print = function(elt) {
|
var print = function(elt) {
|
||||||
|
@ -103,6 +115,24 @@ $(document).ready(function() {
|
||||||
$("<tt/>").text('> ' + src).appendTo(output);
|
$("<tt/>").text('> ' + src).appendTo(output);
|
||||||
$("<br/>").appendTo(output);
|
$("<br/>").appendTo(output);
|
||||||
var onCompile = function(compiledResult) {
|
var onCompile = function(compiledResult) {
|
||||||
|
if (compiledResult.type === 'repl') {
|
||||||
|
return onGoodReplCompile(compiledResult);
|
||||||
|
} else if (compiledResult.type === 'module') {
|
||||||
|
alert('internal error: module unexpected');
|
||||||
|
after();
|
||||||
|
} else if (compiledResult.type === 'error') {
|
||||||
|
return onCompileTimeError(compiledResult);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var onCompileTimeError = function(compiledResult) {
|
||||||
|
writeErrorMessage(compiledResult.message);
|
||||||
|
after();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var onGoodReplCompile = function(compiledResult) {
|
||||||
// compiledResult.compiledCodes is an array of function chunks.
|
// compiledResult.compiledCodes is an array of function chunks.
|
||||||
// The evaluation leaves the value register of the machine
|
// The evaluation leaves the value register of the machine
|
||||||
// to contain the list of values from toplevel evaluation.
|
// to contain the list of values from toplevel evaluation.
|
||||||
|
@ -124,11 +154,7 @@ $(document).ready(function() {
|
||||||
console.log(err.stack);
|
console.log(err.stack);
|
||||||
}
|
}
|
||||||
if (err.message) {
|
if (err.message) {
|
||||||
$("<span/>")
|
writeErrorMessage(err.message);
|
||||||
.text(err.message)
|
|
||||||
.css("color", "red")
|
|
||||||
.appendTo(output);
|
|
||||||
$("<br/>").appendTo(output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
after();
|
after();
|
||||||
|
@ -137,8 +163,11 @@ $(document).ready(function() {
|
||||||
},
|
},
|
||||||
after);
|
after);
|
||||||
};
|
};
|
||||||
|
var onCompileError = function(err) {
|
||||||
|
};
|
||||||
|
|
||||||
var onServerError = function(err) {
|
var onServerError = function(err) {
|
||||||
console.log("error", err);
|
writeErrorMessage("internal server error");
|
||||||
after();
|
after();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -62,38 +62,43 @@
|
||||||
#t]
|
#t]
|
||||||
[else #f]))
|
[else #f]))
|
||||||
;; Compile the program here...
|
;; Compile the program here...
|
||||||
|
(with-handlers ([exn:fail? (lambda (exn)
|
||||||
(cond [(not as-mod?)
|
(write-json (hash 'type "error"
|
||||||
(define ip (open-input-string text-src))
|
'message (exn-message exn))
|
||||||
(port-count-lines! ip)
|
op))])
|
||||||
(define assembled-codes
|
(cond [(not as-mod?)
|
||||||
(let loop ()
|
(define ip (open-input-string text-src))
|
||||||
(define sexp (read-syntax #f ip))
|
(port-count-lines! ip)
|
||||||
(cond [(eof-object? sexp)
|
(define assembled-codes
|
||||||
'()]
|
(let loop ()
|
||||||
[else
|
(define sexp (read-syntax #f ip))
|
||||||
(define raw-bytecode (repl-compile sexp #:lang language))
|
(cond [(eof-object? sexp)
|
||||||
(define op (open-output-bytes))
|
'()]
|
||||||
(write raw-bytecode op)
|
[else
|
||||||
(define whalesong-bytecode (parse-bytecode (open-input-bytes (get-output-bytes op))))
|
(define raw-bytecode (repl-compile sexp #:lang language))
|
||||||
(pretty-print whalesong-bytecode)
|
(define op (open-output-bytes))
|
||||||
(define compiled-bytecode (compile-for-repl whalesong-bytecode))
|
(write raw-bytecode op)
|
||||||
(pretty-print compiled-bytecode)
|
(define whalesong-bytecode (parse-bytecode (open-input-bytes (get-output-bytes op))))
|
||||||
(define assembled-op (open-output-string))
|
(pretty-print whalesong-bytecode)
|
||||||
(define assembled (assemble/write-invoke compiled-bytecode assembled-op 'with-preemption))
|
(define compiled-bytecode (compile-for-repl whalesong-bytecode))
|
||||||
(cons (get-output-string assembled-op) (loop))])))
|
(pretty-print compiled-bytecode)
|
||||||
(printf "assembled codes ~a\n" assembled-codes)
|
(define assembled-op (open-output-string))
|
||||||
(write-json (hash 'compiledCodes assembled-codes)
|
(define assembled (assemble/write-invoke compiled-bytecode assembled-op 'with-preemption))
|
||||||
op)]
|
(cons (get-output-string assembled-op) (loop))])))
|
||||||
[else
|
(printf "assembled codes ~a\n" assembled-codes)
|
||||||
(define program-port (open-output-string))
|
(write-json (hash 'type "repl"
|
||||||
(package (SexpSource (parameterize ([read-accept-reader #t])
|
'compiledCodes assembled-codes)
|
||||||
(read (open-input-string (string-append "#lang whalesong\n" text-src)))))
|
op)]
|
||||||
#:should-follow-children? (lambda (src) #f)
|
[else
|
||||||
#:output-port program-port)
|
(define program-port (open-output-string))
|
||||||
(write-json (hash 'compiledModule (get-output-string program-port))
|
(package (SexpSource (parameterize ([read-accept-reader #t])
|
||||||
op)
|
(read (open-input-string (string-append "#lang whalesong\n" text-src)))))
|
||||||
])
|
#:should-follow-children? (lambda (src) #f)
|
||||||
|
#:output-port program-port)
|
||||||
|
(write-json (hash 'type "module"
|
||||||
|
'compiledModule (get-output-string program-port))
|
||||||
|
op)
|
||||||
|
]))
|
||||||
;; Send it back as json text....
|
;; Send it back as json text....
|
||||||
|
|
||||||
(close-output-port op)
|
(close-output-port op)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user