Michelson: Implement SIZE on lists
This commit is contained in:
parent
ecd861ca70
commit
26c9047349
@ -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)
|
||||
|
@ -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 ->
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user