More tests, integration of some of the operators

This commit is contained in:
Georges Dupéron 2019-06-11 01:27:59 +02:00 committed by Suzanne Dupéron
parent 8c37fe355d
commit 606f7ca907
6 changed files with 73 additions and 2 deletions

View File

@ -0,0 +1,5 @@
let%entry main (i : int) =
if (i = 2 : bool) then
(42 : int)
else
(0 : int)

View File

@ -0,0 +1,9 @@
(* TODO : make a test using mutation, not shadowing *)
let%entry main (i : int) =
let result = 0 in
if i = 2 then
let result = 42 in
result
else
let result = 0 in
result

View File

@ -0,0 +1,5 @@
let%entry main (i : int) =
if i = 2 then
42
else
0

12
src/contracts/fibo.mligo Normal file
View File

@ -0,0 +1,12 @@
type storage = unit
(* not supported yet
let%entry main (p:unit) storage =
(fun x -> ()) ()
*)
let%entry main (p:unit) storage =
(fun (f : int -> int -> int) (x : int) (y : int) -> f y (x + y))
(fun (x : int) (y : int) -> x + y)
0
1

View File

@ -103,9 +103,20 @@ module Simplify = struct
module Camligo = struct
let constants = [
("Bytes.pack" , "PACK") ;
("Map.remove" , "MAP_REMOVE") ;
("Map.update" , "MAP_UPDATE") ;
("Map.add" , "MAP_ADD") ;
("Map.mem" , "MAP_MEM") ;
("Map.find" , "MAP_FIND") ;
("Map.fold" , "MAP_FOLD") ;
("Map.map" , "MAP_MAP") ;
("Crypto.hash" , "HASH") ;
("Operation.transaction" , "CALL") ;
("Operation.get_contract" , "CONTRACT") ;
("sender" , "SENDER") ;
("unit" , "UNIT") ;
("source" , "SOURCE") ;
@ -704,6 +715,13 @@ module Compiler = struct
("MAP_FIND_OPT" , simple_binary @@ prim I_GET) ;
("MAP_ADD" , simple_ternary @@ seq [dip (i_some) ; prim I_UPDATE]) ;
("MAP_UPDATE" , simple_ternary @@ prim I_UPDATE) ;
(* ("GET_CONTRACT" , simple_constant @@ prim I_CONTRACT) ; *)
(* ( "MAP_REMOVE" , simple_binary @@ seq [prim I_NONE TODO: + annotation ; prim I_UPDATE ]) ; *)
( "MAP_MEM" , simple_binary @@ prim I_MEM) ;
(* ( "MAP_FOLD" , simple_ternary @@ prim TODO I_ITER?) ; *)
( "MAP_MAP" , simple_binary @@ prim I_MAP) ;
(* ( "MAP_MAP_FOLD" , simple_ternary @@ prim TODO I_ITER?) ; *)
(* ( "MAP_ITER" , simple_binary @@ prim TODO I_ITER?) ; *)
("SIZE" , simple_unary @@ prim I_SIZE) ;
("FAILWITH" , simple_unary @@ prim I_FAILWITH) ;
("ASSERT_INFERRED" , simple_binary @@ i_if (seq [i_failwith]) (seq [i_drop ; i_push_unit])) ;

View File

@ -533,6 +533,20 @@ let condition () : unit result =
let make_expected = fun n -> e_int (if n = 2 then 42 else 0) in
expect_eq_n program "main" make_input make_expected
let condition_mligo () : unit result =
let%bind _ =
let aux file =
let%bind program = mtype_file file in
let make_input = e_int in
let make_expected = fun n -> e_int (if n = 2 then 42 else 0) in
expect_eq_n program "main" make_input make_expected in
bind_map_list aux [
"./contracts/condition.mligo";
"./contracts/condition-shadowing.mligo";
"./contracts/condition-annot.mligo";
] in
ok ()
let condition_simple () : unit result =
let%bind program = type_file "./contracts/condition-simple.ligo" in
let make_input = e_int in
@ -794,6 +808,12 @@ let lambda2_mligo () : unit result =
let make_expected = (e_unit ()) in
expect_eq program "main" make_input make_expected
let fibo_mligo () : unit result =
let%bind program = mtype_file "./contracts/fibo.mligo" in
let make_input = e_pair (e_unit ()) (e_unit ()) in
let make_expected = (e_int 42) in
expect_eq program "main" make_input make_expected
let website1_ligo () : unit result =
let%bind program = type_file "./contracts/website1.ligo" in
let make_input = fun n-> e_pair (e_int n) (e_int 42) in
@ -851,7 +871,8 @@ let main = test_suite "Integration (End to End)" [
test "tuple" tuple ;
test "record" record ;
test "condition simple" condition_simple ;
test "condition" condition ;
test "condition (ligo)" condition ;
test "condition (mligo)" condition_mligo ;
test "shadow" shadow ;
test "annotation" annotation ;
test "multiple parameters" multiple_parameters ;
@ -893,9 +914,10 @@ let main = test_suite "Integration (End to End)" [
(* test "guess string mligo" guess_string_mligo ; WIP? *)
test "lambda mligo" lambda_mligo ;
test "lambda ligo" lambda_ligo ;
(* test "lambda2 mligo" lambda2_mligo ; *)
test "tez (ligo)" tez_ligo ;
test "tez (mligo)" tez_mligo ;
test "lambda2 mligo" lambda2_mligo ;
(* test "fibo (mligo)" fibo_mligo ; *)
test "website1 ligo" website1_ligo ;
test "website2 ligo" website2_ligo ;
test "website2 (mligo)" website2_mligo ;