repl is starting to work.

This commit is contained in:
Danny Yoo 2013-03-01 13:58:01 -07:00
parent 6720f25ec1
commit 24024e773d
2 changed files with 49 additions and 13 deletions

View File

@ -1,23 +1,26 @@
var COMPILED = [];
$(document).ready(function() { $(document).ready(function() {
"use strict"; "use strict";
var repl = $("#repl"); var repl = $("#repl");
var output = $("#output"); var output = $("#output");
plt.runtime.currentMachine.params.currentDisplayer = function(MACHINE, domNode) { var M = plt.runtime.currentMachine;
// We configure output to send it to the "output" DOM node.
M.params.currentDisplayer = function(MACHINE, domNode) {
$(domNode).appendTo(output); $(domNode).appendTo(output);
} }
plt.runtime.currentMachine.params.currentErrorDisplayer = function(MACHINE, domNode) { M.params.currentErrorDisplayer = function(MACHINE, domNode) {
$(domNode).appendTo(output); $(domNode).appendTo(output);
} }
// We then want to initialize the language module.
var initializeLanguage = function(afterLanguageInitialization) { var initializeLanguage = function(afterLanguageInitialization) {
// Load up the language. // Load up the language.
plt.runtime.currentMachine.modules['whalesong/lang/whalesong.rkt'].invoke( M.modules['whalesong/lang/whalesong.rkt'].invoke(
plt.runtime.currentMachine, M,
function() { function() {
console.log("Environment initialized."); console.log("Environment initialized.");
afterLanguageInitialization(); afterLanguageInitialization();
@ -27,8 +30,6 @@ $(document).ready(function() {
alert("uh oh!"); alert("uh oh!");
}); });
}; };
repl.attr('disabled', 'true'); repl.attr('disabled', 'true');
repl.val('Please wait, initializing...'); repl.val('Please wait, initializing...');
initializeLanguage( initializeLanguage(
@ -50,11 +51,46 @@ $(document).ready(function() {
}); });
// CPS'ed for-each.
var forEachK = function(elts, f, after) {
var n = elts.length;
var loop = function(i) {
if (i >= n) {
return after();
} else {
return f(elts[i], function() { loop(i+1); });
}
}
loop(0);
};
// In evaluation, we'll send compilation requests to the server,
// and get back bytecode that we should evaluate.
var evaluate = function(src, after) { var evaluate = function(src, after) {
console.log("about to eval", src); console.log("about to eval", src);
var onCompile = function(compiledResult) { var onCompile = function(compiledResult) {
COMPILED.push(compiledResult); // compiledResult.compiledCodes is an array of function chunks.
after(); var compiledCodes = compiledResult.compiledCodes;
forEachK(compiledCodes,
function(code, k) {
var codeFunction = eval(code);
var onGoodEvaluation = function() {
console.log('good evaluation');
k();
};
var onBadEvaluation = function(M, err) {
console.log('bad evaluation');
console.log(err);
if (err.stack) {
console.log(err.stack);
}
after();
};
codeFunction(M, onGoodEvaluation, onBadEvaluation);
},
after);
//eval(compiledResult.compiled); //eval(compiledResult.compiled);
// FIXME // FIXME
// plt.runtime.currentMachine.modules['whalesong/repl-prototype/anonymous-module.rkt'].invoke( // plt.runtime.currentMachine.modules['whalesong/repl-prototype/anonymous-module.rkt'].invoke(

View File

@ -73,7 +73,7 @@
(define assembled (assemble/write-invoke compiled-bytecode #f assembled-op)) (define assembled (assemble/write-invoke compiled-bytecode #f assembled-op))
(cons (get-output-string assembled-op) (loop))]))) (cons (get-output-string assembled-op) (loop))])))
(printf "assembled codes ~s\n" assembled-codes) (printf "assembled codes ~s\n" assembled-codes)
(write-json (hash 'compiled-codes assembled-codes) (write-json (hash 'compiledCodes assembled-codes)
op)] op)]
[else [else
(define program-port (open-output-string)) (define program-port (open-output-string))
@ -81,7 +81,7 @@
(read (open-input-string (string-append "#lang whalesong\n" text-src))))) (read (open-input-string (string-append "#lang whalesong\n" text-src)))))
#:should-follow-children? (lambda (src) #f) #:should-follow-children? (lambda (src) #f)
#:output-port program-port) #:output-port program-port)
(write-json (hash 'compiled-module (get-output-string program-port)) (write-json (hash 'compiledModule (get-output-string program-port))
op) op)
]) ])
;; Send it back as json text.... ;; Send it back as json text....