cvsuser     05/01/04 09:45:18

  Modified:    dynclasses pybuiltin.pmc pyclass.pmc pyconsts.h pyfunc.pmc
                        pystring.pmc
  Log:
  Implement bound methods (more prep for t/pie/b0.t)
  
  Revision  Changes    Path
  1.41      +5 -3      parrot/dynclasses/pybuiltin.pmc
  
  Index: pybuiltin.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pybuiltin.pmc,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- pybuiltin.pmc     3 Jan 2005 16:16:02 -0000       1.40
  +++ pybuiltin.pmc     4 Jan 2005 17:45:18 -0000       1.41
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pybuiltin.pmc,v 1.40 2005/01/03 16:16:02 rubys Exp $
  +$Id: pybuiltin.pmc,v 1.41 2005/01/04 17:45:18 rubys Exp $
   
   =head1 NAME
   
  @@ -83,6 +83,7 @@
       void class_init() {
           if (pass) {
               PyBuiltin_PyBoolean    = Parrot_PMC_typenum(INTERP, "PyBoolean");
  +            PyBuiltin_PyBoundMeth  = Parrot_PMC_typenum(INTERP, 
"PyBoundMeth");
               PyBuiltin_PyClass      = Parrot_PMC_typenum(INTERP, "PyClass");
               PyBuiltin_PyComplex    = Parrot_PMC_typenum(INTERP, "PyComplex");
               PyBuiltin_PyDict       = Parrot_PMC_typenum(INTERP, "PyDict");
  @@ -105,12 +106,13 @@
               PyBuiltin_PyType       = Parrot_PMC_typenum(INTERP, "PyType");
   
               PyString_bases = const_string(INTERP, "__bases__");
  -            PyString_class = const_string(INTERP, "__class__");
               PyString_call  = const_string(INTERP, "__call__");
  +            PyString_class = const_string(INTERP, "__class__");
               PyString_cmp   = const_string(INTERP, "__cmp__");
               PyString_dict  = const_string(INTERP, "__dict__");
  -            PyString_hex   = const_string(INTERP, "__hex__");
  +            PyString_get   = const_string(INTERP, "__get__");
               PyString_hash  = const_string(INTERP, "__hash__");
  +            PyString_hex   = const_string(INTERP, "__hex__");
               PyString_init  = const_string(INTERP, "__init__");
               PyString_int   = const_string(INTERP, "__int__");
               PyString_iter  = const_string(INTERP, "__iter__");
  
  
  
  1.21      +9 -2      parrot/dynclasses/pyclass.pmc
  
  Index: pyclass.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyclass.pmc,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- pyclass.pmc       3 Jan 2005 00:20:08 -0000       1.20
  +++ pyclass.pmc       4 Jan 2005 17:45:18 -0000       1.21
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyclass.pmc,v 1.20 2005/01/03 00:20:08 rubys Exp $
  +$Id: pyclass.pmc,v 1.21 2005/01/04 17:45:18 rubys Exp $
   
   =head1 NAME
   
  @@ -161,7 +161,7 @@
   */
   
       PMC* get_attr_str(STRING* idx) {
  -        PMC *class;
  +        PMC *class, *get;
   
           PMC *attr = VTABLE_getprop(INTERP, SELF, idx);
           if (attr && VTABLE_defined(INTERP, attr)) return attr;
  @@ -179,6 +179,13 @@
                   string_to_cstring(INTERP, message));
           }
   
  +        /* is the attribute a Property? */
  +        get = VTABLE_find_method(INTERP, attr, PyString_get);
  +        if (get) {
  +            attr = Parrot_PyClass_run_meth_fromc_P_P(INTERP, get, attr,
  +                PyString_get, SELF);
  +        }
  +
           return attr;
       }
   
  
  
  
  1.8       +2 -0      parrot/dynclasses/pyconsts.h
  
  Index: pyconsts.h
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyconsts.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- pyconsts.h        3 Jan 2005 16:16:02 -0000       1.7
  +++ pyconsts.h        4 Jan 2005 17:45:18 -0000       1.8
  @@ -7,6 +7,7 @@
   /* Python class types */
   
   PYVAR_SCOPE INTVAL PyBuiltin_PyBoolean;
  +PYVAR_SCOPE INTVAL PyBuiltin_PyBoundMeth;
   PYVAR_SCOPE INTVAL PyBuiltin_PyClass;
   PYVAR_SCOPE INTVAL PyBuiltin_PyComplex;
   PYVAR_SCOPE INTVAL PyBuiltin_PyDict;
  @@ -51,6 +52,7 @@
   PYVAR_SCOPE STRING *PyString_class;
   PYVAR_SCOPE STRING *PyString_cmp;
   PYVAR_SCOPE STRING *PyString_dict;
  +PYVAR_SCOPE STRING *PyString_get;
   PYVAR_SCOPE STRING *PyString_hex;
   PYVAR_SCOPE STRING *PyString_hash;
   PYVAR_SCOPE STRING *PyString_init;
  
  
  
  1.11      +19 -2     parrot/dynclasses/pyfunc.pmc
  
  Index: pyfunc.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyfunc.pmc,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- pyfunc.pmc        23 Dec 2004 23:49:32 -0000      1.10
  +++ pyfunc.pmc        4 Jan 2005 17:45:18 -0000       1.11
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyfunc.pmc,v 1.10 2004/12/23 23:49:32 rubys Exp $
  +$Id: pyfunc.pmc,v 1.11 2005/01/04 17:45:18 rubys Exp $
   
   =head1 NAME
   
  @@ -68,7 +68,7 @@
   
   =item C<PMC *find_method(STRING *method_name)>
   
  -Impliement __call__ methods by redirecting to one's self, after having
  +Implement __call__ methods by redirecting to one's self, after having
   resolved all of the parameters into a single positional list.  Note:
   at this time, functions with a maximum of 11 arguments are supported.
   
  @@ -261,6 +261,23 @@
   
   /*
   
  +=item C<void "__get__"()>
  +
  +Return a bound method object.
  +
  +=cut
  +
  +*/
  +
  +    METHOD PMC* __get__ (PMC *self, PMC *obj) {
  +        PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoundMeth);
  +        VTABLE_set_pointer(INTERP, ret, self);
  +        VTABLE_set_pmc(INTERP, ret, obj);
  +        return ret;
  +    }
  +
  +/*
  +
   =back
   
   =cut
  
  
  
  1.17      +36 -15    parrot/dynclasses/pystring.pmc
  
  Index: pystring.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pystring.pmc,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- pystring.pmc      3 Jan 2005 16:16:02 -0000       1.16
  +++ pystring.pmc      4 Jan 2005 17:45:18 -0000       1.17
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pystring.pmc,v 1.16 2005/01/03 16:16:02 rubys Exp $
  +$Id: pystring.pmc,v 1.17 2005/01/04 17:45:18 rubys Exp $
   
   =head1 NAME
   
  @@ -363,7 +363,7 @@
   
   /*
   
  -=item C<PMC* "isalpha"()>
  +=item C<PMC* "isalpha"(PMC *self)>
   
   Return True if all characters in S are alphabetic and there is at least one
   character in S, False otherwise.
  @@ -372,8 +372,8 @@
   
   */
   
  -    METHOD PMC* isalpha () {
  -        STRING *s = PMC_str_val(SELF);
  +    METHOD PMC* isalpha (PMC *self) {
  +        STRING *s = PMC_str_val(self);
           UINTVAL length = string_length(INTERP, s);
           UINTVAL idx ;
           PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
  @@ -402,8 +402,8 @@
   
   */
   
  -    METHOD PMC* isalnum () {
  -        STRING *s = PMC_str_val(SELF);
  +    METHOD PMC* isalnum (PMC *self) {
  +        STRING *s = PMC_str_val(self);
           UINTVAL length = string_length(INTERP, s);
           UINTVAL idx ;
           PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
  @@ -423,7 +423,7 @@
   
   /*
   
  -=item C<PMC* "isdigit"()>
  +=item C<PMC* "isdigit"(PMC *self)>
   
   Return True if all characters in S are numeric and there is at
   least one character in S, False otherwise.
  @@ -432,8 +432,8 @@
   
   */
   
  -    METHOD PMC* isdigit () {
  -        STRING *s = PMC_str_val(SELF);
  +    METHOD PMC* isdigit (PMC *self) {
  +        STRING *s = PMC_str_val(self);
           UINTVAL length = string_length(INTERP, s);
           UINTVAL idx ;
           PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
  @@ -453,7 +453,7 @@
   
   /*
   
  -=item C<PMC* "isspace"()>
  +=item C<PMC* "isspace"(PMC *self)>
   
   Return True if all characters in S are whitespace and there is at least one
   character in S, False otherwise.
  @@ -462,8 +462,8 @@
   
   */
   
  -    METHOD PMC* isspace () {
  -        STRING *s = PMC_str_val(SELF);
  +    METHOD PMC* isspace (PMC *self) {
  +        STRING *s = PMC_str_val(self);
           UINTVAL length = string_length(INTERP, s);
           UINTVAL idx ;
           PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
  @@ -483,7 +483,7 @@
   
   /*
   
  -=item C<PMC* "lower"()>
  +=item C<PMC* "lower"(PMC *self)>
   
   downcase this string
   
  @@ -491,8 +491,8 @@
   
   */
   
  -    METHOD PMC* lower() {
  -        STRING *s = string_downcase(INTERP, PMC_str_val(SELF));
  +    METHOD PMC* lower(PMC *self) {
  +        STRING *s = string_downcase(INTERP, PMC_str_val(self));
           PMC *ret = pmc_new(INTERP, PyBuiltin_PyString);
           VTABLE_set_string_native(INTERP, ret, s);
           return ret;
  @@ -500,6 +500,27 @@
   
   /*
   
  +=item C<PMC* "find"(PMC *haystack, PMC *needle)>
  +
  +downcase this string
  +
  +=cut
  +
  +*/
  +
  +    METHOD PMC* find(PMC *haystack, PMC *needle, PMC *start) {
  +        INTVAL istart = 0;
  +        INTVAL pos;
  +        if (REG_INT(3) > 2) istart = VTABLE_get_integer(INTERP, start);
  +        pos = string_str_index(INTERP, VTABLE_get_string(INTERP, haystack),
  +            VTABLE_get_string(INTERP, needle), istart);
  +        PMC *ret = pmc_new(INTERP, PyBuiltin_PyInt);
  +        VTABLE_set_integer_native(INTERP, ret, pos);
  +        return ret;
  +    }
  +
  +/*
  +
   =item C<void modulus(PMC *value, PMC *dest)>
   
   Interpolates a formatstring with a set of values.
  
  
  

Reply via email to