[racket-dev] current-load/use-compiled
Did you find the compiler/cm library? I think that's what you want.
Robby
On Thu, Jun 23, 2011 at 12:24 AM, Jon Rafkind <rafkind at cs.utah.edu> wrote:
> I'm trying to hook into the part of racket that loads files so I can
> automatically create .zo files when they don't exist (and no, I don't
> want to type raco make). Here is the code that loads the file and sets
> up the handler (more explanation follows the code).
>
> == load.rkt
> (let ([namespace (make-base-namespace)])
> (define loader (current-load/use-compiled))
> (parameterize ([current-namespace namespace]
> [current-load/use-compiled
> (lambda (path something)
> (define-values (parent self _) (split-path path))
> (parameterize ([current-load-relative-directory
> parent])
> (printf "compile/load ~a ~a\n" path something)
> (printf "load directory ~a\n"
> (current-load-relative-directory))
> #;
> ((compile-zos #f #:module? #t) (list path)
> "compiled")
> (define load-path
> (if (is-zo? path)
> path
> (build-path parent "compiled"
> (path-add-suffix self #".zo"))))
> (printf "Loading file ~a\n" load-path)
> (loader load-path something)))])
> (eval-syntax (with-syntax ([file "test.rkt"])
> #'(require file)))))
>
> And here are the files being loaded
> == test.rkt
> #lang racket/base
>
> (require "test1.rkt")
>
> (printf "hello from test!\n")
>
> == test1.rkt
> #lang racket/base
>
> (require (for-syntax racket/base))
>
> (define-syntax (foo stx)
> (printf "hello from foo macro\n")
> #'(void))
>
> (foo)
>
> #;
> (begin-for-syntax
> (printf "hello from phase1 code\n"))
>
> (printf "test1!\n")
>
> If I uncomment the 'begin-for-syntax' expression and run 'raco make' to
> produce a .zo file then running 'racket test.rkt' won't display the
> "hello from phase1 code" line. However if I run 'load.rkt' then no
> matter if there is a .zo or not I see that printf being executed.
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/dev
>