From d87d0aab73136e76f4bf5032b7341dfc6be80f1d Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Fri, 11 Oct 2019 14:35:23 -0500 Subject: [PATCH 1/2] Expose tez/tez division --- src/passes/operators/operators.ml | 2 ++ src/test/contracts/tez.ligo | 10 +++++++++- src/test/integration_tests.ml | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 15ed4928a..abd34903b 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -438,6 +438,8 @@ module Typer = struct then ok @@ t_int () else if eq_1 a (t_tez ()) && eq_1 b (t_nat ()) then ok @@ t_tez () else + if eq_1 a (t_tez ()) && eq_1 b (t_tez ()) + then ok @@ t_nat () else simple_fail "Dividing with wrong types" let mod_ = typer_2 "MOD" @@ fun a b -> diff --git a/src/test/contracts/tez.ligo b/src/test/contracts/tez.ligo index cf487808d..190951d56 100644 --- a/src/test/contracts/tez.ligo +++ b/src/test/contracts/tez.ligo @@ -1,4 +1,12 @@ const add_tez : tez = 21mtz + 0.000021tz; const sub_tez : tez = 21mtz - 20mtz; -(* is this enough? *) +(* This is not enough. *) const not_enough_tez : tez = 4611686018427387903mtz; + + +const nat_mul_tez : tez = 1n * 100mtz; +const tez_mul_nat : tez = 100mtz * 10n; + +const tez_div_tez1 : nat = 100mtz / 1mtz; +const tez_div_tez2 : nat = 100mtz / 90mtz; +const tez_div_tez3 : nat = 100mtz / 110mtz; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 7a50ad29b..4b73b0b33 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -829,6 +829,11 @@ let tez_ligo () : unit result = let%bind _ = expect_eq_evaluate program "add_tez" (e_mutez 42) in let%bind _ = expect_eq_evaluate program "sub_tez" (e_mutez 1) in let%bind _ = expect_eq_evaluate program "not_enough_tez" (e_mutez 4611686018427387903) in + let%bind _ = expect_eq_evaluate program "nat_mul_tez" (e_mutez 100) in + let%bind _ = expect_eq_evaluate program "tez_mul_nat" (e_mutez 1000) in + let%bind _ = expect_eq_evaluate program "tez_div_tez1" (e_nat 100) in + let%bind _ = expect_eq_evaluate program "tez_div_tez2" (e_nat 1) in + let%bind _ = expect_eq_evaluate program "tez_div_tez3" (e_nat 0) in ok () let tez_mligo () : unit result = From e672d10029560f206567edef154af4333ba5999f Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Fri, 11 Oct 2019 14:54:22 -0500 Subject: [PATCH 2/2] Expose tez mod tez, too --- src/passes/operators/operators.ml | 2 ++ src/test/contracts/tez.ligo | 4 ++++ src/test/integration_tests.ml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index abd34903b..65b55c18e 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -445,6 +445,8 @@ module Typer = struct let mod_ = typer_2 "MOD" @@ fun a b -> if (eq_1 a (t_nat ()) || eq_1 a (t_int ())) && (eq_1 b (t_nat ()) || eq_1 b (t_int ())) then ok @@ t_nat () else + if eq_1 a (t_tez ()) && eq_1 b (t_tez ()) + then ok @@ t_tez () else simple_fail "Computing modulo with wrong types" let add = typer_2 "ADD" @@ fun a b -> diff --git a/src/test/contracts/tez.ligo b/src/test/contracts/tez.ligo index 190951d56..cd76c47c7 100644 --- a/src/test/contracts/tez.ligo +++ b/src/test/contracts/tez.ligo @@ -10,3 +10,7 @@ const tez_mul_nat : tez = 100mtz * 10n; const tez_div_tez1 : nat = 100mtz / 1mtz; const tez_div_tez2 : nat = 100mtz / 90mtz; const tez_div_tez3 : nat = 100mtz / 110mtz; + +const tez_mod_tez1 : tez = 100mtz mod 1mtz; +const tez_mod_tez2 : tez = 100mtz mod 90mtz; +const tez_mod_tez3 : tez = 100mtz mod 110mtz; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 4b73b0b33..94f0755a6 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -834,6 +834,9 @@ let tez_ligo () : unit result = let%bind _ = expect_eq_evaluate program "tez_div_tez1" (e_nat 100) in let%bind _ = expect_eq_evaluate program "tez_div_tez2" (e_nat 1) in let%bind _ = expect_eq_evaluate program "tez_div_tez3" (e_nat 0) in + let%bind _ = expect_eq_evaluate program "tez_mod_tez1" (e_mutez 0) in + let%bind _ = expect_eq_evaluate program "tez_mod_tez2" (e_mutez 10) in + let%bind _ = expect_eq_evaluate program "tez_mod_tez3" (e_mutez 100) in ok () let tez_mligo () : unit result =