From 25e3ab8e5d8d49012c914089f9b6492d32e7dfba Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Tue, 3 Sep 2019 18:33:30 +0200 Subject: [PATCH] big map can be looked up --- src/compiler/compiler_type.ml | 8 ++++++++ src/contracts/big_map.ligo | 19 ++++++++++++++++--- src/mini_c/PP.ml | 1 + src/mini_c/types.ml | 1 + src/transpiler/transpiler.ml | 2 +- src/typer/typer.ml | 2 +- vendors/ligo-utils/simple-utils/trace.ml | 2 ++ 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/compiler/compiler_type.ml b/src/compiler/compiler_type.ml index 4596bd74d..b22a0d2ef 100644 --- a/src/compiler/compiler_type.ml +++ b/src/compiler/compiler_type.ml @@ -70,6 +70,7 @@ module Ty = struct | T_or _ -> fail (not_comparable "or") | T_pair _ -> fail (not_comparable "pair") | T_map _ -> fail (not_comparable "map") + | T_big_map _ -> fail (not_comparable "big_map") | T_list _ -> fail (not_comparable "list") | T_set _ -> fail (not_comparable "set") | T_option _ -> fail (not_comparable "option") @@ -116,6 +117,10 @@ module Ty = struct let%bind (Ex_comparable_ty k') = comparable_type k in let%bind (Ex_ty v') = type_ v in ok @@ Ex_ty (map k' v') + | T_big_map (k, v) -> + let%bind (Ex_comparable_ty k') = comparable_type k in + let%bind (Ex_ty v') = type_ v in + ok @@ Ex_ty (big_map k' v') | T_list t -> let%bind (Ex_ty t') = type_ t in ok @@ Ex_ty (list t') @@ -184,6 +189,9 @@ let rec type_ : type_value -> O.michelson result = | T_map kv -> let%bind (k', v') = bind_map_pair type_ kv in ok @@ O.prim ~children:[k';v'] O.T_map + | T_big_map kv -> + let%bind (k', v') = bind_map_pair type_ kv in + ok @@ O.prim ~children:[k';v'] O.T_big_map | T_list t -> let%bind t' = type_ t in ok @@ O.prim ~children:[t'] O.T_list diff --git a/src/contracts/big_map.ligo b/src/contracts/big_map.ligo index 2b6f97581..2eb21153e 100644 --- a/src/contracts/big_map.ligo +++ b/src/contracts/big_map.ligo @@ -1,5 +1,18 @@ -type storage_ is big_map(int, int) * unit +// type storage_ is big_map(int, int) * unit +type storage_ is big_map(int, int) + +// function main(const p : unit; const s : storage_) : list(operation) * storage_ is +// block { skip } +// with ((nil : list(operation)), s) function main(const p : unit; const s : storage_) : list(operation) * storage_ is - block { skip } - with ((nil : list(operation)), s) \ No newline at end of file + // var r : big_map(int, int) := s.0 ; + var r : big_map(int,int) := s ; + var toto : option (int) := Some(0); + block { + // r[23] := 2; + toto := r[23]; + s := r; + // skip + } + with ((nil: list(operation)), s) \ No newline at end of file diff --git a/src/mini_c/PP.ml b/src/mini_c/PP.ml index 13fb005fc..c7eab992d 100644 --- a/src/mini_c/PP.ml +++ b/src/mini_c/PP.ml @@ -27,6 +27,7 @@ let rec type_ ppf : type_value -> _ = function | T_base b -> type_base ppf b | T_function(a, b) -> fprintf ppf "(%a) -> (%a)" type_ a type_ b | T_map(k, v) -> fprintf ppf "map(%a -> %a)" type_ k type_ v + | T_big_map(k, v) -> fprintf ppf "big_map(%a -> %a)" type_ k type_ v | T_list(t) -> fprintf ppf "list(%a)" type_ t | T_set(t) -> fprintf ppf "set(%a)" type_ t | T_option(o) -> fprintf ppf "option(%a)" type_ o diff --git a/src/mini_c/types.ml b/src/mini_c/types.ml index fd0ddd021..8be621954 100644 --- a/src/mini_c/types.ml +++ b/src/mini_c/types.ml @@ -15,6 +15,7 @@ type type_value = | T_deep_closure of environment * type_value * type_value | T_base of type_base | T_map of (type_value * type_value) + | T_big_map of (type_value * type_value) | T_list of type_value | T_set of type_value | T_contract of type_value diff --git a/src/transpiler/transpiler.ml b/src/transpiler/transpiler.ml index 3c8ad1ae3..a2119fe19 100644 --- a/src/transpiler/transpiler.ml +++ b/src/transpiler/transpiler.ml @@ -115,7 +115,7 @@ let rec translate_type (t:AST.type_value) : type_value result = ok (T_map kv') | T_constant ("big_map", [key;value] ) -> let%bind kv' = bind_map_pair translate_type (key, value) in - ok (T_map kv') + ok (T_big_map kv') | T_constant ("list", [t]) -> let%bind t' = translate_type t in ok (T_list t') diff --git a/src/typer/typer.ml b/src/typer/typer.ml index 5c962cc10..6262f3971 100644 --- a/src/typer/typer.ml +++ b/src/typer/typer.ml @@ -614,7 +614,7 @@ and type_expression : environment -> ?tv_opt:O.type_value -> I.expression -> O.a return (E_application (f' , arg)) tv | E_look_up dsi -> let%bind (ds, ind) = bind_map_pair (type_expression e) dsi in - let%bind (src, dst) = get_t_map ds.type_annotation in + let%bind (src, dst) = bind_map_or (get_t_map , get_t_big_map) ds.type_annotation in let%bind _ = O.assert_type_value_eq (ind.type_annotation, src) in return (E_look_up (ds , ind)) (t_option dst ()) (* Advanced *) diff --git a/vendors/ligo-utils/simple-utils/trace.ml b/vendors/ligo-utils/simple-utils/trace.ml index 52637021e..329203a46 100644 --- a/vendors/ligo-utils/simple-utils/trace.ml +++ b/vendors/ligo-utils/simple-utils/trace.ml @@ -639,6 +639,8 @@ let bind_or (a, b) = match a with | Ok _ as o -> o | _ -> b +let bind_map_or (fa , fb) c = + bind_or (fa c , fb c) let bind_lr (type a b) ((a : a result), (b:b result)) : [`Left of a | `Right of b] result = match (a, b) with