From 4a4f1948b5d8e1c6059fac58deb70d77e9f6b588 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 28 Feb 2013 17:53:27 -0700 Subject: [PATCH] still working at it. --- whalesong/repl-prototype/htdocs/repl.js | 47 ++++++++++++++++++------- whalesong/repl-prototype/server.rkt | 28 +++++++++++++-- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/whalesong/repl-prototype/htdocs/repl.js b/whalesong/repl-prototype/htdocs/repl.js index 264c074..1cdb0ab 100644 --- a/whalesong/repl-prototype/htdocs/repl.js +++ b/whalesong/repl-prototype/htdocs/repl.js @@ -13,19 +13,40 @@ $(document).ready(function() { $(domNode).appendTo(output); } - - // Hook up a simple one-line REPL with enter triggering evaluation. - $("#repl").keypress(function(e) { - if (e.which == 13 && !repl.attr('disabled')) { - var src = repl.val(); - $(this).val(""); - repl.attr('disabled', 'true'); - repl.val("... evaluating..."); - evaluate(src, - function() { repl.removeAttr('disabled'); - repl.val("");}); - } - }); + + var initializeLanguage = function(afterLanguageInitialization) { + // Load up the language. + plt.runtime.currentMachine.modules['whalesong/lang/whalesong.rkt'].invoke( + plt.runtime.currentMachine, + function() { + console.log("Environment initialized."); + afterLanguageInitialization(); + }, + function() { + // Nothing should work if we can't get this to work. + alert("uh oh!"); + }); + }; + + + repl.attr('disabled', 'true'); + initializeLanguage( + function() { + repl.removeAttr('disabled'); + // Hook up a simple one-line REPL with enter triggering evaluation. + repl.keypress(function(e) { + if (e.which == 13 && !repl.attr('disabled')) { + var src = repl.val(); + $(this).val(""); + repl.attr('disabled', 'true'); + repl.val("... evaluating..."); + evaluate(src, + function() { repl.removeAttr('disabled'); + repl.val("");}); + } + }); + }); + var evaluate = function(src, after) { console.log("about to eval", src); diff --git a/whalesong/repl-prototype/server.rkt b/whalesong/repl-prototype/server.rkt index becb6c1..eedc0dd 100644 --- a/whalesong/repl-prototype/server.rkt +++ b/whalesong/repl-prototype/server.rkt @@ -11,6 +11,11 @@ web-server/servlet "../make/make-structs.rkt" "../js-assembler/package.rkt" + "../repl-compile.rkt" + "../parser/parse-bytecode.rkt" + "../compiler/compiler.rkt" + "../compiler/compiler-structs.rkt" + "../js-assembler/assemble.rkt" "write-runtime.rkt" (for-syntax racket/base)) @@ -50,8 +55,25 @@ [else #f])) ;; Compile the program here... (define program-port (open-output-string)) - (cond #;[(not as-mod?) - ...] + (cond [(not as-mod?) + (define ip (open-input-string text-src)) + (port-count-lines! ip) + (define assembled-codes + (let loop () + (define sexp (read-syntax #f ip)) + (cond [(eof-object? sexp) + '()] + [else + (define raw-bytecode (repl-compile sexp #:lang 'whalesong/lang/whalesong)) + (define op (open-output-bytes)) + (write raw-bytecode op) + (define whalesong-bytecode (parse-bytecode (open-input-bytes (get-output-bytes op)))) + (define compiled-bytecode (compile whalesong-bytecode 'val next-linkage/drop-multiple)) + (define assembled-op (open-output-bytes)) + (define assembled (assemble/write-invoke compiled-bytecode #f assembled-op)) + (cons (get-output-bytes assembled-op) (loop))]))) + (printf "assembled codes ~s\n" assembled-codes) + (void)] [else (package (SexpSource (parameterize ([read-accept-reader #t]) (read (open-input-string (string-append "#lang whalesong\n" text-src))))) @@ -67,7 +89,7 @@ -(write-repl-runtime-files) +;(write-repl-runtime-files) (serve/servlet start #:servlet-path "/compile" #:extra-files-paths (list htdocs)