Add is_nat operator to PascaLIGO
This commit is contained in:
parent
bdd7e5def2
commit
598fbf96ed
@ -64,6 +64,7 @@ module Simplify = struct
|
||||
("size" , "SIZE") ;
|
||||
("int" , "INT") ;
|
||||
("abs" , "ABS") ;
|
||||
("is_nat", "ISNAT") ;
|
||||
("amount" , "AMOUNT") ;
|
||||
("balance", "BALANCE") ;
|
||||
("now" , "NOW") ;
|
||||
@ -511,6 +512,10 @@ module Typer = struct
|
||||
let%bind () = assert_t_int t in
|
||||
ok @@ t_nat ()
|
||||
|
||||
let is_nat = typer_1 "ISNAT" @@ fun t ->
|
||||
let%bind () = assert_t_int t in
|
||||
ok @@ t_option (t_nat ()) ()
|
||||
|
||||
let neg = typer_1 "NEG" @@ fun t ->
|
||||
let%bind () = Assert.assert_true (eq_1 t (t_nat ()) || eq_1 t (t_int ())) in
|
||||
ok @@ t_int ()
|
||||
@ -775,6 +780,7 @@ module Typer = struct
|
||||
get_entrypoint ;
|
||||
neg ;
|
||||
abs ;
|
||||
is_nat ;
|
||||
cons ;
|
||||
now ;
|
||||
slice ;
|
||||
@ -844,6 +850,7 @@ module Compiler = struct
|
||||
("ASSERT" , simple_unary @@ i_if (seq [i_push_unit]) (seq [i_push_unit ; i_failwith])) ;
|
||||
("INT" , simple_unary @@ prim I_INT) ;
|
||||
("ABS" , simple_unary @@ prim I_ABS) ;
|
||||
("ISNAT", simple_unary @@ prim I_ISNAT) ;
|
||||
("CONS" , simple_binary @@ prim I_CONS) ;
|
||||
("UNIT" , simple_constant @@ prim I_UNIT) ;
|
||||
("BALANCE" , simple_constant @@ prim I_BALANCE) ;
|
||||
|
2
src/test/contracts/isnat.ligo
Normal file
2
src/test/contracts/isnat.ligo
Normal file
@ -0,0 +1,2 @@
|
||||
function main (const i: int) : option(nat) is
|
||||
block {skip} with is_nat(i)
|
@ -1211,6 +1211,20 @@ let balance_constant_mligo () : unit result =
|
||||
let input = e_tuple [e_unit () ; e_mutez 0] in
|
||||
let expected = e_tuple [e_list []; e_mutez 4000000000000] in
|
||||
expect_eq program "main" input expected
|
||||
|
||||
let is_nat () : unit result =
|
||||
let%bind program = type_file "./contracts/isnat.ligo" in
|
||||
let%bind () =
|
||||
let input = e_int 10 in
|
||||
let expected = e_some (e_nat 10) in
|
||||
expect_eq program "main" input expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = e_int (-10) in
|
||||
let expected = e_none () in
|
||||
expect_eq program "main" input expected
|
||||
in ok ()
|
||||
|
||||
let simple_access_ligo () : unit result =
|
||||
let%bind program = type_file "./contracts/simple_access.ligo" in
|
||||
let make_input = e_tuple [e_int 0; e_int 1] in
|
||||
@ -1313,6 +1327,7 @@ let main = test_suite "Integration (End to End)" [
|
||||
test "let multiple (mligo)" mligo_let_multiple ;
|
||||
test "balance constant" balance_constant ;
|
||||
test "balance constant (mligo)" balance_constant_mligo ;
|
||||
test "is_nat" is_nat ;
|
||||
test "simple_access (ligo)" simple_access_ligo;
|
||||
test "deep_access (ligo)" deep_access_ligo;
|
||||
test "entrypoints (ligo)" entrypoints_ligo ;
|
||||
|
Loading…
Reference in New Issue
Block a user