Michelson: Implement SIZE on lists

This commit is contained in:
Fabrice Le Fessant 2017-10-20 10:08:03 +02:00 committed by Benjamin Canou
parent ecd861ca70
commit 26c9047349
3 changed files with 9 additions and 1 deletions

View File

@ -163,6 +163,10 @@ let rec interp
return (partial, qta, ctxt, origination))
(init, qta, ctxt, origination) l >>=? fun (res, qta, ctxt, origination) ->
logged_return ~origination (Item (res, rest), qta, ctxt)
| List_size, Item (list, rest) ->
let len = List.length list in
let len = Script_int.(abs (of_int len)) in
logged_return (Item (len, rest), qta - 1, ctxt)
(* sets *)
| Empty_set t, rest ->
logged_return (Item (empty_set t, rest), qta - 1, ctxt)

View File

@ -763,7 +763,7 @@ let rec parse_data
else fail (Unordered_set_values (loc, expr))
else return ()
| None -> return ()
end >>=? fun () ->
end >>=? fun () ->
return (Some v, set_update v true set))
(None, empty_set t) vs >>|? snd |> traced
| Set_t _, expr ->
@ -932,6 +932,9 @@ and parse_instr
check_item_ty elt pelt loc "REDUCE" 2 3 >>=? fun (Eq _) ->
check_item_ty init r loc "REDUCE" 3 3 >>=? fun (Eq _) ->
return (typed loc annot (List_reduce, Item_t (r, rest)))
| Prim (loc, "SIZE", [], annot),
Item_t (List_t _, rest) ->
return (typed loc annot (List_size, Item_t (Nat_t, rest)))
(* sets *)
| Prim (loc, "EMPTY_SET", [ t ], annot),
rest ->

View File

@ -135,6 +135,7 @@ and ('bef, 'aft) instr =
| List_reduce :
(('param * 'res, 'res) lambda *
('param list * ('res * 'rest)), 'res * 'rest) instr
| List_size : ('a list * 'rest, n num * 'rest) instr
(* sets *)
| Empty_set : 'a comparable_ty ->
('rest, 'a set * 'rest) instr