cvsuser 04/07/23 04:46:22
Modified: classes fixedpmcarray.pmc resizablepmcarray.pmc
languages/python pie-thon.pl
languages/python/t/pie b3.t
src py_func.c trace.c
Log:
Pie-thon 92 - data creation and sort of b3
Revision Changes Path
1.14 +15 -1 parrot/classes/fixedpmcarray.pmc
Index: fixedpmcarray.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/fixedpmcarray.pmc,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- fixedpmcarray.pmc 19 Jul 2004 16:41:39 -0000 1.13
+++ fixedpmcarray.pmc 23 Jul 2004 11:46:10 -0000 1.14
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: fixedpmcarray.pmc,v 1.13 2004/07/19 16:41:39 leo Exp $
+$Id: fixedpmcarray.pmc,v 1.14 2004/07/23 11:46:10 leo Exp $
=head1 NAME
@@ -69,6 +69,7 @@
if (REG_INT(3) == 0) {
default_sort:
func = sort_compare;
+use_func:
the_interp = interpreter;
qsort(PMC_data(self), PMC_int_val(self), sizeof(PMC *),
(int (*)(const void*, const void*))func);
@@ -86,6 +87,19 @@
*/
goto default_sort;
}
+ else {
+ if (cmp_func->vtable->base_type == enum_class_NCI) {
+ /* the C function inside is at struct_val
+ * hopefully this function does compare
+ */
+ func = (int (*)(void*, void*)) PMC_struct_val(cmp_func);
+ /*
+ * XXX not yet -cmp doesn't take an interpreter arg
+ */
+ /* goto use_func; */
+ goto default_sort;
+ }
+ }
/*
* save registers once, as the compare function will be called
* repeatedly
1.11 +2 -2 parrot/classes/resizablepmcarray.pmc
Index: resizablepmcarray.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/resizablepmcarray.pmc,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -r1.10 -r1.11
--- resizablepmcarray.pmc 22 Jul 2004 12:48:22 -0000 1.10
+++ resizablepmcarray.pmc 23 Jul 2004 11:46:10 -0000 1.11
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: resizablepmcarray.pmc,v 1.10 2004/07/22 12:48:22 leo Exp $
+$Id: resizablepmcarray.pmc,v 1.11 2004/07/23 11:46:10 leo Exp $
=head1 NAME
@@ -102,7 +102,7 @@
else {
needed = size - cur;
cur += needed + 4096;
- cur &= 0xfff;
+ cur &= ~0xfff;
}
PMC_data(SELF) = mem_sys_realloc(PMC_data(SELF),
cur * sizeof(PMC*));
1.64 +20 -3 parrot/languages/python/pie-thon.pl
Index: pie-thon.pl
===================================================================
RCS file: /cvs/public/parrot/languages/python/pie-thon.pl,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -w -r1.63 -r1.64
--- pie-thon.pl 23 Jul 2004 08:29:13 -0000 1.63
+++ pie-thon.pl 23 Jul 2004 11:46:13 -0000 1.64
@@ -55,7 +55,7 @@
__iter__ => '__get_iter',
__repr__ => '__get_repr',
__str__ => '__get_string',
- __cmp__ => 'MMD_CMP',
+ __cmp__ => 41, # MMD_CMP
);
# the new way type system
@@ -1671,8 +1671,15 @@
if ($vtables{$c}) {
$c = $vtables{$c};
}
+ my $cc;
+ if ($c =~ /^\d+$/) { # MMD
+ $cc = "-$c";
+ }
+ else {
+ $cc = qq!"$c"!;
+ }
print <<EOC;
- $attr = getattribute $obj, "$c" $cmt
+ $attr = getattribute $obj, $cc $cmt
EOC
push @stack, ["obj $obj attr $c", $attr, 'P'];
}
@@ -1682,8 +1689,18 @@
my ($n, $c, $cmt) = @_;
my $obj = pop @stack; # object
my $val = promote(pop @stack);
+ if ($vtables{$c}) {
+ $c = $vtables{$c};
+ }
+ my $cc;
+ if ($c =~ /^\d+$/) { # MMD
+ $cc = "-$c";
+ }
+ else {
+ $cc = qq!"$c"!;
+ }
print <<EOC;
- setattribute $obj->[1], "$c", $val $cmt
+ setattribute $obj->[1], $cc, $val $cmt
EOC
}
1.4 +18 -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.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- b3.t 23 Jul 2004 08:29:21 -0000 1.3
+++ b3.t 23 Jul 2004 11:46:19 -0000 1.4
@@ -1,9 +1,9 @@
-# $Id: b3.t,v 1.3 2004/07/23 08:29:21 leo Exp $
+# $Id: b3.t,v 1.4 2004/07/23 11:46:19 leo Exp $
use strict;
use lib '../../lib';
-use Parrot::Test tests => 5;
+use Parrot::Test tests => 6;
sub test {
language_output_is('python', $_[0], '', $_[1]);
@@ -124,3 +124,19 @@
main()
CODE
+
+test(<<'CODE', 'data slice');
+def main():
+ a = []
+ N = 20000
+ K = 1
+ for i in range(N):
+ a.append(i)
+ for i in range(N):
+ if a[i] != i:
+ print a[i]
+ print "A", a[:K], a[N//2:N//2+K], a[-K:]
+
+main()
+
+CODE
1.41 +59 -6 parrot/src/py_func.c
Index: py_func.c
===================================================================
RCS file: /cvs/public/parrot/src/py_func.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -w -r1.40 -r1.41
--- py_func.c 23 Jul 2004 08:29:24 -0000 1.40
+++ py_func.c 23 Jul 2004 11:46:22 -0000 1.41
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2004 The Perl Foundation. All Rights Reserved.
-$Id: py_func.c,v 1.40 2004/07/23 08:29:24 leo Exp $
+$Id: py_func.c,v 1.41 2004/07/23 11:46:22 leo Exp $
=head1 NAME
@@ -28,6 +28,8 @@
*/
+static PMC* parrot_py_get_attr_str(Interp*, PMC *object, STRING *name);
+
static PMC *
parrot_py_callable(Interp *interpreter, PMC *pmc)
{
@@ -61,6 +63,12 @@
return s;
}
+static INTVAL
+parrot_py_cmp(Interp *interpreter, PMC *left, PMC *right)
+{
+ return mmd_dispatch_i_pp(interpreter, left, right, MMD_CMP);
+}
+
static void
dict_from_tuple_array(Interp *interpreter, PMC *dict, PMC *ar)
{
@@ -511,7 +519,7 @@
return ex;
}
-static void
+static PMC*
parrot_py_object(Interp *interpreter, STRING *class, void *func,
STRING *name, STRING *sig)
{
@@ -519,13 +527,14 @@
method = pmc_new(interpreter, enum_class_NCI);
VTABLE_set_pointer_keyed_str(interpreter, method, sig, func);
Parrot_store_global(interpreter, class, name, method);
+ return method;
}
-static void
+static PMC*
parrot_py_global(Interp *interpreter, void *func,
STRING *name, STRING *sig)
{
- parrot_py_object(interpreter, NULL, func, name, sig);
+ return parrot_py_object(interpreter, NULL, func, name, sig);
}
/*
@@ -542,11 +551,13 @@
STRING *ip = CONST_STRING(interpreter, "iP");
STRING *pip = CONST_STRING(interpreter, "PIP");
STRING *pipp = CONST_STRING(interpreter, "PIPP");
+ STRING *iipp = CONST_STRING(interpreter, "iIPP");
STRING *pippp = CONST_STRING(interpreter, "PIPPP");
STRING *assert_e = CONST_STRING(interpreter, "AssertionError");
STRING *callable = CONST_STRING(interpreter, "callable");
STRING *chr = CONST_STRING(interpreter, "chr");
+ STRING *cmp = CONST_STRING(interpreter, "cmp");
STRING *divmod = CONST_STRING(interpreter, "divmod");
STRING *enumerate= CONST_STRING(interpreter, "enumerate");
STRING *filter = CONST_STRING(interpreter, "filter");
@@ -561,6 +572,8 @@
STRING *reduce = CONST_STRING(interpreter, "reduce");
STRING *repr = CONST_STRING(interpreter, "repr");
+ STRING *name_ = CONST_STRING(interpreter, "__name__");
+
/* types */
STRING *Py_bool = CONST_STRING(interpreter, "Py_bool");
STRING *Py_complex = CONST_STRING(interpreter, "Py_complex");
@@ -579,7 +592,7 @@
STRING *Py_object = CONST_STRING(interpreter, "Py_object");
STRING *Py_type = CONST_STRING(interpreter, "Py_type");
- PMC* class;
+ PMC* class, *m;
/*
* new types interface, just place a class object as global
* this is invocable and returns a new instance
@@ -618,6 +631,16 @@
parrot_py_global(interpreter, F2DPTR(parrot_py_assert_e), assert_e, pip);
parrot_py_global(interpreter, F2DPTR(parrot_py_callable), callable, pip);
parrot_py_global(interpreter, F2DPTR(parrot_py_chr), chr, pip);
+
+ m = parrot_py_global(interpreter, F2DPTR(parrot_py_cmp), cmp, iipp);
+ {
+ PMC* cmp_name = pmc_new(interpreter, enum_class_PerlString);
+ VTABLE_assign_string_native(interpreter, cmp_name, cmp);
+ VTABLE_setprop(interpreter, m, name_, cmp_name);
+ m->vtable = Parrot_clone_vtable(interpreter, m->vtable);
+ m->vtable->get_attr_str = parrot_py_get_attr_str;
+ }
+
parrot_py_global(interpreter, F2DPTR(parrot_py_divmod), divmod, pipp);
parrot_py_global(interpreter, F2DPTR(parrot_py_enumerate), enumerate, pip);
parrot_py_global(interpreter, F2DPTR(parrot_py_filter), filter, pipp);
@@ -759,6 +782,10 @@
mmd_register(interpreter, MMD_DIVIDE_INT,
enum_class_PerlInt, 0,
(funcptr_t)integer_divide_int);
+ /*
+ * Sub PMCs have an atribute __name__ - redirect __get_attr
+ */
+ Parrot_base_vtables[enum_class_Sub]->get_attr_str = parrot_py_get_attr_str;
}
/*
@@ -957,13 +984,22 @@
/*
* 1) look at props
*/
- if ( (p = PMC_metadata(object)) ) {
+ if (object->pmc_ext && (p = PMC_metadata(object)) ) {
h = PMC_struct_val(p);
b = hash_get_bucket(interpreter, h, name);
if (b) {
return b->value;
}
}
+ if (object->vtable->base_type == enum_class_Sub) {
+ STRING *name_ = CONST_STRING(interpreter, "__name__");
+ if (!string_equal(interpreter, name, name_)) {
+ parrot_sub_t sub = PMC_sub(object);
+ PMC *n = pmc_new(interpreter, enum_class_PerlString);
+ VTABLE_assign_string_native(interpreter, n, sub->name);
+ return n;
+ }
+ }
/*
* check attributes, if its an object
*/
@@ -985,6 +1021,11 @@
if (p)
return p;
}
+ else if (PObj_is_class_TEST(object)) {
+ p = Parrot_find_method_with_cache(interpreter, object, name);
+ if (p)
+ return p;
+ }
/*
* 4) global - class method
*/
@@ -1008,6 +1049,16 @@
Parrot_default_setprop(interpreter, obj, name, v);
}
+static PMC*
+parrot_py_get_attr_num(Interp* interpreter, PMC *object, INTVAL nr)
+{
+ return PMCNULL;
+}
+static void
+parrot_py_set_attr_num(Interp* interpreter, PMC *obj, INTVAL nr, PMC *v)
+{
+
+}
/*
* TODO self.super()
* for now use delegate directly
@@ -1044,6 +1095,8 @@
vtable->get_attr_str = parrot_py_get_attr_str;
vtable->set_attr_str = parrot_py_set_attr_str;
+ vtable->get_attr = parrot_py_get_attr_num;
+ vtable->set_attr = parrot_py_set_attr_num;
vtable->get_iter = parrot_py_get_iter;
class->vtable->get_attr_str = parrot_py_get_attr_str;
1.64 +18 -3 parrot/src/trace.c
Index: trace.c
===================================================================
RCS file: /cvs/public/parrot/src/trace.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -w -r1.63 -r1.64
--- trace.c 22 Jul 2004 04:31:16 -0000 1.63
+++ trace.c 23 Jul 2004 11:46:22 -0000 1.64
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: trace.c,v 1.63 2004/07/22 04:31:16 leo Exp $
+$Id: trace.c,v 1.64 2004/07/23 11:46:22 leo Exp $
=head1 NAME
@@ -36,6 +36,20 @@
*/
+static STRING*
+trace_class_name(Interp *interpreter, PMC* pmc)
+{
+ STRING *class_name;
+ if (PObj_is_class_TEST(pmc)) {
+ SLOTTYPE *class_array = PMC_data(pmc);
+ PMC *class_name_pmc = get_attrib_num(class_array, PCD_CLASS_NAME);
+ class_name = PMC_str_val(class_name_pmc);
+ }
+ else
+ class_name = pmc->vtable->whoami;
+ return class_name;
+}
+
void
trace_pmc_dump(Interp *interpreter, PMC* pmc)
{
@@ -43,8 +57,9 @@
if (pmc && pmc != PMCNULL) {
if(pmc->vtable) {
if (pmc->vtable->data == pmc) {
- PIO_eprintf(interpreter, "%S=Class:PMC(%#p)",
- VTABLE_name(interpreter, pmc), pmc);
+ STRING *name = trace_class_name(interpreter, pmc);
+ PIO_eprintf(interpreter, "%S=%Ss:PMC(%#p)",
+ VTABLE_name(interpreter, pmc), name, pmc);
}
else if (pmc->vtable->base_type == enum_class_PerlString) {
STRING *s = VTABLE_get_string(interpreter, pmc);