RFC: Expression for getting at compile-time information #20

Closed
alexrp opened this Issue Mar 23, 2013 · 0 comments

Comments

Owner

alexrp commented Mar 23, 2013

The problem: We want to be able to retrieve information about various declarations at compile time.

The planned solution: A new meta expression.

The syntax would look something like this:

meta-expr ::= "meta" ( meta-type-expr | meta-fn-expr | meta-trait-expr | meta-glob-expr | meta-macro-expr )
meta-type-expr ::= "type" type
meta-fn-expr ::= "fn" qualified-name
meta-trait-expr ::= "trait" qualified-name
meta-glob-expr ::= ( "glob" | "tls" ) qualified-name
meta-macro-expr ::= "macro" qualified-name

Each of these would return a managed pointer to a particular structure in core::rtti; specifically, @core::rtti::TypeInfo, @core::rtti::FunctionInfo, @core::rtti::TraitInfo, @core::rtti::GlobalVarInfo, @core::rtti::ThreadVarInfo, and @core::rtti::MacroInfo, respectively.

So, we could say:

pub struct Foo {
    pub bar : i32;
    pub baz : f64;
}

let ty : @core::rtti::TypeInfo = meta type Foo;

We could now use ty to discover fields in Foo (i.e. bar and baz).

Ideas, thoughts, suggestions, criticisms, etc, go!

@ghost ghost assigned alexrp Mar 23, 2013

@alexrp alexrp closed this Apr 7, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment