use dig/dug for get/set
This commit is contained in:
parent
56269231b3
commit
8a4b9695e7
@ -14,31 +14,46 @@ let get : environment -> string -> michelson result = fun e s ->
|
|||||||
error title content in
|
error title content in
|
||||||
generic_try error @@
|
generic_try error @@
|
||||||
(fun () -> Environment.get_i s e) in
|
(fun () -> Environment.get_i s e) in
|
||||||
let rec aux = fun n ->
|
let rec aux_bubble = fun n ->
|
||||||
match n with
|
match n with
|
||||||
| 0 -> i_dup
|
| 0 -> i_dup
|
||||||
| n -> seq [
|
| n -> seq [
|
||||||
dip @@ aux (n - 1) ;
|
dip @@ aux_bubble (n - 1) ;
|
||||||
i_swap ;
|
i_swap ;
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
let code = aux position in
|
let aux_dig = fun n -> seq [
|
||||||
|
dipn n i_dup ;
|
||||||
|
i_dig n ;
|
||||||
|
]
|
||||||
|
in
|
||||||
|
let code =
|
||||||
|
if position < 2
|
||||||
|
then aux_bubble position
|
||||||
|
else aux_dig position in
|
||||||
|
|
||||||
ok code
|
ok code
|
||||||
|
|
||||||
let set : environment -> string -> michelson result = fun e s ->
|
let set : environment -> string -> michelson result = fun e s ->
|
||||||
let%bind (_ , position) =
|
let%bind (_ , position) =
|
||||||
generic_try (simple_error "Environment.get") @@
|
generic_try (simple_error "Environment.set") @@
|
||||||
(fun () -> Environment.get_i s e) in
|
(fun () -> Environment.get_i s e) in
|
||||||
let rec aux = fun n ->
|
let rec aux_bubble = fun n ->
|
||||||
match n with
|
match n with
|
||||||
| 0 -> dip i_drop
|
| 0 -> dip i_drop
|
||||||
| n -> seq [
|
| n -> seq [
|
||||||
i_swap ;
|
i_swap ;
|
||||||
dip (aux (n - 1)) ;
|
dip (aux_bubble (n - 1)) ;
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
let code = aux position in
|
let aux_dug = fun n -> seq [
|
||||||
|
dipn (n + 1) i_drop ;
|
||||||
|
i_dug n ;
|
||||||
|
] in
|
||||||
|
let code =
|
||||||
|
if position < 2
|
||||||
|
then aux_bubble position
|
||||||
|
else aux_dug position in
|
||||||
|
|
||||||
ok code
|
ok code
|
||||||
|
|
||||||
|
@ -67,6 +67,9 @@ let i_assert_some = i_if_none (seq [i_push_string "ASSERT_SOME" ; i_failwith]) (
|
|||||||
let i_assert_some_msg msg = i_if_none (seq [msg ; i_failwith]) (seq [])
|
let i_assert_some_msg msg = i_if_none (seq [msg ; i_failwith]) (seq [])
|
||||||
|
|
||||||
let dip code : michelson = prim ~children:[seq [code]] I_DIP
|
let dip code : michelson = prim ~children:[seq [code]] I_DIP
|
||||||
|
let dipn n code = prim ~children:[Int (0 , Z.of_int n) ; seq [code]] I_DIP
|
||||||
|
let i_dig n : michelson = prim ~children:[Int (0 , Z.of_int n)] I_DIG
|
||||||
|
let i_dug n : michelson = prim ~children:[Int (0 , Z.of_int n)] I_DUG
|
||||||
let i_unpair = seq [i_dup ; i_car ; dip i_cdr]
|
let i_unpair = seq [i_dup ; i_car ; dip i_cdr]
|
||||||
let i_unpiar = seq [i_dup ; i_cdr ; dip i_car]
|
let i_unpiar = seq [i_dup ; i_cdr ; dip i_car]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user