cvsuser     03/01/08 14:35:03

  Modified:    .        MANIFEST core.ops
  Added:       t/op     arithmetics.t
  Log:
  More arthmetic ops. With tests no less. Yay!
  
  Courtesy of Bernhard Schmalhof <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.302     +1 -0      parrot/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  RCS file: /cvs/public/parrot/MANIFEST,v
  retrieving revision 1.301
  retrieving revision 1.302
  diff -u -w -r1.301 -r1.302
  --- MANIFEST  3 Jan 2003 15:19:32 -0000       1.301
  +++ MANIFEST  8 Jan 2003 22:35:01 -0000       1.302
  @@ -1710,6 +1710,7 @@
   sub.c
   testyamd
   t/harness
  +t/op/arithmetics.t
   t/op/basic.t
   t/op/bitwise.t
   t/op/comp.t
  
  
  
  1.244     +135 -7    parrot/core.ops
  
  Index: core.ops
  ===================================================================
  RCS file: /cvs/public/parrot/core.ops,v
  retrieving revision 1.243
  retrieving revision 1.244
  diff -u -w -r1.243 -r1.244
  --- core.ops  4 Jan 2003 11:34:51 -0000       1.243
  +++ core.ops  8 Jan 2003 22:35:01 -0000       1.244
  @@ -1279,6 +1279,8 @@
   
   =item B<add>(inout INT, in INT)
   
  +=item B<add>(inout NUM, in INT)
  +
   =item B<add>(inout NUM, in NUM)
   
   =item B<add>(inout PMC, in INT)
  @@ -1291,10 +1293,14 @@
   
   =item B<add>(out INT, in INT, in INT)
   
  +=item B<add>(out NUM, in NUM, in INT)
  +
   =item B<add>(out NUM, in NUM, in NUM)
   
   =item B<add>(inout PMC, in PMC, in INT)
   
  +=item B<add>(inout PMC, in PMC, in NUM)
  +
   =item B<add>(inout PMC, in PMC, in PMC)
   
   Set $1 to the sum of $2 and $3.
  @@ -1306,6 +1312,11 @@
     goto NEXT();
   }
   
  +inline op add(inout NUM, in INT) {
  +  $1 += $2;
  +  goto NEXT();
  +}
  +
   inline op add(inout NUM, in NUM) {
     $1 += $2;
     goto NEXT();
  @@ -1331,6 +1342,11 @@
     goto NEXT();
   }
   
  +inline op add(out NUM, in NUM, in INT) {
  +  $1 = $2 + $3;
  +  goto NEXT();
  +}
  +
   inline op add(out NUM, in NUM, in NUM) {
     $1 = $2 + $3;
     goto NEXT();
  @@ -1341,6 +1357,11 @@
     goto NEXT();
   }
   
  +inline op add(inout PMC, in PMC, in NUM) {
  +  $2->vtable->add_float(interpreter, $2, $3, $1);
  +  goto NEXT();
  +}
  +
   inline op add (inout PMC, in PMC, in PMC) {
     $2->vtable->add(interpreter, $2, $3, $1);
     goto NEXT();
  @@ -1456,40 +1477,91 @@
   
   ########################################
   
  +=item B<div>(inout INT, in INT)
  +
  +=item B<div>(inout NUM, in INT)
  +
  +=item B<div>(inout NUM, in NUM)
  +
  +=item B<div>(inout PMC, in INT)
  +
  +=item B<div>(inout PMC, in NUM)
  +
  +=item B<div>(inout PMC, in PMC)
  +
  +Divide $1 by $2. 
  +
   =item B<div>(out INT, in INT, in INT)
   
  +=item B<div>(out NUM, in NUM, in INT)
  +
   =item B<div>(out NUM, in NUM, in NUM)
   
  -=item B<div>(inout PMC, in PMC, in PMC)
  +=item B<div>(inout PMC, in PMC, in INT)
   
  -=item B<div>(inout PMC, in INT)
  +=item B<div>(inout PMC, in PMC, in NUM)
  +
  +=item B<div>(inout PMC, in PMC, in PMC)
   
   Set $1 to the quotient of $2 divided by $3. In the case of INTVAL division, the
   result is truncated (NOT rounded or floored).
   
   =cut
   
  +inline op div(inout INT, in INT) {
  +  $1 /= $2;
  +  goto NEXT();
  +}
  +
  +inline op div(inout NUM, in INT) {
  +  $1 /= $2;
  +  goto NEXT();
  +}
  +
  +inline op div(inout NUM, in NUM) {
  +  $1 /= $2;
  +  goto NEXT();
  +}
  +
  +inline op div (inout PMC, in INT) {
  +  $1->vtable->divide_int(interpreter, $1, $2, $1);
  +  goto NEXT();
  +}
  +
  +inline op div (inout PMC, in NUM) {
  +  $1->vtable->divide_float(interpreter, $1, $2, $1);
  +  goto NEXT();
  +}
  +
   inline op div(out INT, in INT, in INT) {
     $1 = $2 / $3;
     goto NEXT();
   }
   
  -inline op div(out NUM, in NUM, in NUM) {
  +inline op div(out NUM, in NUM, in INT) {
     $1 = $2 / $3;
     goto NEXT();
   }
   
  -inline op div (inout PMC, in PMC, in PMC) {
  -  $2->vtable->divide(interpreter, $2, $3, $1);
  +inline op div(out NUM, in NUM, in NUM) {
  +  $1 = $2 / $3;
     goto NEXT();
   }
   
  -inline op div (inout PMC, in INT) {
  -  $1->vtable->divide_int(interpreter, $1, $2, $1);
  +inline op div (inout PMC, in PMC, in INT) {
  +  $2->vtable->divide_int(interpreter, $2, $3, $1);
     goto NEXT();
   }
   
  +inline op div (inout PMC, in PMC, in NUM) {
  +  $2->vtable->divide_float(interpreter, $2, $3, $1);
  +  goto NEXT();
  +}
   
  +inline op div (inout PMC, in PMC, in PMC) {
  +  $2->vtable->divide(interpreter, $2, $3, $1);
  +  goto NEXT();
  +}
   
   ########################################
   
  @@ -1631,18 +1703,28 @@
   
   =item B<mul>(inout INT, in INT)
   
  +=item B<mul>(inout NUM, in INT)
  +
   =item B<mul>(inout NUM, in NUM)
   
   =item B<mul>(inout PMC, in INT)
   
  +=item B<mul>(inout PMC, in NUM)
  +
   =item B<mul>(inout PMC, in PMC)
   
   Set $1 to the product of $1 and $2.
   
   =item B<mul>(out INT, in INT, in INT)
   
  +=item B<mul>(out NUM, in NUM, in INT)
  +
   =item B<mul>(out NUM, in NUM, in NUM)
   
  +=item B<mul>(inout PMC, in PMC, in INT)
  +
  +=item B<mul>(inout PMC, in PMC, in NUM)
  +
   =item B<mul>(inout PMC, in PMC, in PMC)
   
   Set $1 to the product of $2 and $3.
  @@ -1654,6 +1736,11 @@
     goto NEXT();
   }
   
  +inline op mul(inout NUM, in INT) {
  +  $1 *= $2;
  +  goto NEXT();
  +}
  +
   inline op mul(inout NUM, in NUM) {
     $1 *= $2;
     goto NEXT();
  @@ -1664,6 +1751,11 @@
     goto NEXT();
   }
   
  +inline op mul ( inout PMC, in NUM ) {
  +  $1->vtable->multiply_float(interpreter, $1, $2, $1);
  +  goto NEXT();
  +}
  +
   inline op mul (inout PMC, in PMC) {
     $1->vtable->multiply(interpreter, $1, $2, $1);
     goto NEXT();
  @@ -1674,11 +1766,26 @@
     goto NEXT();
   }
   
  +inline op mul(out NUM, in NUM, in INT) {
  +  $1 = $2 * $3;
  +  goto NEXT();
  +}
  +
   inline op mul(out NUM, in NUM, in NUM) {
     $1 = $2 * $3;
     goto NEXT();
   }
   
  +inline op mul (inout PMC, in PMC, in INT) {
  +  $2->vtable->multiply_int(interpreter, $2, $3, $1);
  +  goto NEXT();
  +}
  +
  +inline op mul (inout PMC, in PMC, in NUM) {
  +  $2->vtable->multiply_float(interpreter, $2, $3, $1);
  +  goto NEXT();
  +}
  +
   inline op mul (inout PMC, in PMC, in PMC) {
     $2->vtable->multiply(interpreter, $2, $3, $1);
     goto NEXT();
  @@ -1774,6 +1881,8 @@
   
   =item B<sub>(inout INT, in INT)
   
  +=item B<sub>(inout NUM, in INT)
  +
   =item B<sub>(inout NUM, in NUM)
   
   =item B<sub>(inout PMC, in INT)
  @@ -1786,10 +1895,14 @@
   
   =item B<sub>(out INT, in INT, in INT)
   
  +=item B<sub>(out NUM, in NUM, in INT)
  +
   =item B<sub>(out NUM, in NUM, in NUM)
   
   =item B<sub>(inout PMC, in PMC, in INT)
   
  +=item B<sub>(inout PMC, in PMC, in NUM)
  +
   =item B<sub>(inout PMC, in PMC, in PMC)
   
   Set $1 to $2 minus $3.
  @@ -1801,6 +1914,11 @@
     goto NEXT();
   }
   
  +inline op sub(inout NUM, in INT) {
  +  $1 -= $2;
  +  goto NEXT();
  +}
  +
   inline op sub(inout NUM, in NUM) {
     $1 -= $2;
     goto NEXT();
  @@ -1826,6 +1944,11 @@
     goto NEXT();
   }
   
  +inline op sub(out NUM, in NUM, in INT) {
  +  $1 = $2 - $3;
  +  goto NEXT();
  +}
  +
   inline op sub(out NUM, in NUM, in NUM) {
     $1 = $2 - $3;
     goto NEXT();
  @@ -1833,6 +1956,11 @@
   
   inline op sub(inout PMC, in PMC, in INT) {
     $2->vtable->subtract_int(interpreter, $2, $3, $1);
  +  goto NEXT();
  +}
  +
  +inline op sub(inout PMC, in PMC, in NUM) {
  +  $2->vtable->subtract_float(interpreter, $2, $3, $1);
     goto NEXT();
   }
   
  
  
  
  1.1                  parrot/t/op/arithmetics.t
  
  Index: arithmetics.t
  ===================================================================
  #! perl -w
  
  use Parrot::Test tests => 26;
  use Test::More;
  use Parrot::PMC qw(%pmc_types);
  my $max_pmc = scalar(keys(%pmc_types)) + 1;
  
  my $fp_equality_macro = <<'ENDOFMACRO';
  .macro fp_eq (        J, K, L )
        save    N0
        save    N1
        save    N2
  
        set     N0, .J
        set     N1, .K
        sub     N2, N1,N0
        abs     N2, N2
        gt      N2, 0.000001, .$FPEQNOK
  
        restore N2
        restore N1
        restore N0
        branch  .L
  .local $FPEQNOK:
        restore N2
        restore N1
        restore N0
  .endm
  .macro fp_ne( J,K,L)
        save    N0
        save    N1
        save    N2
  
        set     N0, .J
        set     N1, .K
        sub     N2, N1,N0
        abs     N2, N2
        lt      N2, 0.000001, .$FPNENOK
  
        restore N2
        restore N1
        restore N0
        branch  .L
  .local $FPNENOK:
        restore N2
        restore N1
        restore N0
  .endm
  ENDOFMACRO
  
  
  output_is(<<'CODE', <<'OUTPUT', "availability of PerlInt");
        print "starting\n"
        new P0, .PerlInt
        print "ending\n"
        end
  CODE
  starting
  ending
  OUTPUT
  
  output_is(<<'CODE', <<'OUTPUT', "availability of PerlNum");
        print "starting\n"
        new P0, .PerlNum
        print "ending\n"
        end
  CODE
  starting
  ending
  OUTPUT
  
  #
  # INTVAL and INTVAL tests
  #
  output_is(<<'CODE', <<OUTPUT, "add native integer to native integer");
        set I0, 4000
        set I1, -123
        add I2, I0, I1
        print I2
        print "\n"
        add I0, I0, I1
        print I0
        print "\n"
        end
  CODE
  3877
  3877
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "subtract native integer from native integer");
        set I0, 4000
        set I1, -123
        sub I2, I0, I1
        print I2
        print "\n"
        sub I0, I0, I1
        print I0
        print "\n"
        end
  CODE
  4123
  4123
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "multiply native integer with native integer");
        set I0, 4000
        set I1, -123
        mul I2, I0, I1
        print I2
        print "\n"
        mul I0, I0, I1
        print I0
        print "\n"
        end
  CODE
  -492000
  -492000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "divide native integer by native integer"); 
        set I0, 4000
        set I1, -123
        div I2, I0, I1
        print I2
        print "\n"
        div I0, I0, I1
        print I0
        print "\n"
        end
  CODE
  -32
  -32
  OUTPUT
  
  #
  # FLOATVAL and INTVAL tests
  #
  output_is(<<'CODE', <<OUTPUT, "add native integer to native number");
        set I0, 4000
        set N0, -123.123
        add N1, N0, I0
        print N1
        print "\n"
        add N0, N0, I0
        print N0
        print "\n"
        end
  CODE
  3876.877000
  3876.877000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "subtract native integer from native number");
        set I0, 4000
        set N0, -123.123
        sub N1, N0, I0
        print N1
        print "\n"
        sub N0, N0, I0
        print N0
        print "\n"
        end
  CODE
  -4123.123000
  -4123.123000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "multiply native number with native integer");
        set I0, 4000
        set N0, -123.123
        mul N1, N0, I0
        print N1
        print "\n"
        mul N0, N0, I0
        print N0
        print "\n"
        end
  CODE
  -492492.000000
  -492492.000000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "divide native number by native integer"); 
        set I0, 4000
        set N0, -123.123
        div N1, N0, I0
        print N1
        print "\n"
        div N0, N0, I0
        print N0
        print "\n"
        end
  CODE
  -0.030781
  -0.030781
  OUTPUT
  
  #
  # FLOATVAL and FLOATVAL tests
  #
  output_is(<<'CODE', <<OUTPUT, "add native number to native number");
        set N2, 4000.246
        set N0, -123.123
        add N1, N0, N2
        print N1
        print "\n"
        add N0, N0, N2
        print N0
        print "\n"
        end
  CODE
  3877.123000
  3877.123000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "subtract native number from native number");
        set N2, 4000.246
        set N0, -123.123
        sub N1, N0, N2
        print N1
        print "\n"
        sub N0, N0, N2
        print N0
        print "\n"
        end
  CODE
  -4123.369000
  -4123.369000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "multiply native number with native number");
        set N2, 4000.246
        set N0, -123.123
        mul N1, N0, N2
        print N1
        print "\n"
        mul N0, N0, N2
        print N0
        print "\n"
        end
  CODE
  -492522.288258
  -492522.288258
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "divide native number by native number"); 
        set N2, 4000.246
        set N0, -123.123
        div N1, N0, N2
        print N1
        print "\n"
        div N0, N0, N2
        print N0
        print "\n"
        end
  CODE
  -0.030779
  -0.030779
  OUTPUT
  
  #
  # PerlInt and INTVAL tests
  #
  output_is(<<'CODE', <<OUTPUT, "add native integer to PerlInt");
        new P0, .PerlInt
        new P1, .PerlInt
        set I0, 4000
        set P0, 123
        add P1, P0, I0
        print P1
        print "\n"
        add P0, P0, I0
        print P0
        print "\n"
        end
  CODE
  4123
  4123
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "subtract native integer from PerlInt");
        new P0, .PerlInt
        new P1, .PerlInt
        set I0, 4000
        set P0, 123
        sub P1, P0, I0
        print P1
        print "\n"
        sub P0, P0, I0
        print P0
        print "\n"
        end
  CODE
  -3877
  -3877
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "multiply PerlInt with native integer");
        new P0, .PerlInt
        new P1, .PerlInt
        set I0, 4000
        set P0, 123
        mul P1, P0, I0
        print P1
        print "\n"
        mul P0, P0, I0
        print P0
        print "\n"
        end
  CODE
  492000
  492000
  OUTPUT
  
  output_is(<<"CODE", <<OUTPUT, "divide PerlInt by native integer");
  @{[ $fp_equality_macro ]}
        new P0, .PerlInt
        set I0, 4000
        set P0, 123
        div P0, P0, I0
        .fp_eq( P0, 0.03075, EQ1)
        print P0
        print "not "
  EQ1:  print "ok 1"
        print "\\n"
        end
  CODE
  ok 1
  OUTPUT
  
  #
  # PerlInt and FLOATVAL, tests
  #
  output_is(<<'CODE', <<OUTPUT, "add native number to integer");
        new P0, .PerlInt
        new P1, .PerlInt
        set N0, 4000.04
        set P0, 123
        add P1, P0, N0
        print P1
        print "\n"
        add P0, P0, N0
        print P1
        print "\n"
  CODE
  4123.040000
  4123.040000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "subtract native number from integer");
        new P0, .PerlInt
        new P1, .PerlInt
        set N0, 4000.04
        set P0, 123
        sub P1, P0, N0
        print P1
        print "\n"
        sub P0, P0, N0
        print P0
        print "\n"
        end
  CODE
  -3877.040000
  -3877.040000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "multiply integer with native number");
        new P0, .PerlInt
        new P1, .PerlInt
        set N0, 4000.04
        set P0, 123
        mul P1, P0, N0
        print P1
        print "\n"
        mul P0, P0, N0
        print P0
        print "\n"
        end
  CODE
  492004.920000
  492004.920000
  OUTPUT
  
  output_is(<<"CODE", <<OUTPUT, "divide integer by native number");
  @{[ $fp_equality_macro ]}
        new P0, .PerlInt
        set N0, 4000
        set P0, 123
        div P0, P0, N0
  
        .fp_eq( P0, 0.03074969250307496925, EQ1)
        print P0
        print "not "
  EQ1:  print "ok 1"
        print "\\n"
        end
  CODE
  ok 1
  OUTPUT
  
  #
  # PerlNum and PerlNum, tests
  #
  output_is(<<'CODE', <<OUTPUT, "add PerlNum to PerlNum");
        new P0, .PerlNum
        new P1, .PerlNum
        set P1, 4000.04
        set P0, 123
        add P0, P0, P1
        print P0
        print "\n"
        end
  CODE
  4123.040000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "subtract PerlNum from PerlNum");
        new P0, .PerlNum
        new P1, .PerlNum
        set P1, 4000.04
        set P0, 123
        sub P0, P0, P1
        print P0
        print "\n"
        end
  CODE
  -3877.040000
  OUTPUT
  
  output_is(<<'CODE', <<OUTPUT, "multiply PerlNum with PerlNum");
        new P0, .PerlNum
        new P1, .PerlNum
        set P1, 4000.04
        set P0, 123
        mul P0, P0, P1
        print P0
        print "\n"
        end
  CODE
  492004.920000
  OUTPUT
  
  output_is(<<"CODE", <<OUTPUT, "divide PerlNum by PerlNum");
  @{[ $fp_equality_macro ]}
        new P0, .PerlNum
        new P1, .PerlNum
        set P1, 4000
        set P0, 123
        div P0, P0, P1
  
        .fp_eq( P0, 0.03074969250307496925, EQ1)
        print P0
        print "not "
  EQ1:  print "ok 1"
        print "\\n"
        end
  CODE
  ok 1
  OUTPUT
  
  
  


Reply via email to