adjusting the builder so that compression will work as an option

This commit is contained in:
Danny Yoo 2011-07-11 22:40:16 -04:00
parent a01da31310
commit c030b53333
3 changed files with 35 additions and 15 deletions

View File

@ -11,6 +11,7 @@
"../parser/parse-bytecode.rkt" "../parser/parse-bytecode.rkt"
racket/match racket/match
racket/list racket/list
racket/promise
(prefix-in query: "../lang/js/query.rkt") (prefix-in query: "../lang/js/query.rkt")
(planet dyoo/closure-compile:1:1) (planet dyoo/closure-compile:1:1)
(prefix-in runtime: "get-runtime.rkt") (prefix-in runtime: "get-runtime.rkt")
@ -301,22 +302,25 @@ MACHINE.modules[~s] =
(define (compress x) (define (compress x)
(if (current-compress-javascript?) (cond [(current-compress-javascript?)
(closure-compile x) (log-debug "compressing javascript...")
x)) (closure-compile x)]
[else
(log-debug "not compressing javascript...")
x]))
(define *the-runtime* (define *the-runtime*
(let ([buffer (open-output-string)]) (delay (let ([buffer (open-output-string)])
(write-runtime buffer) (write-runtime buffer)
(compress (compress
(get-output-string buffer)))) (get-output-string buffer)))))
;; get-runtime: -> string ;; get-runtime: -> string
(define (get-runtime) (define (get-runtime)
*the-runtime*) (force *the-runtime*))

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
all: all:
../../whalesong get-javascript fact.rkt > fact.js ../../whalesong get-javascript --verbose --compress-javascript fact.rkt > fact.js
../../whalesong get-runtime > runtime.js ../../whalesong get-runtime --verbose --compress-javascript > runtime.js

View File

@ -8,6 +8,7 @@
"js-assembler/package.rkt" "js-assembler/package.rkt"
"private/command.rkt" "private/command.rkt"
"logger.rkt" "logger.rkt"
"parameters.rkt"
raco/command-name) raco/command-name)
@ -43,6 +44,10 @@
[("-v" "--verbose") [("-v" "--verbose")
("Display verbose messages.") ("Display verbose messages.")
(current-verbose? #t)] (current-verbose? #t)]
[("--compress-javascript")
("Compress JavaScript with Google Closure (requires Java)")
(current-compress-javascript? #t)]
#:args (path) #:args (path)
(do-the-build path)] (do-the-build path)]
["get-runtime" "print the runtime library to standard output" ["get-runtime" "print the runtime library to standard output"
@ -51,6 +56,10 @@
[("-v" "--verbose") [("-v" "--verbose")
("Display verbose messages.") ("Display verbose messages.")
(current-verbose? #t)] (current-verbose? #t)]
[("--compress-javascript")
("Compress JavaScript with Google Closure (requires Java)")
(current-compress-javascript? #t)]
#:args () #:args ()
(print-the-runtime)] (print-the-runtime)]
["get-javascript" "Gets just the JavaScript code and prints it to standard output" ["get-javascript" "Gets just the JavaScript code and prints it to standard output"
@ -59,6 +68,11 @@
[("-v" "--verbose") [("-v" "--verbose")
("Display verbose messages.") ("Display verbose messages.")
(current-verbose? #t)] (current-verbose? #t)]
[("--compress-javascript")
("Compress JavaScript with Google Closure (requires Java)")
(current-compress-javascript? #t)]
#:args (file) #:args (file)
(get-javascript-code file)])) (get-javascript-code file)]))
@ -77,7 +91,8 @@
(let ([msg (sync receiver)]) (let ([msg (sync receiver)])
(match msg (match msg
[(vector level msg data) [(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))))))) (loop)))))))
@ -109,15 +124,16 @@
(define (print-the-runtime) (define (print-the-runtime)
(turn-on-logger!) (turn-on-logger!)
(write-runtime (current-output-port))) (display (get-runtime) (current-output-port)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (get-javascript-code filename) (define (get-javascript-code filename)
(turn-on-logger!) (turn-on-logger!)
(write-standalone-code (display (get-standalone-code
(make-ModuleSource (build-path filename)) (make-ModuleSource (build-path filename)))
(current-output-port))) (current-output-port)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;