Simon Cozens <[EMAIL PROTECTED]> wrote: > On Mon, Nov 19, 2001 at 03:29:00PM +0000, Dave Mitchell wrote: > > I'd prefer the "you have 8 private bits, the rest is Parrot's" approach > > rather than the "Parrot has 8 bits and the rest is yours for now, we'll > > let you know when we want to grab some more back off you" approach. I think > > that way, we'll have less backwards compatibility issues for 3rd party code. > > You are right, of course. Thankfully, you're right sufficiently early > that all you need to send me a patch for is the documentation and > include/parrot/pmc.h :)
My bluff has been called! Okay, here's a stab at it. I'm keen that we use enums to define constants, rather than using #define. --- ./docs/vtables.pod Mon Nov 19 23:44:15 2001 +++ ./docs/vtables.pod Tue Nov 20 00:29:34 2001 @@ -100,17 +100,23 @@ is to define a structure that will hook onto the C<data>, if your data type needs to use that, and then also define some user-defined flags. -Flags are accessed by C<< pmc->flags >>, but a number of these flags -are reserved by Parrot internally. Hence, you should start your -user-defined flags from offset C<PMC_USER_FLAG>, like this: +Flags are accessed by C<< pmc->flags >>. Most of the bits in the flag word +are reserved for use by parrot itself, but a number of them have been +assigned for general use by individual classes. These are referred to as +C<PMC_private0_FLAG> .. C<PMC_private7_FLAG>. (The '7' may change during the +early development of parrot, but will become pretty fixed at some point.) - #define FOOBYNUMBER_IS_BIGNUM (1<<(PMC_USER_FLAG)) - #define FOOBYNUMBER_IS_BIGINT (1<<(PMC_USER_FLAG+1)) - ... +Normally, you will want to alias these generic bit names to something +more meaningful within your class: -You're quite at liberty to make these two definitions in a separate -header file, but I find it more convenient to keep everything together -in F<foobynumber.c>. + enum { + Foobynumber_is_bignum = PMC_private0_FLAG, + Foobynumber_is_bigint = PMC_private1_FLAG, + .... + }; + +You're quite at liberty to declare these in a separate header file, but I +find it more convenient to keep everything together in F<foobynumber.c>. You may also use the C<cache> union in the PMC structure to remove some extraneous dereferences in your code if that would help. --- ./include/parrot/pmc.h Mon Nov 19 23:44:15 2001 +++ ./include/parrot/pmc.h Tue Nov 20 00:29:37 2001 @@ -33,7 +33,29 @@ SYNC *synchronize; }; -#define PMC_USER_FLAG 9 /* Unreserved flags start here */ +/* PMC flag bits */ + +typedef enum { + /* the first 8 bits are for private use by individual vtable + * classes. It is suggested that you alias these within an individual + * class's header file + */ + PMC_private0_FLAG = 2 << 0, + PMC_private1_FLAG = 2 << 1, + PMC_private2_FLAG = 2 << 2, + PMC_private3_FLAG = 2 << 3, + PMC_private4_FLAG = 2 << 4, + PMC_private5_FLAG = 2 << 5, + PMC_private6_FLAG = 2 << 6, + PMC_private7_FLAG = 2 << 7, + + /* The rest of the flags are for use by Parrot */ + + PMC_tba_FLAG = 2 << 8, /* XXX none yet, just an example... */ +} PMC_flags; + +/* XXX add various bit test macros once we have need of them */ + #endif