cvsuser     04/12/09 19:35:07

  Modified:    dynclasses pyboolean.pmc pybuiltin.pmc pyclass.pmc
                        pydict.pmc pyobject.pmc pystring.pmc
               languages/python/t/basic oo_attr.t
  Log:
  Incremental progress towards passing languages/python/t/basic/oo_attr.t
  
  Note: the oo_attr.t test was changed as the order of keys in a dictinary
  is not deterministic.
  
  Revision  Changes    Path
  1.5       +21 -2     parrot/dynclasses/pyboolean.pmc
  
  Index: pyboolean.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyboolean.pmc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- pyboolean.pmc     6 Dec 2004 18:09:31 -0000       1.4
  +++ pyboolean.pmc     10 Dec 2004 03:35:06 -0000      1.5
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyboolean.pmc,v 1.4 2004/12/06 18:09:31 rubys Exp $
  +$Id: pyboolean.pmc,v 1.5 2004/12/10 03:35:06 rubys Exp $
   
   =head1 NAME
   
  @@ -26,6 +26,9 @@
   static STRING *_TRUE;
   static STRING *_FALSE;
   
  +/* cache of classes referenced */
  +static INTVAL dynclass_PyBoolean;
  +
   pmclass PyBoolean extends PyObject dynpmc group python_group {
   
   /*
  @@ -40,6 +43,7 @@
   
       void class_init() {
           if (pass) {
  +            dynclass_PyBoolean = Parrot_PMC_typenum(INTERP, "PyBoolean");
               _TRUE = const_string(INTERP, "True");
               _FALSE = const_string(INTERP, "False");
           }
  @@ -49,7 +53,7 @@
   
   =item C<INTVAL get_bool()>
   
  -Returns the boolean value of the scalar.
  +Returns the boolean value.
   
   =cut
   
  @@ -75,6 +79,21 @@
   
   /*
   
  +=item C<void logical_not()>
  +
  +Returns the negated value of the boolean.
  +
  +=cut
  +
  +*/
  +
  +    void logical_not (PMC *dest) {
  +        VTABLE_morph(INTERP, dest, dynclass_PyBoolean);
  +        VTABLE_set_integer_native(INTERP, dest, PMC_int_val(SELF) == 0);
  +    }
  +
  +/*
  +
   =item C<void set_integer_native (INTVAL value)>
   
   =cut
  
  
  
  1.17      +27 -44    parrot/dynclasses/pybuiltin.pmc
  
  Index: pybuiltin.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pybuiltin.pmc,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- pybuiltin.pmc     7 Dec 2004 22:42:31 -0000       1.16
  +++ pybuiltin.pmc     10 Dec 2004 03:35:06 -0000      1.17
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pybuiltin.pmc,v 1.16 2004/12/07 22:42:31 rubys Exp $
  +$Id: pybuiltin.pmc,v 1.17 2004/12/10 03:35:06 rubys Exp $
   
   =head1 NAME
   
  @@ -94,14 +94,14 @@
   
       METHOD void __load__() {
           STRING *name, *key;
  -        PMC *stash, *iter, *item, *pad, *find;
  +        PMC *stash, *iter, *item, *pad, *temp;
           INTVAL j, n;
   
           /* Already init'ed? */
           pad = scratchpad_get_current(INTERP);
           name = const_string(INTERP, "__name__");
  -        find = scratchpad_find(INTERP, pad, name);
  -        if (find && VTABLE_defined(INTERP, find)) return;
  +        temp = scratchpad_find(INTERP, pad, name);
  +        if (temp && VTABLE_defined(INTERP, temp)) return;
   
           /* Find all PyBuiltin "nci" methods */
           stash = Parrot_find_global(INTERP,
  @@ -149,6 +149,12 @@
           VTABLE_set_integer_native(INTERP, item, E_ValueError);
           scratchpad_store_by_name(INTERP, pad, 0, key, item);
   
  +        /* Class objects */
  +        /* TODO: convert this to instances of <type> */
  +        key = const_string(INTERP, "dict");
  +        item = pmc_new(INTERP, dynclass_PyDict);
  +        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +
           /* Begin main! */
           item = pmc_new(INTERP, dynclass_PyString);
           VTABLE_set_string_native(INTERP, item,
  @@ -253,45 +259,6 @@
   
   /*
   
  -=item C<PMC* "dict"(PMC *list)>
  -
  -Create a new dictionary from a sequence
  -
  -=cut
  -
  -*/
  -
  -    METHOD PMC* dict(PMC *ar) {
  -        INTVAL i, el;
  -        PMC *dict = pmc_new(INTERP, dynclass_PyDict);
  -
  -        if (REG_INT(3) == 0) return dict;
  -
  -        if (ar->vtable->base_type == dynclass_PyDict)
  -            return ar;
  -
  -        /*
  -         * ar is an array of tuples which are key/value pairs
  -         */
  -        el = VTABLE_elements(INTERP, ar);
  -        for (i = 0; i < el; ++i) {
  -            PMC *tupl = VTABLE_get_pmc_keyed_int(INTERP, ar, i);
  -            PMC *key, *value;
  -            INTVAL n = VTABLE_elements(INTERP, tupl);
  -            if (n != 2)
  -                real_exception(INTERP, NULL, E_ValueError,
  -                        "dictionary update sequence element #%d "
  -                        "has length %d; 2 is required",
  -                        (int)i, (int)n);
  -            key = VTABLE_get_pmc_keyed_int(INTERP, tupl, 0);
  -            value = VTABLE_get_pmc_keyed_int(INTERP, tupl, 1);
  -            VTABLE_set_pmc_keyed(INTERP, dict, key, value);
  -        }
  -        return dict;
  -    }
  -
  -/*
  -
   =item C<PMC* "enumerate"(PMC *list)>
   
   Iterator for index, value of iterable.
  @@ -403,7 +370,7 @@
   
   =item C<PMC* "hash"(PMC *value)>
   
  -Returns the hex representation of C<value>.
  +Returns the hash of C<value>.
   
   =cut
   
  @@ -435,6 +402,22 @@
   
   /*
   
  +=item C<PMC* "id"(PMC *value)>
  +
  +Returns the "identity" of C<value>.
  +
  +=cut
  +
  +*/
  +
  +    METHOD PMC* id(PMC *value) {
  +        PMC * ret = pmc_new(INTERP, dynclass_PyInt);
  +        VTABLE_set_integer_native(INTERP, ret, (INTVAL)value);
  +        return ret;
  +    }
  +
  +/*
  +
   =item C<PMC* "int"(PMC *value)>
   
   Returns the integer value of C<value>.
  
  
  
  1.6       +38 -1     parrot/dynclasses/pyclass.pmc
  
  Index: pyclass.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyclass.pmc,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- pyclass.pmc       28 Nov 2004 17:27:43 -0000      1.5
  +++ pyclass.pmc       10 Dec 2004 03:35:06 -0000      1.6
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyclass.pmc,v 1.5 2004/11/28 17:27:43 rubys Exp $
  +$Id: pyclass.pmc,v 1.6 2004/12/10 03:35:06 rubys Exp $
   
   =head1 NAME
   
  @@ -23,6 +23,8 @@
   /* cache of classes referenced */
   static INTVAL dynclass_PyType;
   static STRING *CLASS;
  +static STRING *NAME;
  +static STRING *REPR;
   
   pmclass PyClass extends ParrotObject dynpmc group python_group {
   
  @@ -41,6 +43,8 @@
           if (pass) {
               dynclass_PyType = Parrot_PMC_typenum(INTERP, "PyType");
               CLASS = const_string(INTERP, "__class__");
  +            NAME = const_string(INTERP, "__name__");
  +            REPR = const_string(INTERP, "__repr__");
           }
       }
   
  @@ -112,6 +116,23 @@
   
   /*
   
  +=item C<PMC *get_repr()>
  +
  +Return the representation of this object.
  +
  +=cut
  +
  +*/
  +
  +    STRING* get_repr() {
  +        PMC *repr = VTABLE_find_method(INTERP, SELF, REPR);
  +        if (!repr) return VTABLE_get_string(INTERP, SELF);
  +        return (STRING*) Parrot_run_meth_fromc_args(INTERP, repr, SELF,
  +            REPR, "S");
  +    }
  +
  +/*
  +
   =item C<PMC *getprop(STRING *key)>
   
   Returns the property for C<*key>. If the property is not defined then for
  @@ -138,6 +159,22 @@
   
   /*
   
  +=item C<STRING *name()>
  +
  +Returns the name of this class.
  +
  +*/
  +
  +
  +    STRING* name() {
  +        PMC *class = VTABLE_get_class(INTERP, SELF);
  +        PMC *name = VTABLE_getprop(INTERP, class, NAME);
  +        if (!name) return CLASS;
  +        return VTABLE_get_string(INTERP, name);
  +    }
  +
  +/*
  +
   =item C<PMC* subclass(STRING *name)>
   
   Create a subclass of the given class.
  
  
  
  1.7       +87 -1     parrot/dynclasses/pydict.pmc
  
  Index: pydict.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pydict.pmc,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- pydict.pmc        5 Dec 2004 01:31:18 -0000       1.6
  +++ pydict.pmc        10 Dec 2004 03:35:06 -0000      1.7
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pydict.pmc,v 1.6 2004/12/05 01:31:18 rubys Exp $
  +$Id: pydict.pmc,v 1.7 2004/12/10 03:35:06 rubys Exp $
   
   =head1 NAME
   
  @@ -23,7 +23,9 @@
   STRING * hash_get_idx(Interp *interpreter, Hash *hash, PMC *key);
   
   /* cache of classes referenced */
  +static INTVAL dynclass_PyDict;
   static INTVAL dynclass_PyInt;
  +static INTVAL dynclass_PyNone;
   static INTVAL dynclass_PyString;
   
   pmclass PyDict extends PyObject need_ext does hash dynpmc group python_group 
{
  @@ -41,7 +43,9 @@
       void class_init() {
           /* class_init_code */
           if (pass) {
  +            dynclass_PyDict    = Parrot_PMC_typenum(INTERP, "PyDict");
               dynclass_PyInt     = Parrot_PMC_typenum(INTERP, "PyInt");
  +            dynclass_PyNone    = Parrot_PMC_typenum(INTERP, "PyNone");
               dynclass_PyString  = Parrot_PMC_typenum(INTERP, "PyString");
   
               make_bufferlike_pool(INTERP, sizeof(struct _hash));
  @@ -143,6 +147,31 @@
   
   /*
   
  +=item C<PMC* "fromkeys" (PMC* keys, PMC* value)>
  +
  +Create a new dict with the specified C<keys> and C<value>.  If C<value>
  +is not specified, it defaults to C<None>.
  +
  +=cut
  +
  +*/
  +
  +    METHOD PMC* fromkeys (PMC *keys, PMC* value) {
  +        PMC *iter = VTABLE_get_iter(INTERP, keys);
  +        PMC *ret = pmc_new(INTERP, dynclass_PyDict);
  +
  +        if (REG_INT(3) < 2) value = pmc_new(INTERP, dynclass_PyNone);
  +
  +        while (VTABLE_get_bool(INTERP, iter)) {       
  +            PMC *key = VTABLE_shift_pmc(INTERP, iter);
  +            VTABLE_set_pmc_keyed(INTERP, ret, key, value);
  +        }
  +
  +        return ret;
  +    }
  +
  +/*
  +
   =item C<INTVAL get_bool()>
   
   Returns true iff there are elements in the dictionary.
  @@ -346,6 +375,63 @@
   
   /*
   
  +=item C<PMC* "dict"(PMC *list)>
  +
  +Create a new dictionary from a sequence
  +
  +=cut
  +
  +TODO: move this to the dict type as this is meant to be a class method
  +not an instance method.
  +
  +*/
  +
  +    void* invoke(void *next) {
  +        PMC *dict = pmc_new(INTERP, dynclass_PyDict);
  +        PMC *source = REG_PMC(5);
  +        PMC *iter;
  +        INTVAL argc = REG_INT(3);
  +
  +        REG_INT(3) = 1;
  +        REG_PMC(5) = dict;
  +
  +        if (argc == 0) return next;
  +
  +        if (source->vtable->base_type == dynclass_PyDict) {
  +            iter = VTABLE_get_iter(INTERP, source);
  +            while (VTABLE_get_bool(INTERP, iter)) {
  +                PMC *key = VTABLE_shift_pmc(INTERP, iter);
  +                PMC *value = VTABLE_get_pmc_keyed(INTERP, source, key);
  +                VTABLE_set_pmc_keyed(INTERP, dict, key, value);
  +            }
  +        }
  +
  +        else {
  +            /*
  +             * source is an array of tuples which are key/value pairs
  +             */
  +            iter = VTABLE_get_iter(INTERP, source);
  +            while (VTABLE_get_bool(INTERP, iter)) {
  +                PMC *tupl = VTABLE_shift_pmc(INTERP, iter);
  +                PMC *key, *value;
  +                INTVAL n = VTABLE_elements(INTERP, tupl);
  +                if (n != 2)
  +                    real_exception(INTERP, NULL, E_ValueError,
  +                            "dictionary update sequence element "
  +                            "has length %d; 2 is required",
  +                            (int)n);
  +                key = VTABLE_get_pmc_keyed_int(INTERP, tupl, 0);
  +                value = VTABLE_get_pmc_keyed_int(INTERP, tupl, 1);
  +                VTABLE_set_pmc_keyed(INTERP, dict, key, value);
  +            }
  +        }
  +
  +
  +        return next;
  +    }
  +
  +/*
  +
   =item C<void set_integer_keyed(PMC *key, STRING *value)>
   
   =cut
  
  
  
  1.3       +18 -1     parrot/dynclasses/pyobject.pmc
  
  Index: pyobject.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyobject.pmc,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- pyobject.pmc      7 Dec 2004 17:24:51 -0000       1.2
  +++ pyobject.pmc      10 Dec 2004 03:35:06 -0000      1.3
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyobject.pmc,v 1.2 2004/12/07 17:24:51 rubys Exp $
  +$Id: pyobject.pmc,v 1.3 2004/12/10 03:35:06 rubys Exp $
   
   =head1 NAME
   
  @@ -707,6 +707,23 @@
   
   /*
   
  +=item C<void set_string_native(STRING *value)>
  +
  +Sets the string value.
  +
  +=cut
  +
  +*/
  +
  +    void set_string_native (STRING* value) {
  +        if (SELF->vtable->base_type != dynclass_PyString) {
  +            DYNSELF.morph(dynclass_PyString);
  +        }
  +        DYNSELF.set_string_native(value);
  +    }
  +
  +/*
  +
   =item C<void set_pmc(PMC *value)>
   
   Sets the PMC C<*value>, calling the appropriate C<set_*> method
  
  
  
  1.6       +45 -1     parrot/dynclasses/pystring.pmc
  
  Index: pystring.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pystring.pmc,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- pystring.pmc      7 Dec 2004 21:38:02 -0000       1.5
  +++ pystring.pmc      10 Dec 2004 03:35:06 -0000      1.6
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pystring.pmc,v 1.5 2004/12/07 21:38:02 rubys Exp $
  +$Id: pystring.pmc,v 1.6 2004/12/10 03:35:06 rubys Exp $
   
   =head1 NAME
   
  @@ -22,6 +22,7 @@
   
   /* cache of classes referenced */
   static INTVAL dynclass_PyString;
  +static INTVAL dynclass_PyTuple;
   
   pmclass PyString extends PyObject dynpmc group python_group {
   
  @@ -39,6 +40,7 @@
       void class_init() {
           if (pass) {
               dynclass_PyString  = Parrot_PMC_typenum(INTERP, "PyString");
  +            dynclass_PyTuple   = Parrot_PMC_typenum(INTERP, "PyTuple");
           }
       }
   
  @@ -272,6 +274,48 @@
   
   /*
   
  +=item C<PMC* "lower"()>
  +
  +downcase this string
  +
  +=cut
  +
  +*/
  +
  +    METHOD PMC* lower() {
  +        STRING *s = string_downcase(interpreter, PMC_str_val(SELF));
  +        PMC *ret = pmc_new(interpreter, enum_class_PerlString);
  +        string_set(interpreter, PMC_str_val(ret), s);
  +        return ret;
  +    }
  +
  +/*
  +
  +=item C<void modulus(PMC *value, PMC *dest)>
  +
  +Interpolates a formatstring with a set of values.
  +
  +=cut
  +
  +*/
  +
  +    void modulus (PMC* value, PMC* dest) {
  +        PMC *ar = value;
  +        /*
  +         * SELF is formatstring, value = argument array or item
  +         */
  +        if (value->vtable->base_type != enum_class_FixedPMCArray) {
  +            /* not a tuple - make one */
  +            ar = pmc_new(INTERP, dynclass_PyTuple);
  +            VTABLE_set_integer_native(INTERP, ar, 1);
  +            VTABLE_set_pmc_keyed_int( INTERP, ar, 0, value);
  +        }
  +        VTABLE_set_string_native(INTERP, dest,
  +                Parrot_psprintf(INTERP, PMC_str_val(SELF), ar));
  +    }
  +
  +/*
  +
   =item C<void set_pmc(PMC *value)>
   
   Sets the PMC C<*value>, calling the appropriate C<set_*> method
  
  
  
  1.11      +5 -2      parrot/languages/python/t/basic/oo_attr.t
  
  Index: oo_attr.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/t/basic/oo_attr.t,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- oo_attr.t 7 Dec 2004 15:46:28 -0000       1.10
  +++ oo_attr.t 10 Dec 2004 03:35:07 -0000      1.11
  @@ -1,4 +1,4 @@
  -# $Id: oo_attr.t,v 1.10 2004/12/07 15:46:28 rubys Exp $
  +# $Id: oo_attr.t,v 1.11 2004/12/10 03:35:07 rubys Exp $
   
   use strict;
   use lib '../../lib';
  @@ -33,7 +33,10 @@
       print x
   if __name__ == '__main__':
       print "a".__repr__()
  -    print dict.fromkeys("abc")
  +    d = dict.fromkeys("abc")
  +    del d['a']
  +    del d['c']
  +    print d
       it = iter("abcde")
       print it.next()
       print f("Ok")
  
  
  

Reply via email to