cvsuser     04/12/09 08:52:03

  Modified:    classes  boolean.pmc integer.pmc
               t/pmc    objects.t
  Log:
  class refactoring 2 - Boolean
  * Boolean isa Integer (no more PerlInt)
  
  Revision  Changes    Path
  1.19      +28 -91    parrot/classes/boolean.pmc
  
  Index: boolean.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/boolean.pmc,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- boolean.pmc       25 Aug 2004 08:03:18 -0000      1.18
  +++ boolean.pmc       9 Dec 2004 16:52:02 -0000       1.19
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: boolean.pmc,v 1.18 2004/08/25 08:03:18 leo Exp $
  +$Id: boolean.pmc,v 1.19 2004/12/09 16:52:02 leo Exp $
   
   =head1 NAME
   
  @@ -24,13 +24,13 @@
   #include "parrot/parrot.h"
   #include "parrot/perltypes.h"
   
  -pmclass Boolean extends PerlInt {
  +pmclass Boolean extends Integer {
   
   /*
   
   =item C<class_init ()>
   
  -Define 3 pythonic globals C<True>, C<False>, and C<__debug__>.
  +Define 2 pythonic globals C<True>, C<False>.
   
   XXX are these generally useful or should they be moved to src/py_func.c?
   
  @@ -41,38 +41,33 @@
       void class_init() {
           if (pass) {
               PMC *t;
  +            STRING *s;
               t = pmc_new(interp, enum_class_Boolean);
               PMC_int_val(t)  = 1;
  -            Parrot_store_global(interp, NULL,
  -                    const_string(interp, "True"), t);
  +            s = CONST_STRING(interp, "True");
  +            Parrot_store_global(interp, NULL, s, t);
               t = pmc_new(interp, enum_class_Boolean);
  -            Parrot_store_global(interp, NULL,
  -                    const_string(interp, "False"), t);
  -            t = pmc_new(interp, enum_class_Boolean);
  -            PMC_int_val(t)  = 1;
  -            Parrot_store_global(interp, NULL,
  -                    const_string(interp, "__debug__"), t);
  +            Parrot_store_global(interp, NULL, s, t);
           }
       }
   
   /*
   
  -=item C<void* invoke(void* next)>
  +=item C<PMC* instantiate()>
   
  -Pythonic object constructor. SELF is a Boolean Class object. Return a new
  -C<bool> object according to 2.1. Built-in Functions.
  +Object constructor. SELF is a Boolean Class object. Return a new
  +C<bool> object according to the passed PMC value.
   
   =cut
   
   */
  -    void* invoke(void* next) {
  +    PMC* instantiate() {
  +        /* XXX other types */
           int argcP = REG_INT(3);
           PMC *res = pmc_new(interpreter, enum_class_Boolean);
           if (argcP)
  -            VTABLE_set_integer_native(interpreter, res,
  -                    VTABLE_get_bool(interpreter, REG_PMC(5)));
  -        REG_PMC(5) = res;
  -        return next;
  +            PMC_int_val(res) = VTABLE_get_bool(interpreter, REG_PMC(5));
  +        return res;
       }
   /*
   
  @@ -86,8 +81,8 @@
       STRING* get_string () {
           if (Interp_flags_TEST(INTERP, PARROT_PYTHON_MODE))
               return PMC_int_val(SELF) ?
  -                const_string(INTERP, "True") :
  -                const_string(INTERP, "False");
  +                CONST_STRING(INTERP, "True") :
  +                CONST_STRING(INTERP, "False");
           else
               return SUPER();
       }
  @@ -97,14 +92,25 @@
   
   =item C<void set_integer_native (INTVAL value)>
   
  +=item C<void set_bool (INTVAL value)>
  +
  +=item C<void set_pmc (PMC* value)>
  +
   =cut
   
   */
  -
       void set_integer_native (INTVAL value) {
           PMC_int_val(SELF) = (value != 0);
       }
   
  +
  +    void set_bool (INTVAL value) {
  +        PMC_int_val(SELF) = (value != 0);
  +    }
  +
  +    void set_pmc (PMC* value) {
  +        PMC_int_val(SELF) = VTABLE_get_bool(INTERP, value);
  +    }
   /*
   
   =item C<void set_number_native (FLOATVAL value)>
  @@ -132,75 +138,6 @@
       void set_string_native (STRING* value) {
           PMC_int_val(SELF) = string_bool(INTERP, value);
       }
  -
  -/*
  -
  -=item C<void neg(PMC* dest)>
  -
  -Set C<dest> to the negated value of C<SELF>.
  -
  -=cut
  -
  -*/
  -
  -    void neg (PMC* dest) {
  -        if (dest == SELF)
  -            PMC_int_val(SELF) = -PMC_int_val(SELF);
  -        else
  -            VTABLE_set_integer_native(INTERP, dest, -PMC_int_val(SELF));
  -    }
  -
  -/*
  -
  -=item C<void logical_or(PMC* value, PMC* dest)>
  -
  -Sets the logical C<OR> of the boolean and C<*value> as the value of
  -C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void logical_or (PMC* value, PMC* dest) {
  -        VTABLE_set_integer_native(INTERP, dest,
  -            PMC_int_val(SELF) ||
  -            VTABLE_get_bool(INTERP, value));
  -    }
  -
  -/*
  -
  -=item C<>
  -
  -Sets the logical C<AND> of the boolean and C<*value> as the value of
  -C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void logical_and (PMC* value, PMC* dest) {
  -        VTABLE_set_integer_native(INTERP, dest,
  -            PMC_int_val(SELF) &&
  -            VTABLE_get_bool(INTERP, value));
  -    }
  -
  -/*
  -
  -=item C<void logical_xor(PMC* value, PMC* dest)>
  -
  -Sets the logical C<XOR> of the boolean and C<*value> as the value of
  -C<*dest>.
  -
  -=cut
  -
  -*/
  -
  -    void logical_xor (PMC* value, PMC* dest) {
  -        VTABLE_set_integer_native(INTERP, dest,
  -            ( PMC_int_val(SELF) ? 1 : 0 ) ^
  -            VTABLE_get_bool(INTERP, value));
  -    }
  -
   }
   
   /*
  
  
  
  1.20      +13 -1     parrot/classes/integer.pmc
  
  Index: integer.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/integer.pmc,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- integer.pmc       9 Dec 2004 13:31:04 -0000       1.19
  +++ integer.pmc       9 Dec 2004 16:52:02 -0000       1.20
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2003 The Perl Foundation.  All Rights Reserved.
  -$Id: integer.pmc,v 1.19 2004/12/09 13:31:04 leo Exp $
  +$Id: integer.pmc,v 1.20 2004/12/09 16:52:02 leo Exp $
   
   =head1 NAME
   
  @@ -339,6 +339,18 @@
   
   /*
   
  +=item C<void set_bool(INTVAL value)>
  +
  +=cut
  +
  +*/
  +    void set_bool (INTVAL value) {
  +        DYNSELF.morph(enum_class_Boolean);
  +        DYNSELF.set_bool(value);
  +    }
  +
  +/*
  +
   =item C<void set_bignum_native(BIGNUM *value)>
   
   =cut
  
  
  
  1.60      +4 -4      parrot/t/pmc/objects.t
  
  Index: objects.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/objects.t,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- objects.t 7 Dec 2004 13:08:37 -0000       1.59
  +++ objects.t 9 Dec 2004 16:52:03 -0000       1.60
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: objects.t,v 1.59 2004/12/07 13:08:37 leo Exp $
  +# $Id: objects.t,v 1.60 2004/12/09 16:52:03 leo Exp $
   
   =head1 NAME
   
  @@ -113,11 +113,11 @@
       print I0
       print "\n"
   
  -    isa I0, P1, "PerlInt"
  +    isa I0, P1, "Integer"
       print I0
  -    isa I0, P1, "PerlIn"
  +    isa I0, P1, "Integ"
       print I0
  -    isa I0, P1, "erl"
  +    isa I0, P1, "eger"
       print I0
       isa I0, P1, " "
       print I0
  
  
  

Reply via email to