cvsuser     05/01/20 08:24:36

  Modified:    dynclasses pyboundmeth.pmc pybuiltin.pmc pyproxyclass.pmc
  Log:
  Precursor to unbound, class, and static method support
  
  Revision  Changes    Path
  1.4       +19 -11    parrot/dynclasses/pyboundmeth.pmc
  
  Index: pyboundmeth.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyboundmeth.pmc,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- pyboundmeth.pmc   10 Jan 2005 19:58:12 -0000      1.3
  +++ pyboundmeth.pmc   20 Jan 2005 16:24:35 -0000      1.4
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyboundmeth.pmc,v 1.3 2005/01/10 19:58:12 rubys Exp $
  +$Id: pyboundmeth.pmc,v 1.4 2005/01/20 16:24:35 rubys Exp $
   
   =head1 NAME
   
  @@ -73,13 +73,19 @@
           if (ret && VTABLE_defined(INTERP, ret))
               name = VTABLE_get_string(INTERP, ret);
   
  -        res = string_from_cstring(INTERP, "<bound method ", 0);
  -        res = string_append(INTERP, res, name, 0);
  -        res = string_append(INTERP, res, const_string(INTERP, " of "), 0);
  -        res = string_append(INTERP, res,
  -             VTABLE_get_string(INTERP, PMC_pmc_val(SELF)), 0);
  -        res = string_append(INTERP, res, const_string(INTERP, ">"), 0);
  +        if (PMC_struct_val(SELF)) {
  +            res = string_from_cstring(INTERP, "<bound method ", 0);
  +            res = string_append(INTERP, res, name, 0);
  +            res = string_append(INTERP, res, const_string(INTERP, " of "), 
0);
  +            res = string_append(INTERP, res,
  +                 VTABLE_get_string(INTERP, (PMC*)PMC_struct_val(SELF)), 0);
  +        }
  +        else {
  +            res = string_from_cstring(INTERP, "<unbound method ", 0);
  +            res = string_append(INTERP, res, name, 0);
  +        }
   
  +        res = string_append(INTERP, res, const_string(INTERP, ">"), 0);
           return res;
       }
   
  @@ -95,10 +101,12 @@
   */
   
       void* invoke(void* next) {
  -        int i = REG_INT(3)++;
  -        while (i--)
  -            REG_PMC(6+i)=REG_PMC(5+i);
  -        REG_PMC(5) = PMC_struct_val(SELF); 
  +        if (PMC_struct_val(SELF)) {
  +            int i = REG_INT(3)++;
  +            while (i--)
  +                REG_PMC(6+i)=REG_PMC(5+i);
  +            REG_PMC(5) = PMC_struct_val(SELF); 
  +        }
           return VTABLE_invoke(INTERP, PMC_pmc_val(SELF), next);
       }
   
  
  
  
  1.49      +28 -50    parrot/dynclasses/pybuiltin.pmc
  
  Index: pybuiltin.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pybuiltin.pmc,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- pybuiltin.pmc     12 Jan 2005 15:01:20 -0000      1.48
  +++ pybuiltin.pmc     20 Jan 2005 16:24:35 -0000      1.49
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pybuiltin.pmc,v 1.48 2005/01/12 15:01:20 rubys Exp $
  +$Id: pybuiltin.pmc,v 1.49 2005/01/20 16:24:35 rubys Exp $
   
   =head1 NAME
   
  @@ -34,7 +34,10 @@
       return lib_pmc;
   }
   
  -static PMC* make_type(Interp* interpreter, INTVAL class, STRING* name) {
  +static PMC* 
  +make_type(Interp* interpreter, INTVAL class, STRING* name, 
  +          PMC *parent, PMC *pad)
  +{
       STRING *pmcname = Parrot_base_vtables[class]->whoami;
       PMC *type = pmc_new(interpreter, PyBuiltin_PyProxyType);
       PMC *stash, *iter, *item, *nameprop;
  @@ -64,6 +67,10 @@
       nameprop = pmc_new(interpreter, PyBuiltin_PyString);
       VTABLE_set_string_native(interpreter, nameprop, name);
       VTABLE_setprop(interpreter, type, PyString_name, nameprop);
  +    if (parent)
  +        VTABLE_setprop(interpreter, type, PyString_bases, parent);
  +    if (pad)
  +        scratchpad_store_by_name(interpreter, pad, 0, name, type);
   
       return type;
   }
  @@ -229,103 +236,74 @@
   
           /* Class objects */
           key = const_string(INTERP, "object");
  -        item = make_type(INTERP, PyBuiltin_PyClass, key);
  +        item = make_type(INTERP, PyBuiltin_PyClass, key, NULL, pad);
           item->vtable = Parrot_base_vtables[PyBuiltin_PyType];
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        Parrot_base_vtables[PyBuiltin_PyType]->data = item;
   
  -        parent = make_type(INTERP, PyBuiltin_PyObject, key);
  +        parent = make_type(INTERP, PyBuiltin_PyObject, key, NULL, NULL);
           parent->vtable = Parrot_base_vtables[PyBuiltin_PyProxyType];
           PyBuiltin_PyProxyClass_class = parent;
   
           key = const_string(INTERP, "bool");
  -        item = make_type(INTERP, PyBuiltin_PyBoolean, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyBoolean, key, parent, pad);
           PyBuiltin_PyBoolean_class = item;
   
           key = const_string(INTERP, "complex");
  -        item = make_type(INTERP, PyBuiltin_PyComplex, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyComplex, key, parent, pad);
           PyBuiltin_PyComplex_class = item;
   
           key = const_string(INTERP, "dict");
  -        item = make_type(INTERP, PyBuiltin_PyDict, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyDict, key, parent, pad);
           PyBuiltin_PyDict_class = item;
   
           key = const_string(INTERP, "Exception");
  -        item = make_type(INTERP, PyBuiltin_PyException, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyException, key, parent, pad);
           PyBuiltin_PyException_class = item;
   
           key = const_string(INTERP, "int");
  -        item = make_type(INTERP, PyBuiltin_PyInt, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyInt, key, parent, pad);
           PyBuiltin_PyInt_class = item;
   
           key = const_string(INTERP, "iter");
  -        item = make_type(INTERP, PyBuiltin_PyIter, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyIter, key, parent, pad);
           PyBuiltin_PyIter_class = item;
   
           key = const_string(INTERP, "float");
  -        item = make_type(INTERP, PyBuiltin_PyFloat, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyFloat, key, parent, pad);
           PyBuiltin_PyFloat_class = item;
   
           key = const_string(INTERP, "function");
  -        item = make_type(INTERP, PyBuiltin_PyFunc, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  +        item = make_type(INTERP, PyBuiltin_PyFunc, key, parent, pad);
           PyBuiltin_PyFunc_class = item;
   
           key = const_string(INTERP, "list");
  -        item = make_type(INTERP, PyBuiltin_PyList, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyList, key, parent, pad);
           PyBuiltin_PyList_class = item;
   
           key = const_string(INTERP, "long");
  -        item = make_type(INTERP, PyBuiltin_PyLong, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyLong, key, parent, pad);
           PyBuiltin_PyLong_class = item;
   
           key = const_string(INTERP, "tuple");
  -        item = make_type(INTERP, PyBuiltin_PyTuple, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyTuple, key, parent, pad);
           PyBuiltin_PyTuple_class = item;
   
           key = const_string(INTERP, "type");
  -        item = make_type(INTERP, PyBuiltin_PyType, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyType, key, parent, pad);
           PyBuiltin_PyType_class = item;
           item->vtable = Parrot_base_vtables[PyBuiltin_PyType];
   
           key = const_string(INTERP, "staticmethod");
  -        item = make_type(INTERP, PyBuiltin_PyStaticMeth, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyStaticMeth, key, parent, pad);
           PyBuiltin_PyStaticMeth_class = item;
   
           key = const_string(INTERP, "str");
  -        item = make_type(INTERP, PyBuiltin_PyString, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  +        item = make_type(INTERP, PyBuiltin_PyString, key, parent, pad);
           PyBuiltin_PyString_class = item;
   
           key = const_string(INTERP, "xrange");
  -        item = make_type(INTERP, PyBuiltin_PySlice, key);
  -        VTABLE_setprop(INTERP, item, PyString_bases, parent);
  -        scratchpad_store_by_name(INTERP, pad, 0, key, item);
  -        PyBuiltin_PySlice_class = item;
  +        PyBuiltin_PySlice_class = 
  +            make_type(INTERP, PyBuiltin_PySlice, key, parent, pad);
   
           /* Begin main! */
           item = pmc_new(INTERP, PyBuiltin_PyString);
  
  
  
  1.10      +5 -3      parrot/dynclasses/pyproxyclass.pmc
  
  Index: pyproxyclass.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyproxyclass.pmc,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- pyproxyclass.pmc  12 Jan 2005 14:40:18 -0000      1.9
  +++ pyproxyclass.pmc  20 Jan 2005 16:24:35 -0000      1.10
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyproxyclass.pmc,v 1.9 2005/01/12 14:40:18 rubys Exp $
  +$Id: pyproxyclass.pmc,v 1.10 2005/01/20 16:24:35 rubys Exp $
   
   =head1 NAME
   
  @@ -44,8 +44,10 @@
                   internal_exception(1, "Non-bound method encountered in 
proxy");
               else {
                   PMC *proxy = INTERP->ctx.current_object;
  -                VTABLE_set_pmc(INTERP, method,
  -                    VTABLE_getprop(INTERP, proxy, PyString_proxy));
  +                if (proxy) {
  +                    VTABLE_set_pmc(INTERP, method,
  +                        VTABLE_getprop(INTERP, proxy, PyString_proxy));
  +                }
               }
           }
   
  
  
  

Reply via email to