parent
1f2e1c6647
commit
e0e144e210
|
@ -7,4 +7,5 @@
|
||||||
("decompile" compiler/commands/decompile "decompile bytecode" #f)
|
("decompile" compiler/commands/decompile "decompile bytecode" #f)
|
||||||
("expand" compiler/commands/expand "macro-expand source" #f)
|
("expand" compiler/commands/expand "macro-expand source" #f)
|
||||||
("distribute" compiler/commands/exe-dir "prepare executable(s) in a directory for distribution" #f)
|
("distribute" compiler/commands/exe-dir "prepare executable(s) in a directory for distribution" #f)
|
||||||
("ctool" compiler/commands/ctool "compile and link C-based extensions" #f)))
|
("ctool" compiler/commands/ctool "compile and link C-based extensions" #f)
|
||||||
|
("demod" compiler/demodularizer/batch "produce a whole program from a single module" #f)))
|
||||||
|
|
|
@ -65,13 +65,13 @@ Here's the idea:
|
||||||
|
|
||||||
|
|
||||||
;; Compile
|
;; Compile
|
||||||
#;(eprintf "Removing existing zo file~n")
|
#;(log-debug "Removing existing zo file~n")
|
||||||
#;(define compiled-zo-path (build-compiled-path base (path-add-suffix name #".zo")))
|
#;(define compiled-zo-path (build-compiled-path base (path-add-suffix name #".zo")))
|
||||||
|
|
||||||
#;(when (file-exists? compiled-zo-path)
|
#;(when (file-exists? compiled-zo-path)
|
||||||
(delete-file compiled-zo-path))
|
(delete-file compiled-zo-path))
|
||||||
|
|
||||||
(eprintf "Compiling module~n")
|
(log-debug "Compiling module~n")
|
||||||
(void (system* (find-executable-path "raco") "make" file-to-batch))
|
(void (system* (find-executable-path "raco") "make" file-to-batch))
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,39 +80,39 @@ Here's the idea:
|
||||||
(define merged-zo-path (build-compiled-path merged-source-base (path-add-suffix merged-source-name #".zo")))
|
(define merged-zo-path (build-compiled-path merged-source-base (path-add-suffix merged-source-name #".zo")))
|
||||||
|
|
||||||
;; Transformations
|
;; Transformations
|
||||||
(eprintf "Removing dependencies~n")
|
(log-debug "Removing dependencies~n")
|
||||||
(define-values (batch-nodep top-lang-info top-self-modidx)
|
(define-values (batch-nodep top-lang-info top-self-modidx)
|
||||||
(nodep-file file-to-batch (excluded-modules)))
|
(nodep-file file-to-batch (excluded-modules)))
|
||||||
|
|
||||||
(eprintf "Merging modules~n")
|
(log-debug "Merging modules~n")
|
||||||
(define batch-merge
|
(define batch-merge
|
||||||
(merge-compilation-top batch-nodep))
|
(merge-compilation-top batch-nodep))
|
||||||
|
|
||||||
(eprintf "GC-ing top-levels~n")
|
(log-debug "GC-ing top-levels~n")
|
||||||
(define batch-gcd
|
(define batch-gcd
|
||||||
(gc-toplevels batch-merge))
|
(gc-toplevels batch-merge))
|
||||||
|
|
||||||
(eprintf "Alpha-varying top-levels~n")
|
(log-debug "Alpha-varying top-levels~n")
|
||||||
(define batch-alpha
|
(define batch-alpha
|
||||||
(alpha-vary-ctop batch-gcd))
|
(alpha-vary-ctop batch-gcd))
|
||||||
|
|
||||||
(define batch-modname
|
(define batch-modname
|
||||||
(string->symbol (regexp-replace #rx"\\.rkt$" (path->string merged-source-name) "")))
|
(string->symbol (regexp-replace #rx"\\.rkt$" (path->string merged-source-name) "")))
|
||||||
(eprintf "Modularizing into ~a~n" batch-modname)
|
(log-debug (format "Modularizing into ~a~n" batch-modname))
|
||||||
(define batch-mod
|
(define batch-mod
|
||||||
(wrap-in-kernel-module batch-modname batch-modname top-lang-info top-self-modidx batch-alpha))
|
(wrap-in-kernel-module batch-modname batch-modname top-lang-info top-self-modidx batch-alpha))
|
||||||
|
|
||||||
;; Output
|
;; Output
|
||||||
(define batch-final batch-mod)
|
(define batch-final batch-mod)
|
||||||
|
|
||||||
(eprintf "Writing merged source~n")
|
(log-debug "Writing merged source~n")
|
||||||
(with-output-to-file
|
(with-output-to-file
|
||||||
merged-source-path
|
merged-source-path
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(pretty-print (decompile batch-final)))
|
(pretty-print (decompile batch-final)))
|
||||||
#:exists 'replace)
|
#:exists 'replace)
|
||||||
|
|
||||||
(eprintf "Writing merged zo~n")
|
(log-debug "Writing merged zo~n")
|
||||||
(void
|
(void
|
||||||
(with-output-to-file
|
(with-output-to-file
|
||||||
merged-zo-path
|
merged-zo-path
|
||||||
|
@ -120,8 +120,6 @@ Here's the idea:
|
||||||
(write-bytes (zo-marshal batch-final)))
|
(write-bytes (zo-marshal batch-final)))
|
||||||
#:exists 'replace))
|
#:exists 'replace))
|
||||||
|
|
||||||
(eprintf "Running merged source~n")
|
|
||||||
(void (system* (find-executable-path "racket") (path->string merged-source-path)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,12 @@
|
||||||
(index<=? stx-pos ordered-stxs))
|
(index<=? stx-pos ordered-stxs))
|
||||||
(prefix-syntax-start new-prefix))
|
(prefix-syntax-start new-prefix))
|
||||||
form))
|
form))
|
||||||
(eprintf "Total TLS: ~S~n" (length normal-tls))
|
(log-debug (format "Total TLS: ~S~n" (length normal-tls)))
|
||||||
(eprintf "Used TLS: ~S~n" normal-tls)
|
(log-debug (format "Used TLS: ~S~n" normal-tls))
|
||||||
(eprintf "Total lifts: ~S~n" (length lifts))
|
(log-debug (format "Total lifts: ~S~n" (length lifts)))
|
||||||
(eprintf "Used lifts: ~S~n" lifts)
|
(log-debug (format "Used lifts: ~S~n" lifts))
|
||||||
(eprintf "Total stxs: ~S~n" (length stxs))
|
(log-debug (format "Total stxs: ~S~n" (length stxs)))
|
||||||
(eprintf "Used stxs: ~S~n" ordered-stxs)
|
(log-debug (format "Used stxs: ~S~n" ordered-stxs))
|
||||||
(make-compilation-top
|
(make-compilation-top
|
||||||
max-let-depth
|
max-let-depth
|
||||||
new-prefix
|
new-prefix
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
(define total-tls (length (prefix-toplevels new-prefix)))
|
(define total-tls (length (prefix-toplevels new-prefix)))
|
||||||
(define total-stxs (length (prefix-stxs new-prefix)))
|
(define total-stxs (length (prefix-stxs new-prefix)))
|
||||||
(define total-lifts (prefix-num-lifts new-prefix))
|
(define total-lifts (prefix-num-lifts new-prefix))
|
||||||
(eprintf "max-let-depth ~S to ~S~n" max-let-depth new-max-let-depth)
|
(log-debug (format "max-let-depth ~S to ~S~n" max-let-depth new-max-let-depth))
|
||||||
(eprintf "total toplevels ~S~n" total-tls)
|
(log-debug (format "total toplevels ~S~n" total-tls))
|
||||||
(eprintf "total stxs ~S~n" total-stxs)
|
(log-debug (format "total stxs ~S~n" total-stxs))
|
||||||
(eprintf "num-lifts ~S~n" total-lifts)
|
(log-debug (format "num-lifts ~S~n" total-lifts))
|
||||||
(make-compilation-top
|
(make-compilation-top
|
||||||
new-max-let-depth new-prefix
|
new-max-let-depth new-prefix
|
||||||
(make-splice (gen-new-forms new-prefix)))]
|
(make-splice (gen-new-forms new-prefix)))]
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
[(struct module-variable (modidx sym pos phase))
|
[(struct module-variable (modidx sym pos phase))
|
||||||
(match rw
|
(match rw
|
||||||
[(struct modvar-rewrite (self-modidx provide->toplevel))
|
[(struct modvar-rewrite (self-modidx provide->toplevel))
|
||||||
(eprintf "Rewriting ~a of ~S~n" pos (mpi->path* modidx))
|
(log-debug (format "Rewriting ~a of ~S~n" pos (mpi->path* modidx)))
|
||||||
(+ (hash-ref MODULE-TOPLEVEL-OFFSETS self-modidx
|
(+ (hash-ref MODULE-TOPLEVEL-OFFSETS self-modidx
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(error 'compute-new-modvar "toplevel offset not yet computed: ~S" self-modidx)))
|
(error 'compute-new-modvar "toplevel offset not yet computed: ~S" self-modidx)))
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
(cond
|
(cond
|
||||||
; Primitive module like #%paramz
|
; Primitive module like #%paramz
|
||||||
[(symbol? rw)
|
[(symbol? rw)
|
||||||
(eprintf "~S from ~S~n" sym rw)
|
(log-debug (format "~S from ~S~n" sym rw))
|
||||||
(values (add1 i)
|
(values (add1 i)
|
||||||
(list* tl new-toplevels)
|
(list* tl new-toplevels)
|
||||||
(list* (+ i toplevel-offset) remap))]
|
(list* (+ i toplevel-offset) remap))]
|
||||||
|
@ -124,20 +124,20 @@
|
||||||
(length mod-toplevels))
|
(length mod-toplevels))
|
||||||
(error 'merge-module "Not remapping everything: ~S ~S~n"
|
(error 'merge-module "Not remapping everything: ~S ~S~n"
|
||||||
mod-toplevels toplevel-remap))
|
mod-toplevels toplevel-remap))
|
||||||
(eprintf "[~S] Incrementing toplevels by ~a~n"
|
(log-debug (format "[~S] Incrementing toplevels by ~a~n"
|
||||||
name
|
name
|
||||||
toplevel-offset)
|
toplevel-offset))
|
||||||
(eprintf "[~S] Incrementing lifts by ~a~n"
|
(log-debug (format "[~S] Incrementing lifts by ~a~n"
|
||||||
name
|
name
|
||||||
lift-offset)
|
lift-offset))
|
||||||
(eprintf "[~S] Filtered mod-vars from ~a to ~a~n"
|
(log-debug (format "[~S] Filtered mod-vars from ~a to ~a~n"
|
||||||
name
|
name
|
||||||
(length mod-toplevels)
|
(length mod-toplevels)
|
||||||
(length new-mod-toplevels))
|
(length new-mod-toplevels)))
|
||||||
(values (max max-let-depth mod-max-let-depth)
|
(values (max max-let-depth mod-max-let-depth)
|
||||||
(merge-prefix top-prefix new-mod-prefix)
|
(merge-prefix top-prefix new-mod-prefix)
|
||||||
(lambda (top-prefix)
|
(lambda (top-prefix)
|
||||||
(eprintf "[~S] Updating top-levels\n" name)
|
(log-debug (format "[~S] Updating top-levels\n" name))
|
||||||
(define top-lift-start (prefix-lift-start top-prefix))
|
(define top-lift-start (prefix-lift-start top-prefix))
|
||||||
(define mod-lift-start (prefix-lift-start mod-prefix))
|
(define mod-lift-start (prefix-lift-start mod-prefix))
|
||||||
(define total-lifts (prefix-num-lifts top-prefix))
|
(define total-lifts (prefix-num-lifts top-prefix))
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
(current-directory)))
|
(current-directory)))
|
||||||
(define-values (modvar-rewrite lang-info ctop)
|
(define-values (modvar-rewrite lang-info ctop)
|
||||||
(begin
|
(begin
|
||||||
(fprintf (current-error-port) "Load ~S @ ~S~n" pth phase)
|
(log-debug (format "Load ~S @ ~S~n" pth phase))
|
||||||
(nodep/dir
|
(nodep/dir
|
||||||
(parameterize ([current-load-relative-directory base-directory])
|
(parameterize ([current-load-relative-directory base-directory])
|
||||||
(path->comp-top
|
(path->comp-top
|
||||||
|
@ -98,7 +98,7 @@
|
||||||
(when (symbol? tl)
|
(when (symbol? tl)
|
||||||
(hash-set! provide-ht (intern tl) i)))
|
(hash-set! provide-ht (intern tl) i)))
|
||||||
(lambda (sym pos)
|
(lambda (sym pos)
|
||||||
(eprintf "Looking up ~S@~a~n" sym pos)
|
(log-debug (format "Looking up ~S@~a~n" sym pos))
|
||||||
(hash-ref provide-ht (intern sym)
|
(hash-ref provide-ht (intern sym)
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(error 'provide->toplevel "Cannot find ~S in ~S" sym prefix)))))
|
(error 'provide->toplevel "Cannot find ~S in ~S" sym prefix)))))
|
||||||
|
@ -114,15 +114,15 @@
|
||||||
[tl
|
[tl
|
||||||
(void)])
|
(void)])
|
||||||
(prefix-toplevels new-prefix))
|
(prefix-toplevels new-prefix))
|
||||||
(eprintf "[~S] module-variables: ~S~n" name (length (filter module-variable? (prefix-toplevels new-prefix))))
|
(log-debug (format "[~S] module-variables: ~S~n" name (length (filter module-variable? (prefix-toplevels new-prefix)))))
|
||||||
(values (make-modvar-rewrite self-modidx (construct-provide->toplevel new-prefix provides))
|
(values (make-modvar-rewrite self-modidx (construct-provide->toplevel new-prefix provides))
|
||||||
lang-info
|
lang-info
|
||||||
(append (requires->modlist requires phase)
|
(append (requires->modlist requires phase)
|
||||||
(if (and phase (zero? phase))
|
(if (and phase (zero? phase))
|
||||||
(begin (eprintf "[~S] lang-info : ~S~n" name lang-info) ; XXX Seems to always be #f now
|
(begin (log-debug (format "[~S] lang-info : ~S~n" name lang-info)) ; XXX Seems to always be #f now
|
||||||
(list (make-mod name srcname self-modidx new-prefix provides requires body empty
|
(list (make-mod name srcname self-modidx new-prefix provides requires body empty
|
||||||
unexported max-let-depth dummy lang-info internal-context)))
|
unexported max-let-depth dummy lang-info internal-context)))
|
||||||
(begin (eprintf "[~S] Dropping module @ ~S~n" name phase)
|
(begin (log-debug (format "[~S] Dropping module @ ~S~n" name phase))
|
||||||
empty))))]
|
empty))))]
|
||||||
[else (error 'nodep-module "huh?: ~e" mod-form)]))
|
[else (error 'nodep-module "huh?: ~e" mod-form)]))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user