Dan Sugalski <[EMAIL PROTECTED]> writes:

[... stuff I probably don't understand but at least I don't know WHY ...]

> * Integer, String, and Number registers 0-x are used to pass
> * parameters when the compiler calls routines.
> 
> 
> * PMC registers 0-x are used to pass parameters *if* the sub has a
> * prototype. If the sub does *not* have a prototype, a list is created
> * and passed in PMC register 0.
> 
> 
> * Subs may have variable number, or unknown number, of PMC
> * parameters. (Basically Parrot variables) They may *not* take a
> * variable or unknown number of integer, string, or number parameters.
> 
> 
> * Subs may not change prototypes
> 
> * Sub prototypes must be known at compile time. (I.e. by the end of
> * the primary compilation phase, and before mainline run
> * time. Basically the equivalent to the end of BEGIN or beginning of
> * CHECK phase)

OK, this bit I think I *know* exactly how I don't understand.


What happens when I call a prototyped sub with a code ref?


In other words, say I have 

    sub intfoo($x : int, $y : Foo) { ... }

or whatever the syntax should have been.


Then the compiler writes foo so that it gets a parameter in Int
register 0 and a (Foo) parameter in PMC register 0, right?


Now suppose I say (you smelled it coming a mile away, I know)

    my $myFoo : Foo;
    my $rf = &intfoo;
    $rf.(2,$myFoo)

(I hope Conway isn't reading this, I'm just suffering from Exegesis
Collapse and Extreme Apocalypse syntax syndromes).


There's no way the compiler can reliably work out $rf is pointing to a
prototyped code ref (not if I try hard enough), so it compiles code to
pass $rf parameters in a list in PMC register 0.  Oops.


Ways out:

1. "Ariel, you didn't understand anything..."

2. The $rf gets assigned some weird trampoline that does the
   translation from a list in PMC register 0 to Int register 0 and a
   Foo in PMC register 0.

3. intfoo has another entry point that does #2, and $rf points to
   that.

[...]

-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | [EMAIL PROTECTED]
Compugen Ltd.          |   +++ THIS SPACE TO LET +++    \ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658117 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels

Reply via email to