cvsuser     04/07/19 01:22:36

  Modified:    classes  perlhash.pmc
               languages/python/t/pie b6.t
               src      py_func.c
  Log:
  Pie-thon 78 - b6.py is running (modulo import)
  
  Revision  Changes    Path
  1.86      +40 -34    parrot/classes/perlhash.pmc
  
  Index: perlhash.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/perlhash.pmc,v
  retrieving revision 1.85
  retrieving revision 1.86
  diff -u -w -r1.85 -r1.86
  --- perlhash.pmc      17 Jul 2004 16:01:05 -0000      1.85
  +++ perlhash.pmc      19 Jul 2004 08:22:29 -0000      1.86
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: perlhash.pmc,v 1.85 2004/07/17 16:01:05 leo Exp $
  +$Id: perlhash.pmc,v 1.86 2004/07/19 08:22:29 leo Exp $
   
   =head1 NAME
   
  @@ -67,20 +67,24 @@
   
       /*
        * keys should be able to iterate
  -     * TODO check that
  +     * There are currently definitely too many ways to create
  +     * slices.
        */
  -    if (keys->vtable->base_type == enum_class_Iterator ||
  -            VTABLE_isa(interpreter, keys,
  -                const_string(interpreter, "Iterator"))) {
  +    if (keys->vtable->base_type == enum_class_Iterator) {
           iter = keys;
           if (PMC_pmc_val(iter)) {
               PMC *xr = PMC_pmc_val(iter);
               /* check, if we got an xrange iterator */
               if (PObj_is_PMC_TEST(xr) &&
                       xr->vtable->base_type == enum_class_Slice) {
  +                keys = xr;
  +            }
  +        }
  +    }
  +    if (keys->vtable->base_type == enum_class_Slice) {
                   INTVAL start, end, step;
                   Hash* hash;
  -                parrot_range_t *range = PMC_struct_val(xr);
  +        parrot_range_t *range = PMC_struct_val(keys);
                   new_hash_x(interpreter, &hash, enum_type_ptr,
                           0, Hash_key_type_int,
                           int_compare, key_hash_int,
  @@ -90,16 +94,21 @@
                   end   = RVal_int(range->end);
                   step  = RVal_int(range->step);
                   /* TODO step
  -                 * TODO reversed range, negative step
  +         * end is already adjusted
                    */
  -                for (i = start; i <= end; i+= step) {
  +        if (step < 0) {
  +            for (i = start; i >= end; i+= step) {
                       hash_put(interpreter, hash, (void *)i, value);
                   }
  -                goto done;
  +        }
  +        else {
  +            for (i = start; i <= end; i+= step) {
  +                hash_put(interpreter, hash, (void *)i, value);
               }
           }
  +        goto done;
       }
  -    else
  +    if (keys->vtable->base_type != enum_class_Iterator)
           iter = pmc_new_init(interpreter, enum_class_Iterator, keys);
       VTABLE_set_integer_native(interpreter, iter, ITERATE_FROM_START);
       for (; VTABLE_get_bool(interpreter, iter); ) {
  @@ -115,7 +124,7 @@
   }
   
   
  -static PMC* undef = NULL;
  +static PMC* undef, *intret;
   STRING * hash_get_idx(Interp *interpreter, Hash *hash, PMC *key);
   
   /*
  @@ -159,6 +168,8 @@
           if (pass) {
               enter_nci_method(INTERP, enum_class_PerlHash,
                       F2DPTR(fromkeys), "fromkeys", "PIOP");
  +            undef = constant_pmc_new(INTERP, enum_class_PerlUndef);
  +            intret = constant_pmc_new(INTERP, enum_class_PerlInt);
           }
       }
   /*
  @@ -202,10 +213,6 @@
   */
   
       void init () {
  -        if (undef == NULL) {
  -            undef = constant_pmc_new_noinit(INTERP, enum_class_PerlUndef);
  -            VTABLE_init(INTERP, undef);
  -        }
           PObj_custom_mark_SET(SELF);
           new_hash(INTERP, (Hash**)&PMC_struct_val(SELF));
       }
  @@ -612,19 +619,18 @@
   
           switch (PObj_get_FLAGS(key) & KEY_type_FLAGS) {
               case KEY_integer_FLAG: {
  -                PMC *ret = pmc_new(INTERP, enum_class_PerlUndef);
                   /* called from iterator with an integer idx in key
                    * check if we really have Hash_key_type_int
                    */
                   if (hash->key_type == Hash_key_type_int) {
                       INTVAL i = (INTVAL)hash_get_idx(INTERP, hash, key);
  -                    VTABLE_set_integer_native(INTERP, ret, i);
  -                    return ret;
  +                    PMC_int_val(intret) = i;
  +                    return intret;
                   }
                   else {
                       STRING *s = hash_get_idx(INTERP, hash, key);
  -                    VTABLE_set_string_native(INTERP, ret, s);
  -                    return ret;
  +                    VTABLE_set_string_native(INTERP, intret, s);
  +                    return intret;
                   }
              }
               default:
  
  
  
  1.4       +37 -2     parrot/languages/python/t/pie/b6.t
  
  Index: b6.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/t/pie/b6.t,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- b6.t      17 Jul 2004 16:01:24 -0000      1.3
  +++ b6.t      19 Jul 2004 08:22:32 -0000      1.4
  @@ -1,9 +1,9 @@
  -# $Id: b6.t,v 1.3 2004/07/17 16:01:24 leo Exp $
  +# $Id: b6.t,v 1.4 2004/07/19 08:22:32 leo Exp $
   
   use strict;
   use lib '../../lib';
   
  -use Parrot::Test tests => 3;
  +use Parrot::Test tests => 4;
   
   sub test {
       language_output_is('python', $_[0], '', $_[1]);
  @@ -79,3 +79,38 @@
   if __name__ == '__main__':
       main()
   CODE
  +
  +test(<<'CODE', 'b6');
  +show=True
  +# from b5 import check
  +def check(a, b):
  +    if __debug__:
  +        if show:
  +            print `a`, "==", `b`
  +    if not a == b:
  +        raise AssertionError("%.30r != %.30r" % (a, b))
  +
  +def main():
  +    L = [1]*1000000
  +    L[-1] = 42
  +    n = 0
  +    for i in L:
  +        n += i
  +    check(i, 42)
  +    check(n, 1000041)
  +    n = 0
  +    for i in xrange(1000000):
  +        n += i
  +    check(i, 999999)
  +    check(n, 999999*1000000//2)
  +    d = dict.fromkeys(xrange(1000000))
  +    n = 0
  +    for i in d:
  +        n += i
  +    check(n, 999999*1000000//2)
  +
  +if __name__ == '__main__':
  +    main()
  +
  +CODE
  +
  
  
  
  1.32      +23 -2     parrot/src/py_func.c
  
  Index: py_func.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/py_func.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -w -r1.31 -r1.32
  --- py_func.c 17 Jul 2004 11:33:29 -0000      1.31
  +++ py_func.c 19 Jul 2004 08:22:36 -0000      1.32
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2004 The Perl Foundation.  All Rights Reserved.
  -$Id: py_func.c,v 1.31 2004/07/17 11:33:29 leo Exp $
  +$Id: py_func.c,v 1.32 2004/07/19 08:22:36 leo Exp $
   
   =head1 NAME
   
  @@ -679,6 +679,21 @@
   */
   
   #include "pmc_default.h"
  +
  +static void
  +integer_divide(Interp* interp, PMC* self, PMC* value, PMC* destination)
  +{
  +     INTVAL result;
  +     result = PMC_int_val(self) / PMC_int_val(value);
  +     VTABLE_set_integer_native(interp, destination, result);
  +}
  +static void
  +integer_divide_int(Interp* interp, PMC* self, INTVAL value, PMC* destination)
  +{
  +     INTVAL result;
  +     result = PMC_int_val(self) / value;
  +     VTABLE_set_integer_native(interp, destination, result);
  +}
   static void
   parrot_py_create_default_meths(Interp *interpreter)
   {
  @@ -690,6 +705,12 @@
       parrot_py_object(interpreter, class,
              F2DPTR(Parrot_default_get_repr), meth, sio);
   
  +    mmd_register(interpreter, MMD_DIVIDE,
  +            enum_class_PerlInt, enum_class_PerlInt,
  +            (funcptr_t)integer_divide);
  +    mmd_register(interpreter, MMD_DIVIDE_INT,
  +            enum_class_PerlInt, 0,
  +            (funcptr_t)integer_divide_int);
   }
   /*
   
  
  
  

Reply via email to