cvsuser 04/07/23 06:26:35
Modified: classes default.pmc resizablepmcarray.pmc
languages/python/t/basic 03_types.t
languages/python/t/pie b3.t
src inter_run.c py_func.c
t/pmc pmc.t
Log:
Pie-thon 93 - 2 sortum() calls from b3.y are running
* when an overriden vtable like __get_repr returns a PMC
Parrot trusts now the return signature and exctracts
e.g. a STRING* from a PMC, if the signature wants a STRING.
* But no PMCs are created if the function returns a native type
and the signature wants a PMC.
Revision Changes Path
1.97 +1 -13 parrot/classes/default.pmc
Index: default.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/default.pmc,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -w -r1.96 -r1.97
--- default.pmc 19 Jul 2004 10:48:29 -0000 1.96
+++ default.pmc 23 Jul 2004 13:26:21 -0000 1.97
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: default.pmc,v 1.96 2004/07/19 10:48:29 nicholas Exp $
+$Id: default.pmc,v 1.97 2004/07/23 13:26:21 leo Exp $
=head1 NAME
@@ -343,18 +343,6 @@
STRING* name () {
return SELF->vtable->whoami;
}
-/*
-
-=item C<STRING* get_repr()>
-
-Fallback to get_string() - return pythonic textual representation of
-SELF.
-
-*/
-
- STRING* get_repr() {
- return DYNSELF.get_string();
- }
/*
1.12 +5 -3 parrot/classes/resizablepmcarray.pmc
Index: resizablepmcarray.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/resizablepmcarray.pmc,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -r1.11 -r1.12
--- resizablepmcarray.pmc 23 Jul 2004 11:46:10 -0000 1.11
+++ resizablepmcarray.pmc 23 Jul 2004 13:26:21 -0000 1.12
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: resizablepmcarray.pmc,v 1.11 2004/07/23 11:46:10 leo Exp $
+$Id: resizablepmcarray.pmc,v 1.12 2004/07/23 13:26:21 leo Exp $
=head1 NAME
@@ -219,9 +219,11 @@
res = string_from_cstring(INTERP, "[", 0);
n = VTABLE_elements(INTERP, SELF);
for (j = 0; j < n; ++j) {
+ STRING *vals;
val = SELF.get_pmc_keyed_int(j);
- res = string_append(INTERP, res,
- VTABLE_get_repr(INTERP, val), 0);
+ REG_INT(3) = 0;
+ vals = VTABLE_get_repr(INTERP, val);
+ res = string_append(INTERP, res, vals, 0);
if (j < n - 1)
res = string_append(INTERP, res,
const_string(INTERP, ", "), 0);
1.12 +19 -2 parrot/languages/python/t/basic/03_types.t
Index: 03_types.t
===================================================================
RCS file: /cvs/public/parrot/languages/python/t/basic/03_types.t,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -r1.11 -r1.12
--- 03_types.t 17 Jul 2004 11:33:21 -0000 1.11
+++ 03_types.t 23 Jul 2004 13:26:26 -0000 1.12
@@ -1,9 +1,9 @@
-# $Id: 03_types.t,v 1.11 2004/07/17 11:33:21 leo Exp $
+# $Id: 03_types.t,v 1.12 2004/07/23 13:26:26 leo Exp $
use strict;
use lib '../../lib';
-use Parrot::Test tests => 16;
+use Parrot::Test tests => 17;
sub test {
language_output_is('python', $_[0], '', $_[1]);
@@ -145,3 +145,20 @@
if __name__ == "__main__":
main()
CODE
+
+test(<<'CODE', 'repr of all');
+def main():
+ print "int", `1`
+ print "bool", `1==1`
+ print 'long', `1L`
+ print 'float', `1.2`
+ print 'str', `"ab"`
+ print 'unicode', `u"ab"`
+ print 'complex', `1+2j`
+ print 'list', `[1,2]`
+ print 'tuple', `(1,2)`
+ print 'dict', `{"a":1}`
+
+main()
+
+CODE
1.5 +106 -2 parrot/languages/python/t/pie/b3.t
Index: b3.t
===================================================================
RCS file: /cvs/public/parrot/languages/python/t/pie/b3.t,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- b3.t 23 Jul 2004 11:46:19 -0000 1.4
+++ b3.t 23 Jul 2004 13:26:29 -0000 1.5
@@ -1,9 +1,9 @@
-# $Id: b3.t,v 1.4 2004/07/23 11:46:19 leo Exp $
+# $Id: b3.t,v 1.5 2004/07/23 13:26:29 leo Exp $
use strict;
use lib '../../lib';
-use Parrot::Test tests => 6;
+use Parrot::Test tests => 8;
sub test {
language_output_is('python', $_[0], '', $_[1]);
@@ -140,3 +140,107 @@
main()
CODE
+test(<<'CODE', 'overriden rept in list');
+T = int
+
+class TT(T):
+ def __repr__(self):
+ return "T(%d)" % self
+
+class Int(TT):
+ def __new__(cls, value=None):
+ if value is None:
+ value = 42
+ return TT.__new__(cls, value)
+
+def main():
+ data = [ Int() for x in xrange(1)]
+ print data
+
+main()
+
+CODE
+
+test(<<'CODE', '2 sorts done');
+class Random:
+
+ def __init__(self, x, y, z):
+ self._seed = (x, y, z)
+
+ def random(self):
+ x, y, z = self._seed
+ x = (171 * x) % 30269
+ y = (172 * y) % 30307
+ z = (170 * z) % 30323
+ self._seed = x, y, z
+ return (x/30269.0 + y/30307.0 + z/30323.0) % 1.0
+
+ def uniform(self, a, b):
+ return a + (b-a) * self.random()
+
+ def randint(self, a, b):
+ return a + int((b+1-a) * self.random())
+
+ def choice(self, seq):
+ return seq[int(self.random() * len(seq))]
+
+rgen = Random(57, 86, 708 % 650)
+
+compares = 0
+
+T = int
+
+class TT(T):
+ def __repr__(self):
+ return "T(%d)" % self
+
+class Int(TT):
+ def __new__(cls, value=None):
+ if value is None:
+ value = rgen.randint(0, 0x7ffffffe)
+ return TT.__new__(cls, value)
+
+def icmp(a, b):
+ global compares
+ compares += 1
+ return T.__cmp__(a, b)
+
+N = 20000
+K = 1
+
+##if __debug__: import time
+
+def sortum(data, cmp=None):
+ global compares
+ compares = 0
+ data = data[:]
+ ##if __debug__: t0 = time.time()
+ if cmp is None:
+ print "using None"
+ data.sort()
+ else:
+ print "using", cmp.__name__
+ data.sort(cmp)
+ ##if __debug__: t1 = time.time()
+ print "Z", data[:K], data[N//2:N//2+K], data[-K:]
+ print compares,
+ ##if __debug__: print "%.3f" % (t1-t0),
+ print
+
+def main():
+ ##if __debug__: t0 = time.time()
+ data = [Int() for x in xrange(N)]
+ ##if __debug__: t1 = time.time()
+ ##if __debug__: print "%.3f" % (t1-t0)
+ print "A", data[:K], data[N//2:N//2+K], data[-K:]
+ sortum(data)
+ sortum(data, cmp)
+ # sortum(data, icmp)
+ # TT.__cmp__ = icmp
+ # sortum(data)
+ # TT.__cmp__ = T.__cmp__
+ # sortum(data)
+
+if __name__ == '__main__':
+ main()
+CODE
1.6 +14 -1 parrot/src/inter_run.c
Index: inter_run.c
===================================================================
RCS file: /cvs/public/parrot/src/inter_run.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -r1.5 -r1.6
--- inter_run.c 22 Jul 2004 04:31:16 -0000 1.5
+++ inter_run.c 23 Jul 2004 13:26:32 -0000 1.6
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: inter_run.c,v 1.5 2004/07/22 04:31:16 leo Exp $
+$Id: inter_run.c,v 1.6 2004/07/23 13:26:32 leo Exp $
=head1 NAME
@@ -494,6 +494,19 @@
* by the subroutine or both if possible, i.e. extract
* e.g. an INTVAL from a returned PMC?
*/
+ if (REG_INT(3) == 1) {
+ /*
+ * pythons functions from pie-thon always return a PMC
+ */
+ switch (sig_ret) {
+ case 'S':
+ REG_STR(5) = VTABLE_get_string(interpreter, REG_PMC(5));
+ break;
+ case 'I':
+ REG_INT(5) = VTABLE_get_integer(interpreter, REG_PMC(5));
+ break;
+ }
+ }
REG_INT(0) = 1; /* prototyped */
REG_INT(1) = 0; /* I */
REG_INT(2) = 0; /* S */
1.42 +10 -1 parrot/src/py_func.c
Index: py_func.c
===================================================================
RCS file: /cvs/public/parrot/src/py_func.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -w -r1.41 -r1.42
--- py_func.c 23 Jul 2004 11:46:22 -0000 1.41
+++ py_func.c 23 Jul 2004 13:26:32 -0000 1.42
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2004 The Perl Foundation. All Rights Reserved.
-$Id: py_func.c,v 1.41 2004/07/23 11:46:22 leo Exp $
+$Id: py_func.c,v 1.42 2004/07/23 13:26:32 leo Exp $
=head1 NAME
@@ -599,12 +599,18 @@
*/
class = Parrot_base_vtables[enum_class_Boolean]->data;
Parrot_store_global(interpreter, NULL, Py_bool, class);
+ class->vtable->get_repr = class->vtable->get_string;
+
class = Parrot_base_vtables[enum_class_Complex]->data;
Parrot_store_global(interpreter, NULL, Py_complex, class);
+ class->vtable->get_repr = class->vtable->get_string;
+
class = Parrot_base_vtables[enum_class_PerlNum]->data;
Parrot_store_global(interpreter, NULL, Py_float, class);
class = Parrot_base_vtables[enum_class_PerlInt]->data;
Parrot_store_global(interpreter, NULL, Py_int, class);
+ class->vtable->get_repr = class->vtable->get_string;
+
class = Parrot_base_vtables[enum_class_BigInt]->data;
Parrot_store_global(interpreter, NULL, Py_long, class);
class = Parrot_base_vtables[enum_class_PerlString]->data;
@@ -612,10 +618,13 @@
class = Parrot_base_vtables[enum_class_FixedPMCArray]->data;
Parrot_store_global(interpreter, NULL, Py_tuple, class);
+ class->vtable->get_repr = class->vtable->get_string;
+
class = Parrot_base_vtables[enum_class_ResizablePMCArray]->data;
Parrot_store_global(interpreter, NULL, Py_list, class);
class = Parrot_base_vtables[enum_class_PerlHash]->data;
Parrot_store_global(interpreter, NULL, Py_dict, class);
+ class->vtable->get_repr = class->vtable->get_string;
class = Parrot_base_vtables[enum_class_Iterator]->data;
Parrot_store_global(interpreter, NULL, Py_iter, class);
1.90 +4 -2 parrot/t/pmc/pmc.t
Index: pmc.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/pmc.t,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -w -r1.89 -r1.90
--- pmc.t 12 Jul 2004 19:24:30 -0000 1.89
+++ pmc.t 23 Jul 2004 13:26:35 -0000 1.90
@@ -1,6 +1,6 @@
#! perl -w
# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-# $Id: pmc.t,v 1.89 2004/07/12 19:24:30 leo Exp $
+# $Id: pmc.t,v 1.90 2004/07/23 13:26:35 leo Exp $
=head1 NAME
@@ -1540,12 +1540,14 @@
.pcc_sub __name:
set S5, "delegate"
set I0, 1
- set I3, 1
+ set I1, 1 # 1 string retval
+ set I3, 0 # no pmc
invoke P1
.pcc_sub __type:
find_type I5, "delegate"
set I0, 1
set I1, 1
+ set I3, 0
invoke P1
CODE
All names and ids ok.