ligo/src/compiler/compiler_environment.ml

44 lines
962 B
OCaml
Raw Normal View History

2019-05-13 00:56:22 +04:00
open Trace
open Mini_c
open Environment
2019-05-13 16:20:23 +04:00
open Michelson
2019-05-13 00:56:22 +04:00
module Stack = Meta_michelson.Stack
let get : environment -> string -> michelson result = fun e s ->
2019-08-21 00:51:16 +04:00
let%bind (_ , position) =
2019-05-13 00:56:22 +04:00
let error =
let title () = "Environment.get" in
let content () = Format.asprintf "%s in %a"
s PP.environment e in
error title content in
generic_try error @@
(fun () -> Environment.get_i s e) in
let rec aux = fun n ->
match n with
| 0 -> i_dup
| n -> seq [
dip @@ aux (n - 1) ;
i_swap ;
]
in
let code = aux position in
ok code
let set : environment -> string -> michelson result = fun e s ->
2019-08-21 00:51:16 +04:00
let%bind (_ , position) =
2019-05-13 00:56:22 +04:00
generic_try (simple_error "Environment.get") @@
(fun () -> Environment.get_i s e) in
let rec aux = fun n ->
match n with
| 0 -> dip i_drop
| n -> seq [
i_swap ;
dip (aux (n - 1)) ;
]
in
let code = aux position in
ok code