Boost logo

Boost :

From: Stefan Roiser (stefan.roiser_at_[hidden])
Date: 2006-01-31 16:43:50


On 31 Jan 2006, at 19:40, David Abrahams wrote:

> Stefan Roiser <stefan.roiser_at_[hidden]> writes:
>
>> On 30 Jan 2006, at 17:08, Stefan Seefeld wrote:
>>
>> With interaction with objects I meant e.g. through the meta-level
>> instantiate a class, get/set the data member values, call a function
>> on that instance, retrieve the function's return value and so on. I
>> may have missed that, but I couldn't find examples on the synopsis
>> page for this functionality.
>>
>> Reflex code for this would look something like
>>
>> Type t = Type::ByName("foo");
>> Object instance = t.Construct();
>> Object ret_obj = instance.Invoke("myFunction");
>
> Very interesting. Where do you get the object code for
> foo::myFunction? Or have you implemented a full C++ interpreter?

foo::myFunction will be invoked through a stub function which is part
of the dictionary library for class foo. A dictionary library may be
dynamically loaded in a program.

The source code for this dictionary library is produced in a non-
intrusive way with a python script (genreflex.py). Besides the stub
functions this dictionary source code contains the information about
all types, scopes, members one wants to generate the reflection
information for.

To give you an idea, typically this automatically produced code would
look like (this is part of the code for the example class of my first
mail)

static void* constructor_3558( void* mem, const std::vector<void*>&
arg, void*) {
   return ::new(mem) ::zot::foo(*(const ::zot::foo*)arg[0]);
}
static void* constructor_3559( void* mem, const std::vector<void*>&,
void*) {
   return ::new(mem) ::zot::foo();
}
static void* destructor_3560(void * o, const std::vector<void*>&,
void *) {
   ((::zot::foo*)o)->~foo(); return 0;
}
static void* method_3561( void* o, const std::vector<void*>&, void*)
{
   static int ret;
   ret = ((::zot::foo*)o)->bar();
   return &ret;
}
......

void __zot__foo_dict() {
   ClassBuilder("zot::foo", typeid(zot::foo), sizeof(zot::foo),
PUBLIC | CLASS)
   .AddBase(type_2263, BaseOffset< ::zot::foo, ::zot::foo_base >::Get
(), VIRTUAL | PUBLIC)
   .AddFunctionMember(FunctionTypeBuilder(type_void, type_4260),
"foo", constructor_3558, 0, "_ctor_arg", PUBLIC | ARTIFICIAL |
CONSTRUCTOR)
   .AddFunctionMember(FunctionTypeBuilder(type_void), "foo",
constructor_3559, 0, 0, PUBLIC | ARTIFICIAL | CONSTRUCTOR)
   .AddFunctionMember(FunctionTypeBuilder(type_void), "~foo",
destructor_3560, 0, 0, PUBLIC | ARTIFICIAL | DESTRUCTOR )
   .AddFunctionMember(FunctionTypeBuilder(type_9), "bar",
method_3561, 0, 0, PUBLIC)
   ......

>
> Have you considered something like the object interface of
> Boost.Python?
>
> Type t = Type::ByName("foo"):
> Object instance = t();
> Object ret_obj = instance.member("myFunction")();
>
> Then you'd also have, e.g.
>
> Object enlarged = instance & 5;

To be frank - no, but this is a very good idea. Thx for the input!

>
> --
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/
> listinfo.cgi/boost

-- 
Stefan Roiser
CERN, PH Department
CH - 1211 Geneva 23
Mob:+41 76 487 5334
Tel:+41 22 767 4838
Fax:+41 22 767 9425

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk