----- Original Message ----- From: "Dan Sugalski" <[EMAIL PROTECTED]> To: "K Stol" <[EMAIL PROTECTED]>; "Gordon Henriksen" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Friday, July 04, 2003 4:56 PM Subject: Re: Tentative [PATCH]: valclone
> At 9:13 AM +0200 7/2/03, K Stol wrote: > >In Perl this is possible (because of the syntax of Perl). But what > >about languages in which it cannot be expressed? > >I know, Parrot is mainly for Perl, but not *only* for Perl. Wouldn't > >it be nice to have Parrot supporting this? > > Yup, it would. Parrot's assuming pass-by-reference for reference > types (Strings and PMCs) and pass-by-value for value types (ints and > nums). I'm tempted to leave it like that so there's a level of > constancy there, and let the languages that want to take parameters > in by value rather than reference make a copy of what's passed in. > So, you agree it would be nice for Parrot to have an option to pass PMCs (and maybe strings as well) by value, as well as the standard by reference, right? If so, there should be some *fast* way of doing this (of course, this is already possible using the current instructions, but it should be *fast*), so maybe a special instruction for that? > Real reference types, the way objects are traditionally handled, > won't change in this sort of scheme (as we'd just copy the reference) > but that's normally the way things are supposed to happen. > > This, of course, brings up the question of who gets to decide whether > things are passed by value or reference, the caller or callee, so I'm > up for discussion on that. Well, this is my try... Good point. At first I didn't really think this through too well. My first idea was this: The callee copies the passed-in PMCs, so the callee would be responsible. In this case, the caller isn't really sure if the passed-in PMCs are still valid after the function call: the called function could have changed them, or even destroyed them (if the callee was compiled to handle the params. by reference) (But this really isn't an issue, because the compiler will emit the right instructions, but it's just a thought). On the other hand, it would be quite ok if the callee doesn't really care which PMCs it receives, it just does its job (and it doesn't really care if the args are copies or the 'original' PMCs), and it depends on the compiler for emitting the right code (so it will spit out by-value instructions). (so the caller is responsible). Would there be a performance difference? I think not, but I could well be wrong (anybody?). klaas-jan
