cvsuser     04/11/28 20:47:05

  Modified:    dynclasses pybuiltin.pmc pydict.pmc pystring.pmc
               languages/python README
               languages/python/t/basic 02_expr.t
               lib/Parrot/Test Python.pm
  Log:
  __main__
  dictionary exists
  index individual chars in a string
  hook the python test harness to Pirate
  
  Revision  Changes    Path
  1.4       +18 -6     parrot/dynclasses/pybuiltin.pmc
  
  Index: pybuiltin.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pybuiltin.pmc,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- pybuiltin.pmc     28 Nov 2004 17:27:43 -0000      1.3
  +++ pybuiltin.pmc     29 Nov 2004 04:47:01 -0000      1.4
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pybuiltin.pmc,v 1.3 2004/11/28 17:27:43 rubys Exp $
  +$Id: pybuiltin.pmc,v 1.4 2004/11/29 04:47:01 rubys Exp $
   
   =head1 NAME
   
  @@ -25,6 +25,7 @@
   static INTVAL dynclass_PyInt;
   static INTVAL dynclass_PyFloat;
   static INTVAL dynclass_PyList;
  +static INTVAL dynclass_PyString;
   
   static STRING *HEX;
   static STRING *OCT;
  @@ -49,6 +50,7 @@
               dynclass_PyInt     = Parrot_PMC_typenum(INTERP, "PyInt");
               dynclass_PyFloat   = Parrot_PMC_typenum(INTERP, "PyFloat");
               dynclass_PyList    = Parrot_PMC_typenum(INTERP, "PyList");
  +            dynclass_PyString  = Parrot_PMC_typenum(INTERP, "PyString");
   
               HEX = const_string(INTERP, "__hex__");
               OCT = const_string(INTERP, "__oct__");
  @@ -75,11 +77,17 @@
   */
   
       METHOD void __load__() {
  -        STRING *class;
  -        PMC *stash, *iter, *pad;
  +        STRING *class, *name, *key;
  +        PMC *stash, *iter, *item, *pad, *find;
           HashBucket *b;
           INTVAL j, n;
   
  +        /* Already init'ed? */
  +        pad = scratchpad_get_current(interpreter);
  +        name = const_string(INTERP, "__name__");
  +        find = scratchpad_find(INTERP, pad, name);
  +        if (find && VTABLE_defined(INTERP, find)) return;
  +
           /* Find all PyBuiltin "nci" methods */
           class = const_string(INTERP, "PyBuiltin");
           stash = interpreter->globals->stash_hash;
  @@ -90,13 +98,17 @@
           stash = b->value;
           iter = Parrot_PerlHash_get_iter(INTERP, stash);
           n = VTABLE_elements(INTERP, stash);
  -        pad = scratchpad_get_current(interpreter);
           for (j = 0; j < n; ++j) {
  -            STRING *key = VTABLE_shift_string(INTERP, iter);
  -            PMC *item = VTABLE_get_pmc_keyed_str(INTERP, stash, key);
  +            key = VTABLE_shift_string(INTERP, iter);
  +            item = VTABLE_get_pmc_keyed_str(INTERP, stash, key);
               scratchpad_store_by_name(INTERP, pad, 0, key, item);
           }
   
  +        /* Begin main! */
  +        item = pmc_new(INTERP, dynclass_PyString);
  +        VTABLE_set_string_native(INTERP, item,
  +            const_string(INTERP, "__main__"));
  +        scratchpad_store_by_name(INTERP, pad, 0, name, item);
       }
   
   
  
  
  
  1.3       +25 -1     parrot/dynclasses/pydict.pmc
  
  Index: pydict.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pydict.pmc,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- pydict.pmc        20 Nov 2004 17:49:56 -0000      1.2
  +++ pydict.pmc        29 Nov 2004 04:47:01 -0000      1.3
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pydict.pmc,v 1.2 2004/11/20 17:49:56 rubys Exp $
  +$Id: pydict.pmc,v 1.3 2004/11/29 04:47:01 rubys Exp $
   
   =head1 NAME
   
  @@ -104,6 +104,30 @@
   
   /*
   
  +=item C<INTVAL exists_keyed(PMC *key)>
  +
  +Returns whether a key C<*key> exists in the hash.
  +
  +=cut
  +
  +*/
  +
  +    INTVAL exists_keyed(PMC* key) {
  +        STRING * sx;
  +        Hash * h = (Hash *)PMC_struct_val(SELF);
  +        HashBucket *b;
  +        sx = key_string(INTERP, key);
  +        key = key_next(INTERP, key);
  +        b = hash_get_bucket(INTERP, h, sx);
  +        if (b == NULL)
  +            return 0;       /* no such key */
  +        if (key == NULL)
  +            return 1;       /* lookup stops here */
  +        return VTABLE_exists_keyed(INTERP, (PMC*)b->value, key);
  +    }
  +
  +/*
  +
   =item C<PMC* get_iter ()>
   
   Return a new iterator for dictionary
  
  
  
  1.2       +32 -1     parrot/dynclasses/pystring.pmc
  
  Index: pystring.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/pystring.pmc,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- pystring.pmc      10 Nov 2004 01:23:21 -0000      1.1
  +++ pystring.pmc      29 Nov 2004 04:47:01 -0000      1.2
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: pystring.pmc,v 1.1 2004/11/10 01:23:21 rubys Exp $
  +$Id: pystring.pmc,v 1.2 2004/11/29 04:47:01 rubys Exp $
   
   =head1 NAME
   
  @@ -92,6 +92,37 @@
   
   /*
   
  +=item C<PMC *get_pmc_keyed_int(INTVAL key)>
  +
  +Extracts a given character from the string.
  +
  +=cut
  +
  +*/
  +
  +    PMC* get_pmc_keyed (PMC *key) {
  +        return DYNSELF.get_pmc_keyed_int(PMC_int_val(key));
  +    }
  +
  +/*
  +
  +=item C<PMC *get_pmc_keyed_int(INTVAL key)>
  +
  +Extracts a given character from the string.
  +
  +=cut
  +
  +*/
  +
  +    PMC* get_pmc_keyed_int (INTVAL key) {
  +        PMC * ret = pmc_new(INTERP, dynclass_PyString);
  +        PMC_str_val(ret) =
  +            string_substr(INTERP, PMC_str_val(SELF), key, 1, NULL, 0);
  +        return ret;
  +    }
  +
  +/*
  +
   =item C<STRING* get_repr()>
   
   Returns pythons string repr (w/o any escaping, just single quotes around)
  
  
  
  1.2       +23 -0     parrot/languages/python/README
  
  Index: README
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/README,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- README    24 Jul 2004 10:26:50 -0000      1.1
  +++ README    29 Nov 2004 04:47:02 -0000      1.2
  @@ -1,3 +1,26 @@
  +Python on Parrot is still a work in progress.  It builds upon work
  +by Leo, Dan and others (described below), and by Michal Sabren and
  +others in the Pirate project.
  +
  +The ultimate goal is to have a version of Python which is written
  +in Python and directly targets Parrot Byte Code.  This final version
  +should have no dependencies on CPython, instead it will depend on
  +Parrot and a set of Parrot PMCs which will implement the Python
  +specific behavior required.
  +
  +For now, Pirate, its tests, and the tests in this directory and those
  +in the t/dynclass directory are being used to flesh out the runtime.
  +
  +You can get the latest version of Pirate from:
  +
  +    http://pirate.tangentcode.com/
  +
  +- Sam Ruby
  +
  +Below is the previous contents of this README:
  +
  + - - -
  +
   This directory contains the outcome of the (failed) attempt to
   implement - within five weeks - enough of Python, to run the Pie-thon
   benchmark for OSCON:
  
  
  
  1.15      +5 -9      parrot/languages/python/t/basic/02_expr.t
  
  Index: 02_expr.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/t/basic/02_expr.t,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- 02_expr.t 5 Aug 2004 16:47:16 -0000       1.14
  +++ 02_expr.t 29 Nov 2004 04:47:04 -0000      1.15
  @@ -1,4 +1,4 @@
  -# $Id: 02_expr.t,v 1.14 2004/08/05 16:47:16 leo Exp $
  +# $Id: 02_expr.t,v 1.15 2004/11/29 04:47:04 rubys Exp $
   
   use strict;
   use lib '../../lib';
  @@ -127,9 +127,6 @@
       print "nok"
   CODE
   
  -SKIP: {
  -   skip("Not yet", 3);
  -
   test( <<'CODE', 'subscr' );
   print "abcde"[2]
   i =3
  @@ -145,10 +142,10 @@
   
   def main():
       for x in range(5):
  -     if x in tests:
  -         print 1,
  -     else:
  -         print 0,
  +        if x in tests:
  +            print 1,
  +        else:
  +            print 0,
       print
   
   if __name__ == '__main__':
  @@ -160,4 +157,3 @@
   print -a
   print +a - -a
   CODE
  -}
  
  
  
  1.7       +10 -17    parrot/lib/Parrot/Test/Python.pm
  
  Index: Python.pm
  ===================================================================
  RCS file: /cvs/public/parrot/lib/Parrot/Test/Python.pm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Python.pm 2 Aug 2004 13:33:12 -0000       1.6
  +++ Python.pm 29 Nov 2004 04:47:05 -0000      1.7
  @@ -9,6 +9,9 @@
   This is currently alarmingly similar to the generated subs in Parrot::Test.
   Perhaps someone can do a better job of delegation here.
   
  +Note: this current verion is based on Pirate.  Previous versions were
  +based on ast2past and versions before that on pie-thon.
  +
   =cut
   
   sub new {
  @@ -24,9 +27,8 @@
       $desc = $language unless $desc;
   
       my $lang_f = Parrot::Test::per_test('.py',$count);
  -    my $past_f = Parrot::Test::per_test('.past',$count);
       my $py_out_f = "$lang_f.out";
  -    my $past_out_f = "$past_f.out";
  +    my $pirate_out_f = Parrot::Test::per_test('.pirate.out',$count);
       my $parrotdir = dirname $self->{parrot};
   
       $TEST_PROG_ARGS = $ENV{TEST_PROG_ARGS} || '-j -Oc';
  @@ -38,35 +40,26 @@
       my $exit_code = 0;
   
       $pycmd = "python  $lang_f";
  -    $cmd = "python ast2past.py $lang_f";
  +    $cmd = "pirate $lang_f";
   
       # For some reason, if you redirect both STDERR and STDOUT here,
       # you get a 38M file of garbage. We'll temporarily assume everything
       # works and ignore stderr.
       $exit_code = Parrot::Test::_run_command($pycmd, STDOUT => $py_out_f);
       my $py_file = Parrot::Test::slurp_file($py_out_f);
  -    my $past_file;
  +    my $pirate_file;
   
       $exit_code |= Parrot::Test::_run_command($cmd,
  -         STDOUT => $past_f);
  -    if ($exit_code) {
  -     $past_file = Parrot::Test::slurp_file($past_f);
  -    }
  -    else {
  -     $cmd = $self->{relpath}. $self->{parrot} . " --python ${args} $past_f";
  -     # print STDERR "$cmd\n";
  -     $exit_code = Parrot::Test::_run_command($cmd, STDOUT => $past_out_f);
  -     $past_file = Parrot::Test::slurp_file($past_out_f);
  -    }
  -    $pass = $self->{builder}->is_eq( $past_file, $py_file, $desc );
  +         STDOUT => $pirate_out_f);
  +     $pirate_file = Parrot::Test::slurp_file($pirate_out_f);
  +    $pass = $self->{builder}->is_eq( $pirate_file, $py_file, $desc );
       $self->{builder}->diag("'$cmd' failed with exit code $exit_code")
       if $exit_code and not $pass;
   
       unless($ENV{POSTMORTEM}) {
        unlink $lang_f;
        unlink $py_out_f;
  -     unlink $past_out_f;
  -     unlink $past_f;
  +     unlink $pirate_out_f;
       }
   
       return $pass;
  
  
  

Reply via email to