cvsuser     04/07/22 05:48:35

  Modified:    .        MANIFEST
               classes  perlint.pmc resizablepmcarray.pmc
               languages/python pie-thon pie-thon.pl
               languages/python/t/basic oo_attr.t
               src      objects.c
  Added:       languages/python/t/pie b3.t
  Log:
  Pie-thon 89 - Random class from b3; fix ResizablePMCarray.push
  
  Revision  Changes    Path
  1.709     +1 -0      parrot/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  RCS file: /cvs/public/parrot/MANIFEST,v
  retrieving revision 1.708
  retrieving revision 1.709
  diff -u -w -r1.708 -r1.709
  --- MANIFEST  22 Jul 2004 09:27:15 -0000      1.708
  +++ MANIFEST  22 Jul 2004 12:48:10 -0000      1.709
  @@ -2276,6 +2276,7 @@
   languages/python/t/basic/iter.t                   []
   languages/python/t/pie/b1.t                       []
   languages/python/t/pie/b2.t                       []
  +languages/python/t/pie/b3.t                       []
   languages/python/t/pie/b5.t                       []
   languages/python/t/pie/b6.t                       []
   languages/regex/ChangeLog                         [regex]
  
  
  
  1.1                  parrot/languages/python/t/pie/b3.t
  
  Index: b3.t
  ===================================================================
  # $Id: b3.t,v 1.1 2004/07/22 12:48:15 leo Exp $
  
  use strict;
  use lib '../../lib';
  
  use Parrot::Test tests => 3;
  
  sub test {
      language_output_is('python', $_[0], '', $_[1]);
  }
  
  test(<<'CODE', 'rgen seed');
  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 randint(self, a, b):
          return a + int((b+1-a) * self.random())
  
  rgen = Random(57, 86, 708 % 650)
  
  def main():
      print rgen._seed
  
  main()
  CODE
  
  test(<<'CODE', 'randint');
  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 randint(self, a, b):
          return a + int((b+1-a) * self.random())
  
  rgen = Random(57, 86, 708 % 650)
  
  def main():
      print rgen.randint(0, 0x7ffffffe)
  
  main()
  CODE
  
  test(<<'CODE', 'randint data');
  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 randint(self, a, b):
          return a + int((b+1-a) * self.random())
  
  rgen = Random(57, 86, 708 % 650)
  
  N = 8
  
  def main():
      data = [int(rgen.randint(0, 0x7ffffffe)) for x in xrange(N)]
      print data
  
  main()
  CODE
  
  
  
  1.77      +20 -3     parrot/classes/perlint.pmc
  
  Index: perlint.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/perlint.pmc,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -w -r1.76 -r1.77
  --- perlint.pmc       19 Jul 2004 15:56:55 -0000      1.76
  +++ perlint.pmc       22 Jul 2004 12:48:22 -0000      1.77
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: perlint.pmc,v 1.76 2004/07/19 15:56:55 leo Exp $
  +$Id: perlint.pmc,v 1.77 2004/07/22 12:48:22 leo Exp $
   
   =head1 NAME
   
  @@ -97,12 +97,25 @@
               base = 10;
           if (argcP == 2)
               base = VTABLE_get_integer(INTERP, REG_PMC(6));
  -        res = pmc_new(interpreter, enum_class_BigInt);
           arg = REG_PMC(5);
  +        if (arg->vtable->base_type == enum_class_PerlInt && base == 10) {
  +            res = pmc_new(interpreter, enum_class_PerlInt);
  +            PMC_int_val(res) = PMC_int_val(arg);
  +            REG_PMC(5) = res;
  +            return next;
  +        }
  +
           if (arg->vtable->base_type == enum_class_PerlNum) {
               FLOATVAL d = VTABLE_get_number(INTERP, arg);
               const char *sign = "-";
  +            INTVAL i = VTABLE_get_integer(INTERP, arg);
               d = floor(d);
  +            if (d == i) {
  +                res = pmc_new(interpreter, enum_class_PerlInt);
  +                PMC_int_val(res) = i;
  +                REG_PMC(5) = res;
  +                return next;
  +            }
               if (!signbit(d))
                   sign = "";
               d = fabs(d);
  @@ -110,12 +123,13 @@
           }
           else
               num = VTABLE_get_string(interpreter, arg);
  +        res = pmc_new(interpreter, enum_class_BigInt);
           VTABLE_set_string_keyed_int(interpreter, res, base, num);
           if (num->strlen < 9) {  /* XXX */
               /* TODO not if it would overflow */
               INTVAL intnum = VTABLE_get_integer(interpreter, res);
               res = pmc_new(interpreter, enum_class_PerlInt); /*TODO morph */
  -            VTABLE_set_integer_native(interpreter, res, intnum);
  +            PMC_int_val(res) = intnum;
           }
           REG_PMC(5) = res;
           return next;
  @@ -371,6 +385,7 @@
           FLOATVAL valf;
           FLOATVAL diff;
   
  +        /* XXX overflow, MMD */
           pmci = PMC_int_val(SELF);
           if (vtype == enum_class_PerlUndef) {
               VTABLE_set_integer_native(INTERP, dest, pmci);
  @@ -966,6 +981,7 @@
   
   */
       void increment () {
  +        /* XXX overflow */
           PMC_int_val(SELF) ++;
       }
   
  @@ -979,6 +995,7 @@
   
   */
       void decrement () {
  +        /* XXX overflow */
           PMC_int_val(SELF) --;
       }
   /*
  
  
  
  1.10      +12 -3     parrot/classes/resizablepmcarray.pmc
  
  Index: resizablepmcarray.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/resizablepmcarray.pmc,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -w -r1.9 -r1.10
  --- resizablepmcarray.pmc     21 Jul 2004 08:45:46 -0000      1.9
  +++ resizablepmcarray.pmc     22 Jul 2004 12:48:22 -0000      1.10
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: resizablepmcarray.pmc,v 1.9 2004/07/21 08:45:46 leo Exp $
  +$Id: resizablepmcarray.pmc,v 1.10 2004/07/22 12:48:22 leo Exp $
   
   =head1 NAME
   
  @@ -79,9 +79,16 @@
   
           if (!PMC_data(SELF)) {
               /* empty - used fixed routine */
  +            if (size < 8) {
  +                SUPER(8);
  +                PMC_int_val(SELF) = size;
  +                PMC_int_val2(SELF) = 8;
  +            }
  +            else {
               SUPER(size);
               PMC_int_val2(SELF) = size;
           }
  +        }
           else if (size <= PMC_int_val2(SELF)) {
               PMC_int_val(SELF) = size;
               /* we could shrink here if necessary */
  @@ -178,6 +185,8 @@
           INTVAL size = PMC_int_val(SELF);
           if (size + 1 >= cap)
               DYNSELF.set_integer_native(size + 1);
  +        else
  +            PMC_int_val(SELF) = size + 1;
           ((PMC**)PMC_data(SELF))[size] = value;
       }
   
  
  
  
  1.2       +1 -0      parrot/languages/python/pie-thon
  
  Index: pie-thon
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/pie-thon,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- pie-thon  22 Jul 2004 09:27:19 -0000      1.1
  +++ pie-thon  22 Jul 2004 12:48:28 -0000      1.2
  @@ -1,6 +1,7 @@
   # pie-thon x.py [ parrot-options ]
   
   f=${1%%".py"}
  +[ pie-thon.pl -nt $f.pbc ] && rm -f $f.pbc
   [ $f.py -nt $f.pbc ] && rm -f $f.pbc
   [ -e $f.pbc ] || (
        perl pie-thon.pl $1 > $f.pir
  
  
  
  1.61      +25 -2     parrot/languages/python/pie-thon.pl
  
  Index: pie-thon.pl
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/pie-thon.pl,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -w -r1.60 -r1.61
  --- pie-thon.pl       22 Jul 2004 09:27:19 -0000      1.60
  +++ pie-thon.pl       22 Jul 2004 12:48:28 -0000      1.61
  @@ -77,6 +77,15 @@
       object => 'Py_object',
       type => 'Py_type',
   );
  +
  +my %nci_methods = (
  +    'append' => 'append',
  +    'fromkeys' => 'fromkeys',
  +    'locase' => 'locase',
  +    'next' => 'next',
  +    'sort' => 'sort',
  +);
  +
   my %rev_type_map;
   
   while (my ($k, $v) =  each (%type_map)) {
  @@ -88,6 +97,13 @@
   exit if $opt{D};
   gen_code();
   
  +sub nci_method {
  +    my $m = shift;
  +    return 1 if $vtables{$m};
  +    return 1 if $nci_methods{$m};
  +    return 0;
  +}
  +
   sub type_map {
       my $t = $_[0];
       return $type_map{$t} if $type_map{$t} ;
  @@ -1243,7 +1259,13 @@
            $t = temp($rett = $ret_type);
            $ret_string = "$t = ";
        }
  -     my $internal_pmc;
  +     if (!nci_method($attr)) {       # a method function
  +         print <<EOC;
  +     P2 = $1
  +     ${ret_string}$func($args)  $cmt
  +EOC
  +     }
  +     else {
        print <<EOC;
        .local NCI meth\:\:$attr
        meth\:\:$attr = $func # avoid savetop
  @@ -1251,6 +1273,7 @@
        ${ret_string}meth\:\:$attr($args)  $cmt
   EOC
       }
  +    }
       else {
        my $ret_type = ret_val($func);
        my $ret_string = "";
  
  
  
  1.8       +28 -2     parrot/languages/python/t/basic/oo_attr.t
  
  Index: oo_attr.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/t/basic/oo_attr.t,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- oo_attr.t 22 Jul 2004 08:01:27 -0000      1.7
  +++ oo_attr.t 22 Jul 2004 12:48:32 -0000      1.8
  @@ -1,9 +1,9 @@
  -# $Id: oo_attr.t,v 1.7 2004/07/22 08:01:27 leo Exp $
  +# $Id: oo_attr.t,v 1.8 2004/07/22 12:48:32 leo Exp $
   
   use strict;
   use lib '../../lib';
   
  -use Parrot::Test tests => 10;
  +use Parrot::Test tests => 12;
   
   sub test {
       language_output_is('python', $_[0], '', $_[1]);
  @@ -142,3 +142,29 @@
   
   main()
   CODE
  +
  +test(<<'CODE', '__init__ method');
  +class C:
  +    def __init__(self, x):
  +        self.a = x
  +
  +def main():
  +    c = C(42)
  +    print c.a
  +
  +main()
  +CODE
  +
  +test(<<'CODE', '__init__ method, args');
  +class C:
  +    def __init__(self, x, y, z):
  +        self.a = x
  +        self.b = y
  +        self.c = z
  +
  +def main():
  +    c = C(42, -2, "ok")
  +    print c.a, c.b, c.c
  +
  +main()
  +CODE
  
  
  
  1.109     +9 -6      parrot/src/objects.c
  
  Index: objects.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/objects.c,v
  retrieving revision 1.108
  retrieving revision 1.109
  diff -u -w -r1.108 -r1.109
  --- objects.c 21 Jul 2004 11:42:41 -0000      1.108
  +++ objects.c 22 Jul 2004 12:48:35 -0000      1.109
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: objects.c,v 1.108 2004/07/21 11:42:41 leo Exp $
  +$Id: objects.c,v 1.109 2004/07/22 12:48:35 leo Exp $
   
   =head1 NAME
   
  @@ -544,7 +544,7 @@
       INTVAL nparents;
       STRING *meth_str;
       PMC *meth;
  -    PMC *arg = REG_PMC(5);  /* TODO more args */
  +    PMC *arg = REG_PMC(5);
   
       nparents = VTABLE_elements(interpreter, classsearch_array);
       if (nparents) {
  @@ -563,11 +563,14 @@
           }
       }
       meth_str = CONST_STRING(interpreter, "__init__");
  -    meth = Parrot_find_method_with_cache(interpreter,
  -            class, meth_str);
  +    meth = Parrot_find_method_with_cache(interpreter, class, meth_str);
       if (meth) {
  -        Parrot_runops_fromc_args_save(interpreter, meth,
  -                "vPP", object, arg);
  +        void *data = Parrot_save_register_frames(interpreter, meth);
  +        REG_STR(0) = meth_str;
  +        REG_PMC(2) = object;
  +        /* args are just passed on */
  +        Parrot_runops_fromc(interpreter, meth);
  +        Parrot_restore_register_frames(interpreter, data);
       }
   }
   
  
  
  

Reply via email to