Klaas-Jan Stol wrote:
Leopold Toetsch wrote:
A couple of things I don't understand:
1. When I invoke an object, its invoke handler is called, right? Isn't
this invoke handler by default just empty?
No, not really. Have a look at parrotobject.c to see the generated code
(after removing invoke() in parrotobject.pmc).
... It's the task of the PMC
implementor (or when writing a class in PIR, then the class writer -- me
in this case) to implement this invoke handler (so I can implement the
behaviour I want)
Well, I think we should have a reasonable default implementation.
2. what should "void *invoke(void *next)" in ParrotObject.pmc do then?
(what should be its function?) (this is more or less a the same question
as 1.)
3. What's this "next" argument?
The default operation of an invoke inside Parrot (written in C) is
return the address in bytecode to execute next. The passed in argument
next is just the address after the invoke.
4. And, last but not least, what do you mean by this:
" because it can't create a signature for the "void *next" argument
in the call. "
pmc2c.pl just tries to convert all arguments to something that is usable
in PASM/PIR. This fails for the void *next thingy.
Or, do you perhaps mean that when doing this:
$P0 = new "Foo"
$P0(arg1, arg2, arg3)
Yep.
then, the object (represented by ParrotObject.pmc) 's __invoke is
called, and it should be possible to pass arguments arg1, arg2, and arg3
to the __invoke handler?
If so, then the above mentioned invoke function could be implemented
like this:
void *invoke(void *next, ...) {
va_list args; struct parrot_regs_t *bp; va_start(args,
next);
// I'm not sure what should happen now ??
Yep. See inter_run.c *runops* called from various methods in
parrotobject.c (the generated code has examples)
I'd like to try, but as pointed out above, I don't really understand
some key points (yet...)
If there are any more question, please just ask. I'm also on #parrot
(irc.pobox.com)
klaas-jan
leo