[racket] querying for compile-time information
One way is a compile-time table. See, for example, the implementation of
typed scheme/racket:
www.ccs.neu.edu/scheme/pubs/scheme2007-ctf.pdf
Except instead of being indexed by identifier, the table should be
indexed by module. Probably the simplest way to represent a module is by
its resolved module path (path/symbol, not the structure). You can get
the resolved module path via #%variable-reference.
(define-syntax-rule (require-permission perm)
(begin-for-syntax
(let* ([this-module
(variable-reference->resolved-module-path
(#%variable-reference))]
[key
(resolved-module-path-name this-module)])
(hash-set! the-table
key
(cons 'perm (hash-ref the-table key null))))))
You can use (dynamic-require mod (void)) to *visit* a module (and thus
have it register itself in the compile-time table) without running it.
Ryan
On 09/09/2010 02:56 PM, Danny Yoo wrote:
> I'm trying to figure out how to query a module for compile-time
> information. I've got some toy code here:
>
> http://github.com/dyoo/permissions
>
> Basically, I want to annotate a module with permissions that the
> module requires. I'm defining a permission to be a literal string for
> the moment. I want to have a way of querying a module, later on, for
> those permissions. For example, the open-image-url.rkt module here:
>
> http://github.com/dyoo/permissions/blob/master/t/open-image-url.rkt
>
> says that it requires network access. I'd like to have my query module:
>
> http://github.com/dyoo/permissions/blob/master/query.rkt
>
> be able to grab the set of permissions that a module says that it needs.
>
> Doing this at runtime is something I know how to accomplish, by having
> my require-permission macro introduce a 'permissions binding.
> However, I don't want to do it that way: I want to grab this
> information without evaluating the run-time portion of a module.
>
>
> I started hacking at this on my compile-time branch
> (http://github.com/dyoo/permissions/tree/compile-time) but I'm getting
> stuck. In particular, I don't quite know how to get my query.rkt
> module to communicate with the record.rkt module. Can someone give
> pointers on what I should be looking at?
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users