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"
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*))

View File

@ -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

View File

@ -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)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;