Skip to content

Commit

Permalink
fix decrement vtable override, tests for:
Browse files Browse the repository at this point in the history
abs, decrement, div_* fdiv_*, i_abs, i_div_*, i_fdiv_*, i_mod*, i_neg, increment, mod_*, neg
  • Loading branch information
bubaflub committed Jul 5, 2011
1 parent 588f5bd commit 0d30391
Show file tree
Hide file tree
Showing 27 changed files with 594 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/GMP/Integer.pir
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,11 @@


.sub 'decrement' :method :vtable
.const 'Sub' WSubId_11 = "WSubId_11"
# Body
# {
.annotate 'line', 272
'mpz_add_si'(self, self, -1)
WSubId_11(self, self, 1)
# }
.annotate 'line', 273

Expand Down
2 changes: 1 addition & 1 deletion src/GMP/Integer.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace GMP {
}

function decrement[vtable]() {
mpz_add_si(self, self, -1);
mpz_sub_ui(self, self, 1);
}

function absolute[vtable](var dest) {
Expand Down
2 changes: 1 addition & 1 deletion src/GMP/Integer.winxed.template
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace GMP {
}

function decrement[vtable]() {
mpz_add_si(self, self, -1);
mpz_sub_ui(self, self, 1);
}

function absolute[vtable](var dest) {
Expand Down
25 changes: 25 additions & 0 deletions t/integer/vtable/abs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_abs {
function test_mpz_abs() {
var x = new GMP.Integer();
var y = new GMP.Integer(30);
${ abs x, y };
int i = mpz_get_ui(x);
self.assert.equal(i, 30);
y = new GMP.Integer(-24);
${ abs x, y };
i = mpz_get_ui(x);
self.assert.equal(i, 24);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_abs);
}
23 changes: 23 additions & 0 deletions t/integer/vtable/decrement.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_decrement {
function test_mpz_decrement() {
var x = new GMP.Integer(30);
${ dec x };
int i = mpz_get_ui(x);
self.assert.equal(i, 29);
${ dec x };
i = mpz_get_ui(x);
self.assert.equal(i, 28);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_decrement);
}
25 changes: 25 additions & 0 deletions t/integer/vtable/div.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_div {
function test_mpz_div() {
var x = new GMP.Integer();
var y = new GMP.Integer(65);
var z = new GMP.Integer(32);
${ div x, y, z};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ div x, x, y};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_div);
}
25 changes: 25 additions & 0 deletions t/integer/vtable/div_float.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_div_float {
function test_mpz_div_float() {
var x = new GMP.Integer();
var y = new GMP.Integer(65);
float z = 32.1;
${ div x, y, z};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ div x, x, z};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_div_float);
}
25 changes: 25 additions & 0 deletions t/integer/vtable/div_int.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_div_int {
function test_mpz_div_int() {
var x = new GMP.Integer();
var y = new GMP.Integer(65);
int z = 32;
${ div x, y, z};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ div x, x, z};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_div_int);
}
25 changes: 25 additions & 0 deletions t/integer/vtable/fdiv.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_fdiv {
function test_mpz_fdiv() {
var x = new GMP.Integer();
var y = new GMP.Integer(65);
var z = new GMP.Integer(32);
${ fdiv x, y, z};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ fdiv x, x, y};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_fdiv);
}
25 changes: 25 additions & 0 deletions t/integer/vtable/fdiv_float.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_fdiv_float {
function test_mpz_fdiv_float() {
var x = new GMP.Integer();
var y = new GMP.Integer(65);
float z = 32.1;
${ fdiv x, y, z};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ fdiv x, x, z};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_fdiv_float);
}
25 changes: 25 additions & 0 deletions t/integer/vtable/fdiv_int.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_fdiv_int {
function test_mpz_fdiv_int() {
var x = new GMP.Integer();
var y = new GMP.Integer(65);
int z = 32;
${ fdiv x, y, z};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ fdiv x, x, z};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_fdiv_int);
}
24 changes: 24 additions & 0 deletions t/integer/vtable/i_abs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_i_abs {
function test_mpz_i_abs() {
var x = new GMP.Integer(30);
${ abs x};
int i = mpz_get_ui(x);
self.assert.equal(i, 30);
x = new GMP.Integer(-24);
${ abs x};
i = mpz_get_ui(x);
self.assert.equal(i, 24);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_i_abs);
}
24 changes: 24 additions & 0 deletions t/integer/vtable/i_div.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_i_div {
function test_mpz_i_div() {
var x = new GMP.Integer(65);
var y = new GMP.Integer(32);
${ div x, y};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ div x, y};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_i_div);
}
24 changes: 24 additions & 0 deletions t/integer/vtable/i_div_float.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_i_div_float {
function test_mpz_i_div_float() {
var x = new GMP.Integer(65);
float y = 32.1;
${ div x, y};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ div x, y};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_i_div_float);
}
24 changes: 24 additions & 0 deletions t/integer/vtable/i_div_int.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_i_div_int {
function test_mpz_i_div_int() {
var x = new GMP.Integer(65);
int y = 32;
${ div x, y};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ div x, y};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_i_div_int);
}
24 changes: 24 additions & 0 deletions t/integer/vtable/i_fdiv.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_i_fdiv {
function test_mpz_i_fdiv() {
var x = new GMP.Integer(65);
var y = new GMP.Integer(32);
${ fdiv x, y};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ fdiv x, y};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_i_fdiv);
}
24 changes: 24 additions & 0 deletions t/integer/vtable/i_fdiv_float.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$load "rosella/test.pbc";
$load "GMP/Integer.pbc";

namespace GMP {
class Integer;
}

class Test_GMP_Vtable_i_fdiv_float {
function test_mpz_i_fdiv_float() {
var x = new GMP.Integer(65);
float y = 32.1;
${ fdiv x, y};
int i = mpz_get_ui(x);
self.assert.equal(i, 2);
${ fdiv x, y};
i = mpz_get_ui(x);
self.assert.equal(i, 0);
}
}

function main[main]() {
using Rosella.Test.test;
test(class Test_GMP_Vtable_i_fdiv_float);
}
Loading

0 comments on commit 0d30391

Please sign in to comment.