Monday, December 06, 2004

Why support the Introspector, What is it?

Often I am asked, What is the introspector? What does it provide? Why should I support you? What makes your product unique?

Let me try and put it down for the record, at least a starting point.

When you program in C, you are often confronted with the problem that you want to wrap a structure in another to do this You want to be able to traverse over all the fields of a structure.

You ask yourself, why dont I have the ability to do this? Why does not the compiler support this simple feature? Well the answer is, the compiler * supports* this feature, you just dont have access to it! There are a wealth of features in the compiler that you are not given access to.

Now, you may ask yourself, why cannot I have access to this information, and my answer is you can! The introspector provides it.

Now, you may ask yourself : How will you be able to access this data? When will you get access to it? What will it look like?

The data will be first extracted into rdf. Then it will be presented to you via the rdf api redland. The question is, when will this code be invoked? My goal is to be able to present this data to you at compile time and at runtime!

It should be possible to write code that uses the metadata of the compiler that is usable at any given time. It should be possible to write expressions that are captured at compile time and made available at run time.

Let me give you an example :

Lets say you want to defined a new function called funky_print().

This function you want to make very flexible, so that it will be able to process any type that you pass to it. So, you declare it like this funky_print(void *).

Then you want to generate code to handle all types of calls to it, so you make an introspector query like this : intercept_calls(&funky_print,funky_print_handler);

Lets say you have the simple set of declarations :
funky_print (void * args);
funky_print_handler (void * args);
intercept_calls (void * function,void * process);

int main()
{
intercept_calls (&funky_print,&funky_print_handler);
return 1;
}

Now,
none of these functions are defined yet. But we have clearly be able to mark the relationships using the compiler, using native c. Now all we need to do is create a program that will process this data once it is extracted.

In the introspector you have the ability to capture all calls to a function. You can filter the rdf and extract all those calls via query. Then you can extract all the types of the parameters, all the sources of data from the caller. Basically you have all the data that the compiler does.

In this case you will be able to generate code for all types of the print routine and then replace the funky_print function calls with a specialized function.

The advantage of this technique is that you will be able define
your own meta data and meta functions inside and outside of the compiler without changing the compiler. The meta functions will be able to written in your language of choice and will allow you do have the freedom program the way you feel like.

more to follow.

mike