From 0fb37e9d3f08979d63c2df3d7c4ce6b16e4f21ba Mon Sep 17 00:00:00 2001 From: galfour Date: Sun, 8 Sep 2019 12:34:29 +0200 Subject: [PATCH] adding list cons --- src/contracts/list.ligo | 4 ++++ src/operators/operators.ml | 8 ++++++++ src/test/integration_tests.ml | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/src/contracts/list.ligo b/src/contracts/list.ligo index 99920b92a..a533d12e2 100644 --- a/src/contracts/list.ligo +++ b/src/contracts/list.ligo @@ -5,6 +5,10 @@ const fb : foobar = list 42 ; end +const fb2 : foobar = 144 # fb + +const fb3 : foobar = cons(688 , fb2) + function size_ (const m : foobar) : nat is block {skip} with (size(m)) diff --git a/src/operators/operators.ml b/src/operators/operators.ml index cdf983b6a..61495e0e9 100644 --- a/src/operators/operators.ml +++ b/src/operators/operators.ml @@ -88,6 +88,7 @@ module Simplify = struct ("sha_256" , "SHA256") ; ("sha_512" , "SHA512") ; ("blake2b" , "BLAKE2b") ; + ("cons" , "CONS") ; ] let type_constants = type_constants @@ -228,6 +229,11 @@ module Typer = struct let some = typer_1 "SOME" @@ fun a -> ok @@ t_option a () + let list_cons : typer = typer_2 "CONS" @@ fun hd tl -> + let%bind tl' = get_t_list tl in + let%bind () = assert_type_value_eq (hd , tl') in + ok tl + let map_remove : typer = typer_2 "MAP_REMOVE" @@ fun k m -> let%bind (src , _) = get_t_map m in let%bind () = assert_type_value_eq (src , k) in @@ -617,6 +623,7 @@ module Typer = struct slice ; address ; assertion ; + list_cons ; ] end @@ -691,6 +698,7 @@ module Compiler = struct ("HASH_KEY" , simple_unary @@ prim I_HASH_KEY) ; ("PACK" , simple_unary @@ prim I_PACK) ; ("CONCAT" , simple_binary @@ prim I_CONCAT) ; + ("CONS" , simple_binary @@ prim I_CONS) ; ] (* Some complex predicates will need to be added in compiler/compiler_program *) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 4432f07b9..baea8d256 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -402,6 +402,14 @@ let list () : unit result = let expected = ez [23 ; 42] in expect_eq_evaluate program "fb" expected in + let%bind () = + let expected = ez [144 ; 23 ; 42] in + expect_eq_evaluate program "fb2" expected + in + let%bind () = + let expected = ez [688 ; 144 ; 23 ; 42] in + expect_eq_evaluate program "fb3" expected + in let%bind () = let make_input = fun n -> (ez @@ List.range n) in let make_expected = e_nat in