cvsuser 04/12/21 09:37:43
Modified: . MANIFEST
classes nci.pmc
config/gen/makefiles dynclasses.in
dynclasses pybuiltin.pmc
t/dynclass pybuiltin.t
Log:
Refactor Python specific logic into a separate subclass.
Revision Changes Path
1.809 +1 -0 parrot/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.808
retrieving revision 1.809
diff -u -r1.808 -r1.809
--- MANIFEST 18 Dec 2004 03:51:44 -0000 1.808
+++ MANIFEST 21 Dec 2004 17:37:38 -0000 1.809
@@ -376,6 +376,7 @@
dynclasses/pylist.pmc [devel]
dynclasses/pylong.pmc [devel]
dynclasses/pymodule.pmc [devel]
+dynclasses/pynci.pmc [devel]
dynclasses/pynone.pmc [devel]
dynclasses/pyobject.pmc [devel]
dynclasses/pyproxyclass.pmc [devel]
1.30 +2 -26 parrot/classes/nci.pmc
Index: nci.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/nci.pmc,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- nci.pmc 21 Dec 2004 11:51:56 -0000 1.29
+++ nci.pmc 21 Dec 2004 17:37:39 -0000 1.30
@@ -1,10 +1,10 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: nci.pmc,v 1.29 2004/12/21 11:51:56 rubys Exp $
+$Id: nci.pmc,v 1.30 2004/12/21 17:37:39 rubys Exp $
=head1 NAME
-classes/nci.pmc - Naitive Call Interface
+classes/nci.pmc - Native Call Interface
=head1 DESCRIPTION
@@ -151,30 +151,6 @@
return(0 != (INTVAL)PMC_data(SELF));
}
-/*
-
-=item C<PMC* get_attr_str(STRING *name)>
-
-Return attribute named C<name>.
-
-=cut
-
-TODO: refactor into a separate subclass, and either modify Pmc2c.pm and
-enter_nci_method to directly build this subclass, or add code to morph
-NCI instances into the correct subclass later.
-
-The line of code in test case t/pie/b3 that motivates this is:
-
- print "using", cmp.__name__
-
-Where cmp may be a NCI subroutine.
-
-*/
-
- PMC* get_attr_str(STRING* idx) {
- return VTABLE_getprop(INTERP, SELF, idx);
- }
-
}
/*
1.18 +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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- dynclasses.in 18 Dec 2004 03:51:45 -0000 1.17
+++ dynclasses.in 21 Dec 2004 17:37:40 -0000 1.18
@@ -11,6 +11,7 @@
tcllist tclarray \
match matchrange \
pybuiltin \
+pynci \
pyclass \
pyobject \
pyboolean \
1.29 +19 -4 parrot/dynclasses/pybuiltin.pmc
Index: pybuiltin.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pybuiltin.pmc,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- pybuiltin.pmc 21 Dec 2004 00:09:29 -0000 1.28
+++ pybuiltin.pmc 21 Dec 2004 17:37:41 -0000 1.29
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pybuiltin.pmc,v 1.28 2004/12/21 00:09:29 rubys Exp $
+$Id: pybuiltin.pmc,v 1.29 2004/12/21 17:37:41 rubys Exp $
=head1 NAME
@@ -30,6 +30,7 @@
static INTVAL dynclass_PyFloat;
static INTVAL dynclass_PyList;
static INTVAL dynclass_PyLong;
+static INTVAL dynclass_PyNCI;
static INTVAL dynclass_PyNone;
static INTVAL dynclass_PyProxyType;
static INTVAL dynclass_PyString;
@@ -70,6 +71,14 @@
for (j = 0; j < n; ++j) {
key = VTABLE_shift_string(interpreter, iter);
item = VTABLE_get_pmc_keyed_str(interpreter, stash, key);
+
+ if (item->vtable->base_type == enum_class_NCI) {
+ PMC *nameprop = pmc_new(interpreter, dynclass_PyString);
+ VTABLE_set_string_native(interpreter, nameprop, key);
+ VTABLE_setprop(interpreter, item, NAME, nameprop);
+ item->vtable = Parrot_base_vtables[dynclass_PyNCI];
+ }
+
VTABLE_add_method(interpreter, type, key, item);
}
@@ -102,6 +111,7 @@
dynclass_PyFloat = Parrot_PMC_typenum(INTERP, "PyFloat");
dynclass_PyList = Parrot_PMC_typenum(INTERP, "PyList");
dynclass_PyLong = Parrot_PMC_typenum(INTERP, "PyLong");
+ dynclass_PyNCI = Parrot_PMC_typenum(INTERP, "PyNCI");
dynclass_PyNone = Parrot_PMC_typenum(INTERP, "PyNone");
dynclass_PyProxyType = Parrot_PMC_typenum(INTERP, "PyProxyType");
dynclass_PyString = Parrot_PMC_typenum(INTERP, "PyString");
@@ -160,11 +170,16 @@
iter = Parrot_Hash_get_iter(INTERP, stash);
n = VTABLE_elements(INTERP, stash);
for (j = 0; j < n; ++j) {
- PMC *nameprop = pmc_new(interpreter, dynclass_PyString);
key = VTABLE_shift_string(INTERP, iter);
item = VTABLE_get_pmc_keyed_str(INTERP, stash, key);
- VTABLE_set_string_native(interpreter, nameprop, key);
- VTABLE_setprop(interpreter, item, NAME, nameprop);
+
+ if (item->vtable->base_type == enum_class_NCI) {
+ PMC *nameprop = pmc_new(interpreter, dynclass_PyString);
+ VTABLE_set_string_native(interpreter, nameprop, key);
+ VTABLE_setprop(interpreter, item, NAME, nameprop);
+ item->vtable = Parrot_base_vtables[dynclass_PyNCI];
+ }
+
scratchpad_store_by_name(INTERP, pad, 0, key, item);
}
1.8 +17 -2 parrot/t/dynclass/pybuiltin.t
Index: pybuiltin.t
===================================================================
RCS file: /cvs/public/parrot/t/dynclass/pybuiltin.t,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- pybuiltin.t 16 Dec 2004 10:37:17 -0000 1.7
+++ pybuiltin.t 21 Dec 2004 17:37:42 -0000 1.8
@@ -1,6 +1,6 @@
#! perl -w
# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-# $Id: pybuiltin.t,v 1.7 2004/12/16 10:37:17 leo Exp $
+# $Id: pybuiltin.t,v 1.8 2004/12/21 17:37:42 rubys Exp $
=head1 NAME
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 5;
+use Parrot::Test tests => 6;
use Parrot::Config;
pir_output_is(<< 'CODE', << 'OUTPUT', "autoload");
@@ -192,3 +192,18 @@
CODE
False True
OUTPUT
+
+output_is(<< 'CODE', << 'OUTPUT', "boolean");
+##PIR##
+.sub main @MAIN
+ new_pad 0
+ loadlib $P0, "python_group"
+
+ find_lex $P1, "cmp"
+ getattribute $P2, $P1, '__name__'
+ print $P2
+ print "\n"
+.end
+CODE
+cmp
+OUTPUT