Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Calling Methods on Class PMCs

已查看 2 次
跳至第一个未读帖子

Chromatic

未读,
2006年10月8日 23:12:162006/10/8
收件人 parrot-...@perl.org
I'm experimenting with better forms of OO in PIR. I want to add a
get_parents() method on the Class PMC. Normally, I'd do something like the
attached patch, but the attached example file I use for testing shows that it
doesn't work for me.

I dug around a bit and couldn't find a reason for why it shouldn't work.

Note that I can't even call name() on a Class PMC either. Hm.

-- c

class_method.patch
class_fun.pir

Leopold Toetsch

未读,
2006年10月9日 13:48:362006/10/9
收件人 perl6-i...@perl.org
Am Montag, 9. Oktober 2006 05:12 schrieb chromatic:
> I'm experimenting with better forms of OO in PIR. I want to add a
> get_parents() method on the Class PMC. Normally, I'd do something like the
> attached patch, but the attached example file I use for testing shows that
> it doesn't work for me.

You were probably looking for the C<get_mro> opcode. Your get_parents() is
only returning the immediate parent(s) of that _class_ but not the full
chain, which is in C<vtable->mro>.

See also: perldoc src/ops/pmc.ops

> I dug around a bit and couldn't find a reason for why it shouldn't work.

You are calling it on a ParrotObject, which ought to delegate the call to it's
class. But as said, you'd get only 'Child' in your case.

> Note that I can't even call name() on a Class PMC either. Hm.

As a method? You can't call any vtable function with method syntax.

See also:

http://perlcabal.org/~lt/toreview/Cfunc.pod

But there is:

inline op typeof (out STR, invar PMC) {
$1 = VTABLE_name(interpreter, $2);
goto NEXT();
}

i.e. the C<typeof> opcode is the interface to the class name.

> -- c

leo

0 个新帖子