cvsuser     04/09/03 03:25:10

  Modified:    classes  complex.pmc
               t/pmc    complex.t
  Log:
  new_extended for Complex PMC
  
  Revision  Changes    Path
  1.9       +55 -5     parrot/classes/complex.pmc
  
  Index: complex.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/complex.pmc,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- complex.pmc       29 Jul 2004 09:12:38 -0000      1.8
  +++ complex.pmc       3 Sep 2004 10:25:08 -0000       1.9
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2004 The Perl Foundation.  All Rights Reserved.
  -$Id: complex.pmc,v 1.8 2004/07/29 09:12:38 leo Exp $
  +$Id: complex.pmc,v 1.9 2004/09/03 10:25:08 leo Exp $
   
   =head1 NAME
   
  @@ -32,10 +32,11 @@
   complex_parse_string (Parrot_Interp interp,
           FLOATVAL *re, FLOATVAL *im, STRING *value)>
   
  -Parses the string in C<value> to produce a complex number, represented by the real
  -(C<*re>) and imaginary (C<*im>) parts. Raises an exception if it cannot understand
  -the string.
  -The string should be of the form C<a+bi> with optional spaces around C<+> and 
before C<i>. You can also use C<j> instead of C<i>.
  +Parses the string in C<value> to produce a complex number, represented
  +by the real (C<*re>) and imaginary (C<*im>) parts. Raises an exception
  +if it cannot understand the string.  The string should be of the form
  +C<a+bi> with optional spaces around C<+> and before C<i>. You can also
  +use C<j> instead of C<i>.
   
   =cut
   
  @@ -192,6 +193,55 @@
   }
   
   pmclass Complex {
  +
  +/*
  +
  +=item C<PMC* new_extended()>
  +
  +Create a new complex PMC with passed arguments according to pdd03.
  +
  +=cut
  +
  +*/
  +
  +    PMC* new_extended() {
  +        PMC *res = pmc_new(interpreter, enum_class_Complex);
  +        FLOATVAL re = 0.0, im = 0.0;
  +        int argcI = REG_INT(1);
  +        int argcS = REG_INT(2);
  +        int argcP = REG_INT(3);
  +        int argcN = REG_INT(4);
  +        /*
  +         * we can only allow 0..2 arguments of one kind. For
  +         * mixed (e.g. N,P) args the order of arguments isn't fixed
  +         */
  +        if (argcP) {
  +            re = VTABLE_get_number(INTERP, REG_PMC(5));
  +            if (argcP == 2)
  +                im = VTABLE_get_number(INTERP, REG_PMC(6));
  +            /*
  +             * TODO throw exception if argument mismatch
  +             */
  +        }
  +        else if (argcN) {
  +            re = REG_NUM(5);
  +            if (argcN == 2)
  +                im = REG_NUM(6);
  +        }
  +        else if (argcI) {
  +            re = REG_INT(5);
  +            if (argcI == 2)
  +                im = REG_INT(6);
  +        }
  +        else if (argcS == 1) {
  +            complex_parse_string(INTERP, &RE(res), &IM(res), REG_STR(5));
  +            return res;
  +        }
  +        RE(res) = re;
  +        IM(res) = im;
  +        return res;
  +    }
  +
   /*
   
   =item C<void* invoke(void* next)>
  
  
  
  1.5       +61 -2     parrot/t/pmc/complex.t
  
  Index: complex.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/complex.t,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- complex.t 22 Aug 2004 09:15:52 -0000      1.4
  +++ complex.t 3 Sep 2004 10:25:10 -0000       1.5
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: complex.t,v 1.4 2004/08/22 09:15:52 leo Exp $
  +# $Id: complex.t,v 1.5 2004/09/03 10:25:10 leo Exp $
   
   =head1 NAME
   
  @@ -16,7 +16,7 @@
   
   =cut
   
  -use Parrot::Test tests => 12;
  +use Parrot::Test tests => 16;
   use Test::More;
   
   my $fp_equality_macro = <<'ENDOFMACRO';
  @@ -549,3 +549,62 @@
   0
   OUTPUT
   
  +output_is(<< 'CODE', << 'OUTPUT', "new_extended, PASM, I");
  +    set I0, 1
  +    set I1, 2
  +    set I2, 0
  +    set I3, 0
  +    set I4, 0
  +    set I5, 10
  +    set I6, 20
  +    getclass P2, "Complex"
  +    new_extended P1
  +    print P1
  +    print "\n"
  +    end
  +CODE
  +10+20i
  +OUTPUT
  +
  +output_is(<< 'CODE', << 'OUTPUT', "new_extended, PIR, N");
  +##PIR##
  +.sub main
  +    $P0 = getclass "Complex"
  +    $P1 = $P0."new_extended"(2.0, 3.0)
  +    print $P1
  +    print "\n"
  +    end
  +.end
  +CODE
  +2+3i
  +OUTPUT
  +
  +output_is(<< 'CODE', << 'OUTPUT', "new_extended, PIR, P");
  +##PIR##
  +.sub main
  +    $P0 = getclass "Complex"
  +    $P1 = new Float
  +    $P1 = 2.0
  +    $P2 = new Float
  +    $P2 = 3.0
  +    $P1 = $P0."new_extended"($P1, $P2)
  +    print $P1
  +    print "\n"
  +    end
  +.end
  +CODE
  +2+3i
  +OUTPUT
  +
  +output_is(<< 'CODE', << 'OUTPUT', "new_extended, PIR, S");
  +##PIR##
  +.sub main
  +    $P0 = getclass "Complex"
  +    $P1 = $P0."new_extended"("2 + 3i")
  +    print $P1
  +    print "\n"
  +    end
  +.end
  +CODE
  +2+3i
  +OUTPUT
  
  
  

Reply via email to