[Cardinal-devel] Cardinal Design Documents - Code Generation
Dan Sugalski
dan at sidhe.org
Mon Aug 9 15:46:05 EDT 2004
At 8:44 PM +0100 8/9/04, mark sparshatt wrote:
>h1. Code Generation
>
>h2. Method Name Munging
>
>Parrot doesn't support symbols within function names so it's
>neccessary to modify the names of some methods.
Bah, we need to fix that. (Though it may be worth it to alias these
to the 'standard' vtable method names, but that's a separate issue)
>h2. Blocks/Yield
>
>A block will be converted into a sub (or sub like) pmc object and
>passed to the method as a parameter.
>
>Yield can then be translated to an invocation of that sub pmc.
>
>Some issues are
>1 This parameter needs to be marked somehow so the method knows that
>it's a block. In particular care needs to be taken to ensure it
>doesn't get slurped up by *args. One method is to say that the first
>parameter to a method will either be a sub pmc representing a block or
>nil if there isn't a block
>
>2 The block needs to access any local variables where it's created.
>
>3 Parameter passing is different for blocks and for methods
Arguably the block ought to be turned into a closure, but that's another issue.
We'd talked about having a special block parameter for just this use,
but Larry argued me out of it. I'm all for being argued back in if
you want. :) Alternately we can come up with a good Plan B here.
>h2. Modules
>
>h3. Implementing
>
>Modules need to be implemented using a specialised version of the
>class PMC which can't be instantiated.
Is that the only difference between a class and a module? (Not being
able to instantiate an object of the class?)
>h3. Including
>
>This should work the same way as cRuby. Create an annomynous class
>which references the module, then twiddle the inheritance for the
>including class so it inherits from the anomynous class.
Or alternately just use MI when building the class, so if you had
class C which was a B and included A, then its parents would be B and
A.
>h2. MetaClasses
>
>Classes in Ruby are also objects. Parrot doesn't currently have
>support for metaclasses
Bah. Let's fix this too. I'm fuzzy on metaclasses, unfortunately, as
I'm not a big OO guy. Time to change that, I guess.
>
>h2. Singleton Classes
>
>Ruby handles adding methods to an individual object by creating an
>anomynous singleton class which inherits from the objects class and
>then changing the object to be an instance of this class.
Which should work for Parrot too, though we lack some support to add
methods to class objects.
--
Dan
--------------------------------------it's like this-------------------
Dan Sugalski even samurai
dan at sidhe.org have teddy bears and even
teddy bears get drunk
More information about the Cardinal-devel
mailing list