diff --git a/js-assembler/package.rkt b/js-assembler/package.rkt index 7a0d233..0a67e81 100644 --- a/js-assembler/package.rkt +++ b/js-assembler/package.rkt @@ -11,6 +11,7 @@ "../parser/parse-bytecode.rkt" racket/match racket/list + racket/promise (prefix-in query: "../lang/js/query.rkt") (planet dyoo/closure-compile:1:1) (prefix-in runtime: "get-runtime.rkt") @@ -301,22 +302,25 @@ MACHINE.modules[~s] = (define (compress x) - (if (current-compress-javascript?) - (closure-compile x) - x)) + (cond [(current-compress-javascript?) + (log-debug "compressing javascript...") + (closure-compile x)] + [else + (log-debug "not compressing javascript...") + x])) (define *the-runtime* - (let ([buffer (open-output-string)]) - (write-runtime buffer) - (compress - (get-output-string buffer)))) + (delay (let ([buffer (open-output-string)]) + (write-runtime buffer) + (compress + (get-output-string buffer))))) ;; get-runtime: -> string (define (get-runtime) - *the-runtime*) + (force *the-runtime*)) diff --git a/tests/coersing/Makefile b/tests/coersing/Makefile index 0c1cfb4..a616d5b 100644 --- a/tests/coersing/Makefile +++ b/tests/coersing/Makefile @@ -1,5 +1,5 @@ #!/bin/sh all: - ../../whalesong get-javascript fact.rkt > fact.js - ../../whalesong get-runtime > runtime.js + ../../whalesong get-javascript --verbose --compress-javascript fact.rkt > fact.js + ../../whalesong get-runtime --verbose --compress-javascript > runtime.js diff --git a/whalesong.rkt b/whalesong.rkt index 3ae44f5..ef19026 100755 --- a/whalesong.rkt +++ b/whalesong.rkt @@ -8,6 +8,7 @@ "js-assembler/package.rkt" "private/command.rkt" "logger.rkt" + "parameters.rkt" raco/command-name) @@ -43,6 +44,10 @@ [("-v" "--verbose") ("Display verbose messages.") (current-verbose? #t)] + [("--compress-javascript") + ("Compress JavaScript with Google Closure (requires Java)") + (current-compress-javascript? #t)] + #:args (path) (do-the-build path)] ["get-runtime" "print the runtime library to standard output" @@ -51,6 +56,10 @@ [("-v" "--verbose") ("Display verbose messages.") (current-verbose? #t)] + [("--compress-javascript") + ("Compress JavaScript with Google Closure (requires Java)") + (current-compress-javascript? #t)] + #:args () (print-the-runtime)] ["get-javascript" "Gets just the JavaScript code and prints it to standard output" @@ -59,6 +68,11 @@ [("-v" "--verbose") ("Display verbose messages.") (current-verbose? #t)] + + [("--compress-javascript") + ("Compress JavaScript with Google Closure (requires Java)") + (current-compress-javascript? #t)] + #:args (file) (get-javascript-code file)])) @@ -77,7 +91,8 @@ (let ([msg (sync receiver)]) (match msg [(vector level msg data) - (printf "~a: ~a\n" level msg)])) + (fprintf (current-error-port)"~a: ~a\n" level msg) + (flush-output (current-error-port))])) (loop))))))) @@ -109,15 +124,16 @@ (define (print-the-runtime) (turn-on-logger!) - (write-runtime (current-output-port))) + (display (get-runtime) (current-output-port))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (get-javascript-code filename) (turn-on-logger!) - (write-standalone-code - (make-ModuleSource (build-path filename)) - (current-output-port))) + (display (get-standalone-code + (make-ModuleSource (build-path filename))) + (current-output-port))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;