cvsuser     04/12/21 11:13:37

  Modified:    dynclasses pyfunc.pmc
  Added:       dynclasses pynci.pmc
  Log:
  Commit pynci (oops!), and make it easy to set the function name.
  
  Revision  Changes    Path
  1.9       +49 -1     parrot/dynclasses/pyfunc.pmc
  
  Index: pyfunc.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pyfunc.pmc,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- pyfunc.pmc        20 Dec 2004 22:27:12 -0000      1.8
  +++ pyfunc.pmc        21 Dec 2004 19:13:37 -0000      1.9
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pyfunc.pmc,v 1.8 2004/12/20 22:27:12 rubys Exp $
  +$Id: pyfunc.pmc,v 1.9 2004/12/21 19:13:37 rubys Exp $
   
   =head1 NAME
   
  @@ -22,10 +22,12 @@
   
   static INTVAL dynclass_PyList;
   static INTVAL dynclass_PyTuple;
  +static INTVAL dynclass_PyString;
   static STRING *FUNC_ARGS;
   static STRING *FUNC_DEFAULTS;
   static STRING *FUNC_VARARGS;
   static STRING *__CALL__;
  +static STRING *__NAME__;
   
   pmclass PyFunc extends Closure dynpmc group python_group {
   
  @@ -44,10 +46,12 @@
           if (pass) {
               dynclass_PyList = Parrot_PMC_typenum(INTERP, "PyList");
               dynclass_PyTuple = Parrot_PMC_typenum(INTERP, "PyTuple");
  +            dynclass_PyString = Parrot_PMC_typenum(INTERP, "PyString");
               FUNC_ARGS = const_string(INTERP, "func_args");
               FUNC_VARARGS = const_string(INTERP, "func_varargs");
               FUNC_DEFAULTS = const_string(INTERP, "func_defaults");
               __CALL__ = const_string(INTERP, "__call__");
  +            __NAME__ = const_string(INTERP, "__name__");
           }
       }
   
  @@ -144,6 +148,34 @@
   
   /*
   
  +=item C<STRING *get_string()>
  +
  +Return the representation of this object.
  +
  +=cut
  +
  +*/
  +
  +    STRING* get_string() {
  +        STRING *res;
  +
  +        STRING *name = const_string(INTERP, "(unnamed)");
  +        PMC *ret = VTABLE_getprop(INTERP, SELF, __NAME__);
  +        if (ret && VTABLE_defined(INTERP, ret))
  +            name = VTABLE_get_string(INTERP, ret);
  +
  +        res = string_from_cstring(INTERP, "<function ", 0);
  +        res = string_append(INTERP, res, name, 0);
  +        res = string_append(INTERP, res, const_string(INTERP, " at "), 0);
  +        res = string_append(INTERP, res,
  +            Parrot_sprintf_c(INTERP, "%#x", (INTVAL) SELF), 0);
  +        res = string_append(INTERP, res, const_string(INTERP, ">"), 0);
  +
  +        return res;
  +    }
  +
  +/*
  +
   =item C<void* invoke(void* next)>
   
   Invoke a function.  Defaults are filled in first.
  @@ -222,6 +254,22 @@
   
   /*
   
  +=item C<void set_string_native(STRING *value)>
  +
  +Set the function name.
  +
  +=cut
  +
  +*/
  +
  +    void set_string_native (STRING * value) {
  +        PMC *nameprop = pmc_new(INTERP, dynclass_PyString);
  +        VTABLE_set_string_native(INTERP, nameprop, value);
  +        VTABLE_setprop(INTERP, SELF, __NAME__, nameprop);
  +    }
  +
  +/*
  +
   =back
   
   =cut
  
  
  
  1.1                  parrot/dynclasses/pynci.pmc
  
  Index: pynci.pmc
  ===================================================================
  /*
  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  $Id: pynci.pmc,v 1.1 2004/12/21 19:13:37 rubys Exp $
  
  =head1 NAME
  
  classes/nci.pmc - Python Native Call Interface Functions
  
  =head1 DESCRIPTION
  
  Extends Parrot's NCI to include attributes, implemented as properties.
  
  =head2 Methods
  
  =over 4
  
  =cut
  
  */
  
  #include "parrot/parrot.h"
  
  pmclass PyNCI extends NCI dynpmc group python_group {
  
  /*
  
  =item C<PMC* get_attr_str(STRING *name)>
  
  Return attribute named C<name>.
  
  =cut
  
  */
  
      PMC* get_attr_str(STRING* idx) {
          return VTABLE_getprop(INTERP, SELF, idx);
      }
  
  }
  
  /*
  
  =back
  
  =head1 SEE ALSO
  
  F<docs/pdds/pdd03_calling_conventions.pod>.
  
  =head1 HISTORY
  
  Initial revision by sean 2002/08/04.
  
  =cut
  
  */
  
  /*
   * Local variables:
   * c-indentation-style: bsd
   * c-basic-offset: 4
   * indent-tabs-mode: nil
   * End:
   *
   * vim: expandtab shiftwidth=4:
  */
  
  
  

Reply via email to