cvsuser 04/07/09 09:39:01
Modified: . MANIFEST include/parrot parrot.h classes perlhash.pmc slice.pmc languages/python/t/pie b5.t src py_func.c Added: include/parrot slice.h Log: Pie-thon 44 - slices cleanup Revision Changes Path 1.702 +1 -0 parrot/MANIFEST Index: MANIFEST =================================================================== RCS file: /cvs/public/parrot/MANIFEST,v retrieving revision 1.701 retrieving revision 1.702 diff -u -w -r1.701 -r1.702 --- MANIFEST 9 Jul 2004 05:23:30 -0000 1.701 +++ MANIFEST 9 Jul 2004 16:38:49 -0000 1.702 @@ -1845,6 +1845,7 @@ include/parrot/runops_cores.h [devel]include include/parrot/rx.h [devel]include include/parrot/rxstacks.h [devel]include +include/parrot/slice.h [devel]include include/parrot/smallobject.h [devel]include include/parrot/stacks.h [devel]include include/parrot/stat.h [devel]include 1.97 +2 -1 parrot/include/parrot/parrot.h Index: parrot.h =================================================================== RCS file: /cvs/public/parrot/include/parrot/parrot.h,v retrieving revision 1.96 retrieving revision 1.97 diff -u -w -r1.96 -r1.97 --- parrot.h 20 Jun 2004 08:10:21 -0000 1.96 +++ parrot.h 9 Jul 2004 16:38:52 -0000 1.97 @@ -1,7 +1,7 @@ /* parrot.h * Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. * CVS Info - * $Id: parrot.h,v 1.96 2004/06/20 08:10:21 leo Exp $ + * $Id: parrot.h,v 1.97 2004/07/09 16:38:52 leo Exp $ * Overview: * General header file includes for the parrot interpreter * Data Structure and Algorithms: @@ -281,6 +281,7 @@ #include "parrot/library.h" #include "parrot/global.h" #include "parrot/stat.h" +#include "parrot/slice.h" #endif /* PARROT_PARROT_H_GUARD */ 1.1 parrot/include/parrot/slice.h Index: slice.h =================================================================== /* slice.h * Copyright: 2001-2004 The Perl Foundation. All Rights Reserved. * CVS Info * $Id: slice.h,v 1.1 2004/07/09 16:38:52 leo Exp $ * Overview: * This is the api header for slices. * Data Structure and Algorithms: * History: * Notes: * References: */ #if !defined(PARROT_SLICE_H_GUARD) #define PARROT_SLICE_H_GUARD #ifdef PARROT_IN_CORE typedef struct { INTVAL i; STRING *s; } RUnion; #define RVal_int(u) u.i #define RVal_str(u) u.s typedef struct _parrot_range_t { int type; /* enum_type_INTVAL or STRING */ RUnion start; /* start of this range */ RUnion end; /* end of this range */ RUnion step; /* step of this range */ RUnion cur; /* current value */ struct _parrot_range_t *next; /* next in chain */ } parrot_range_t; #endif /* PARROT_IN_CORE */ #endif /* PARROT_SLICE_H_GUARD */ /* * Local variables: * c-indentation-style: bsd * c-basic-offset: 4 * indent-tabs-mode: nil * End: * * vim: expandtab shiftwidth=4: */ 1.81 +2 -21 parrot/classes/perlhash.pmc Index: perlhash.pmc =================================================================== RCS file: /cvs/public/parrot/classes/perlhash.pmc,v retrieving revision 1.80 retrieving revision 1.81 diff -u -w -r1.80 -r1.81 --- perlhash.pmc 9 Jul 2004 15:24:10 -0000 1.80 +++ perlhash.pmc 9 Jul 2004 16:38:56 -0000 1.81 @@ -1,6 +1,6 @@ /* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. -$Id: perlhash.pmc,v 1.80 2004/07/09 15:24:10 leo Exp $ +$Id: perlhash.pmc,v 1.81 2004/07/09 16:38:56 leo Exp $ =head1 NAME @@ -44,25 +44,6 @@ return a != b; } -/* XXX duplicated from classes/slice.pmc */ - -typedef struct { - INTVAL i; - STRING *s; -} RUnion; - -#define RVal_int(u) u.i -#define RVal_str(u) u.s - -typedef struct _range_t { - int type; /* enum_type_INTVAL or STRING */ - RUnion start; /* start of this range */ - RUnion end; /* end of this range */ - RUnion step; /* step of this range */ - RUnion cur; /* current value */ - struct _range_t *next; /* next in chain */ -} range_t; - static void fromkeys(Interp *interpreter, PMC *self, PMC *keys, PMC *value) { @@ -99,7 +80,7 @@ xr->vtable->base_type == enum_class_Slice) { INTVAL start, end, step; Hash* hash; - range_t *range = PMC_struct_val(xr); + parrot_range_t *range = PMC_struct_val(xr); new_hash_x(interpreter, &hash, enum_type_ptr, 0, Hash_key_type_int, int_compare, key_hash_int, 1.13 +11 -29 parrot/classes/slice.pmc Index: slice.pmc =================================================================== RCS file: /cvs/public/parrot/classes/slice.pmc,v retrieving revision 1.12 retrieving revision 1.13 diff -u -w -r1.12 -r1.13 --- slice.pmc 9 Jul 2004 15:24:10 -0000 1.12 +++ slice.pmc 9 Jul 2004 16:38:56 -0000 1.13 @@ -1,6 +1,6 @@ /* Copyright: 2004 The Perl Foundation. All Rights Reserved. -$Id: slice.pmc,v 1.12 2004/07/09 15:24:10 leo Exp $ +$Id: slice.pmc,v 1.13 2004/07/09 16:38:56 leo Exp $ =head1 NAME @@ -26,7 +26,7 @@ to see slice constant flags. -During initialization above key chain gets converted to range_t structures. +During initialization above key chain gets converted to parrot_range_t structures. =head2 Methods @@ -38,24 +38,6 @@ #include "parrot/parrot.h" -typedef struct { - INTVAL i; - STRING *s; -} RUnion; - -#define RVal_int(u) u.i -#define RVal_str(u) u.s - -typedef struct _range_t { - int type; /* enum_type_INTVAL or STRING */ - RUnion start; /* start of this range */ - RUnion end; /* end of this range */ - RUnion step; /* step of this range */ - RUnion cur; /* current value */ - struct _range_t *next; /* next in chain */ -} range_t; - - /* * create range_t structure * @@ -69,7 +51,7 @@ static void set_slice_start(Interp *interpreter, PMC *self, PMC *key, PMC *agg) { - range_t *range = mem_sys_allocate(sizeof *range); + parrot_range_t *range = mem_sys_allocate(sizeof *range); PMC_struct_val(self) = range; next_range: @@ -123,7 +105,7 @@ range_end: key = PMC_data(key); if (key) { - range_t *n = mem_sys_allocate(sizeof *range); + parrot_range_t *n = mem_sys_allocate(sizeof *range); range->next = n; range = n; goto next_range; @@ -167,11 +149,11 @@ static void set_slice_next(Interp *interpreter, PMC *self, PMC *agg) { - range_t *r = PMC_struct_val(self); + parrot_range_t *r = PMC_struct_val(self); if (r->type == enum_type_INTVAL) { RVal_int(r->cur) += RVal_int(r->step); if (RVal_int(r->cur) > RVal_int(r->end)) { - range_t *n; + parrot_range_t *n; next_range: n = r->next; mem_sys_free(r); @@ -208,7 +190,7 @@ } void destroy () { - range_t *r = PMC_struct_val(SELF), *n; + parrot_range_t *r = PMC_struct_val(SELF), *n; /* iteration ended - all is freed */ if ((INTVAL) r == -1) return; @@ -239,12 +221,12 @@ */ INTVAL get_integer() { - range_t *r = PMC_struct_val(SELF); + parrot_range_t *r = PMC_struct_val(SELF); return RVal_int(r->cur); } STRING* get_string() { - range_t *r = PMC_struct_val(SELF); + parrot_range_t *r = PMC_struct_val(SELF); return RVal_str(r->cur); } @@ -280,7 +262,7 @@ } INTVAL elements () { - range_t *r = PMC_struct_val(SELF); + parrot_range_t *r = PMC_struct_val(SELF); /* only start .. end supported so: * TODO check flags somewhere * */ @@ -289,7 +271,7 @@ } INTVAL get_integer_keyed(PMC* key) { - range_t *r = PMC_struct_val(key); + parrot_range_t *r = PMC_struct_val(key); return RVal_int(r->cur); } 1.4 +29 -2 parrot/languages/python/t/pie/b5.t Index: b5.t =================================================================== RCS file: /cvs/public/parrot/languages/python/t/pie/b5.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- b5.t 9 Jul 2004 13:17:21 -0000 1.3 +++ b5.t 9 Jul 2004 16:38:58 -0000 1.4 @@ -1,9 +1,9 @@ -# $Id: b5.t,v 1.3 2004/07/09 13:17:21 leo Exp $ +# $Id: b5.t,v 1.4 2004/07/09 16:38:58 leo Exp $ use strict; use lib '../../lib'; -use Parrot::Test tests => 4; +use Parrot::Test tests => 5; sub test { language_output_is('python', $_[0], '', $_[1]); @@ -110,4 +110,31 @@ main() CODE +test(<<'CODE', 'check_functions bool slices, aggregates'); + +show = True + +def check(a, b): + if __debug__: + if show: + print `a`, "==", `b` + if not a == b: + raise AssertionError("%.30r != %.30r" % (a, b)) + +def check_functions(i=0, j=0): + check(bool([i, j][i:j]), False) + check(bool({i: j}), True) + check(bool({}), False) + +def main(): + check_functions() + check_functions(j=10, i=10) + for i in range(0,500,249): + print "i:", i + check_functions(j=long(i*1000000), i=i*1000000) + +if __name__ == '__main__': + main() +CODE + 1.14 +9 -24 parrot/src/py_func.c Index: py_func.c =================================================================== RCS file: /cvs/public/parrot/src/py_func.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -r1.13 -r1.14 --- py_func.c 9 Jul 2004 15:24:32 -0000 1.13 +++ py_func.c 9 Jul 2004 16:39:01 -0000 1.14 @@ -1,6 +1,6 @@ /* Copyright: 2001-2004 The Perl Foundation. All Rights Reserved. -$Id: py_func.c,v 1.13 2004/07/09 15:24:32 leo Exp $ +$Id: py_func.c,v 1.14 2004/07/09 16:39:01 leo Exp $ =head1 NAME @@ -659,31 +659,12 @@ parrot_py_create_default_meths(interpreter); } -/* - * XXX create slice.h - */ -typedef struct { - INTVAL i; - STRING *s; -} RUnion; - -#define RVal_int(u) u.i -#define RVal_str(u) u.s - -typedef struct _range_t { - int type; /* enum_type_INTVAL or STRING */ - RUnion start; /* start of this range */ - RUnion end; /* end of this range */ - RUnion step; /* step of this range */ - RUnion cur; /* current value */ - struct _range_t *next; /* next in chain */ -} range_t; PMC* Parrot_py_get_slice(Interp *interpreter, PMC *self, PMC *key) { INTVAL i, n, type; - range_t *range; + parrot_range_t *range; PMC *res, *slice, *item; INTVAL start, end, iitem; @@ -699,7 +680,10 @@ */ res = pmc_new(interpreter, type); start = RVal_int(range->start); - end = RVal_int(range->end); + /* + * set_slice_start did already decrement it + */ + end = RVal_int(range->end) + 1; n = VTABLE_elements(interpreter, self); if (!n) { /* slice of empty is empty @@ -718,17 +702,18 @@ end = start; else if (end > n) end = n; - for (i = start; i <= end; ++i) { + for (i = start; i < end; ++i) { switch (type) { case enum_class_Array: case enum_class_PerlArray: + case enum_class_FixedPMCArray: item = VTABLE_get_pmc_keyed_int(interpreter, self, i); VTABLE_set_pmc_keyed_int(interpreter, res, i-start, item); break; case enum_class_String: case enum_class_PerlString: string_substr(interpreter, PMC_str_val(self), start, - end - start + 1, &PMC_str_val(res), 1); + end - start, &PMC_str_val(res), 1); return res; case enum_class_IntList: iitem = VTABLE_get_integer_keyed_int(interpreter, self, i);