cvsuser 05/01/04 12:46:07
Modified: . MANIFEST
config/gen/makefiles dynclasses.in
dynclasses pybuiltin.pmc pyproxyclass.pmc
Added: dynclasses pyboundmeth.pmc
Log:
Actually commit pyboundmeth.pmc this time (oops!), and some minor
fixes/additions.
Revision Changes Path
1.817 +1 -0 parrot/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.816
retrieving revision 1.817
diff -u -r1.816 -r1.817
--- MANIFEST 3 Jan 2005 00:20:07 -0000 1.816
+++ MANIFEST 4 Jan 2005 20:46:05 -0000 1.817
@@ -363,6 +363,7 @@
dynclasses/match.pmc [devel]
dynclasses/matchrange.pmc [devel]
dynclasses/pyboolean.pmc [devel]
+dynclasses/pyboundmeth.pmc [devel]
dynclasses/pybuiltin.pmc [devel]
dynclasses/pycomplex.pmc [devel]
dynclasses/pyconsts.h [devel]
1.22 +1 -0 parrot/config/gen/makefiles/dynclasses.in
Index: dynclasses.in
===================================================================
RCS file: /cvs/public/parrot/config/gen/makefiles/dynclasses.in,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- dynclasses.in 30 Dec 2004 13:07:22 -0000 1.21
+++ dynclasses.in 4 Jan 2005 20:46:06 -0000 1.22
@@ -15,6 +15,7 @@
pyclass \
pyobject \
pyboolean \
+ pyboundmeth \
pycomplex \
pydict \
pyexception \
1.42 +32 -3 parrot/dynclasses/pybuiltin.pmc
Index: pybuiltin.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pybuiltin.pmc,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- pybuiltin.pmc 4 Jan 2005 17:45:18 -0000 1.41
+++ pybuiltin.pmc 4 Jan 2005 20:46:07 -0000 1.42
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pybuiltin.pmc,v 1.41 2005/01/04 17:45:18 rubys Exp $
+$Id: pybuiltin.pmc,v 1.42 2005/01/04 20:46:07 rubys Exp $
=head1 NAME
@@ -517,13 +517,13 @@
*/
- METHOD PMC* hasattr(PMC *object, PMC *value) {
+ METHOD PMC* hasattr(PMC *object, PMC *name) {
PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
new_internal_exception(INTERP);
push_new_c_exception_handler(INTERP, INTERP->exceptions);
if (!setjmp(INTERP->exceptions->destination)) {
VTABLE_get_attr_str(INTERP, object,
- VTABLE_get_string(INTERP, value));
+ VTABLE_get_string(INTERP, name));
VTABLE_set_integer_native(INTERP, ret, 1);
} else {
Parrot_exception *exception = INTERP->exceptions;
@@ -537,6 +537,35 @@
/*
+=item C<PMC* "getattr"(PMC *object, PMC *name)>
+
+Get the attribute with the given name.
+
+=cut
+
+*/
+
+ METHOD PMC* getattr(PMC *object, PMC *name) {
+ return VTABLE_get_attr_str(INTERP, object,
+ VTABLE_get_string(INTERP, name));
+ }
+
+/*
+
+=item C<PMC* "setattr"(PMC *object, PMC *name, PMC *value)>
+
+Sets the attribute with the given name.
+
+=cut
+
+*/
+
+ METHOD void setattr(PMC *object, PMC *name, PMC *value) {
+ VTABLE_setprop(INTERP, object, VTABLE_get_string(INTERP, name),
value);
+ }
+
+/*
+
=item C<PMC* "hex"(PMC *value)>
Returns the hex representation of C<value>.
1.8 +17 -2 parrot/dynclasses/pyproxyclass.pmc
Index: pyproxyclass.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pyproxyclass.pmc,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- pyproxyclass.pmc 23 Dec 2004 23:49:33 -0000 1.7
+++ pyproxyclass.pmc 4 Jan 2005 20:46:07 -0000 1.8
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pyproxyclass.pmc,v 1.7 2004/12/23 23:49:33 rubys Exp $
+$Id: pyproxyclass.pmc,v 1.8 2005/01/04 20:46:07 rubys Exp $
=head1 NAME
@@ -37,12 +37,27 @@
*/
void init () {
- PMC_pmc_val(SELF) = 0;
+ PObj_custom_mark_SET(SELF);
PMC_struct_val(SELF) = 0;
}
/*
+=item C<void mark()>
+
+Marks the hash as live.
+
+=cut
+
+*/
+
+ void mark () {
+ if (PMC_struct_val(SELF)) /* forwarder */
+ pobject_lives(INTERP, (PObj *) PMC_struct_val(SELF));
+ }
+
+/*
+
=item C<PMC *find_method(STRING *method_name)>
Looks up the method for C<*method_name> and returns it.
1.1 parrot/dynclasses/pyboundmeth.pmc
Index: pyboundmeth.pmc
===================================================================
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
$Id: pyboundmeth.pmc,v 1.1 2005/01/04 20:46:07 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"
#include "pyconsts.h"
pmclass PyBoundMeth dynpmc group python_group {
/*
=item C<void init()>
Initializes the key.
=cut
*/
void init () {
PObj_custom_mark_SET(SELF);
PMC_struct_val(SELF) = NULL;
PMC_pmc_val(SELF) = SELF;
}
/*
=item C<void mark()>
Marks the hash as live.
=cut
*/
void mark () {
if (PMC_struct_val(SELF)) /* bound object */
pobject_lives(INTERP, (PObj *) PMC_struct_val(SELF));
if (PMC_pmc_val(SELF)) /* real sub */
pobject_lives(INTERP, (PObj *) PMC_pmc_val(SELF));
}
/*
=item C<PMC *find_method(STRING *method_name)>
Find a method call on the indicated object.
=cut
*/
PMC* find_method(STRING* method_name) {
if (0 == string_compare(INTERP, method_name, PyString_call)) {
int i = REG_INT(3)++;
while (i--)
REG_PMC(6+i)=REG_PMC(5+i);
REG_PMC(5) = PMC_struct_val(SELF);
}
return VTABLE_find_method(INTERP, PMC_pmc_val(SELF), method_name);
}
/*
=item C<PMC* get_attr_str(STRING *name)>
Return attribute named C<name>.
=cut
*/
PMC* get_attr_str(STRING* idx) {
return VTABLE_get_attr_str(INTERP, PMC_pmc_val(SELF), idx);
}
/*
=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, PMC_pmc_val(SELF), PyString_name);
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);
return res;
}
/*
=item C<void* invoke(void* next)>
Invoke a method call on the indicated object.
=cut
*/
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);
return VTABLE_invoke(INTERP, PMC_pmc_val(SELF), next);
}
/*
=item C<void set_pointer(void *value)>
Sets the pointer to the actual subroutine.
=cut
*/
void set_pointer (void* value) {
PMC_pmc_val(SELF) = value;
}
/*
=item C<void set_pmc(PMC *value)>
Sets the pointer to the "bound" object.
=cut
*/
void set_pmc (PMC* value) {
PMC_struct_val(SELF) = value;
}
}
/*
=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:
*/