Commit 435d135a authored by Alain Mebsout's avatar Alain Mebsout Committed by Benjamin Canou

Michelson: annotations for variable bindings with $

Also move annotation specific code to own module.
parent 68f86fe2
......@@ -16,7 +16,7 @@ code { DUP; CAR;
IF_LEFT { DUP; DIIP{ CDR %stored_balance; DUP };
DIP{ SWAP }; GET;
# Create the account
IF_SOME @previous_balance
IF_SOME $previous_balance
# Add to an existing account
{ AMOUNT; ADD; SOME; SWAP; UPDATE; NIL operation; PAIR }
{ DIP{ AMOUNT; SOME }; UPDATE; NIL operation; PAIR }}
......@@ -31,7 +31,7 @@ code { DUP; CAR;
DIIP{ CDR %stored_balance; DUP };
CAR %from; HASH_KEY @from_hash; DIP{ SWAP }; GET;
# Account does not exist
IF_NONE @previous_balance
IF_NONE $previous_balance
{ FAIL }
# Account exists
{ DUP; DIIP{ DUP; CDAR %withdraw_amount; DUP };
......
parameter (map int int);
storage (pair int int);
code { CAR; PUSH int 0; DUP; PAIR; SWAP;
ITER { DIP {DUP; CAR; DIP{CDR}}; DUP; # Last instr
parameter (map (int :k) (int :e));
storage (pair (int :k) (int :e));
code { CAR; PUSH @acc_e (int :e) 0; PUSH @acc_k (int :k) 0; PAIR; SWAP;
ITER $my_key $my_elt
{ DIP {DUP; CAR; DIP{CDR}}; DUP; # Last instr
DIP{CAR; ADD}; SWAP; DIP{CDR; ADD}; PAIR };
NIL operation; PAIR}
......@@ -12,6 +12,7 @@ open Alpha_context
open Tezos_micheline
open Script_typed_ir
open Script_tc_errors
open Script_ir_annot
open Script_ir_translator
open Script_interpreter
open Michelson_v1_printer
......
......@@ -59,6 +59,7 @@
"Fees",
"Script_tc_errors",
"Michelson_v1_gas",
"Script_ir_annot",
"Script_ir_translator",
"Script_tc_errors_registration",
"Script_interpreter",
......
This diff is collapsed.
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2018. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
open Alpha_context
open Script_typed_ir
(** Default annotations *)
val default_now_annot : var_annot option
val default_amount_annot : var_annot option
val default_balance_annot : var_annot option
val default_steps_annot : var_annot option
val default_source_annot : var_annot option
val default_self_annot : var_annot option
val default_param_annot : field_annot option
val default_storage_annot : field_annot option
val default_car_annot : field_annot option
val default_cdr_annot : field_annot option
val default_contract_annot : field_annot option
val default_addr_annot : field_annot option
val default_manager_annot : field_annot option
val default_arg_annot : binding_annot option
val default_elt_annot : binding_annot option
val default_key_annot : binding_annot option
val default_hd_annot : binding_annot option
val default_some_annot : binding_annot option
val default_left_annot : binding_annot option
val default_right_annot : binding_annot option
(** Unparse annotations to their string representation *)
val unparse_type_annot : type_annot option -> string list
val unparse_var_annot : var_annot option -> string list
val unparse_field_annot : field_annot option -> string list
val unparse_binding_annot : binding_annot option -> string list
(** Convertions functions between different annotation kinds *)
val field_to_var_annot : field_annot option -> var_annot option
val field_to_binding_annot : field_annot option -> binding_annot option
val binding_to_var_annot : binding_annot option -> var_annot option
val binding_to_field_annot : binding_annot option -> field_annot option
val var_to_binding_annot : var_annot option -> binding_annot option
val type_to_field_annot : type_annot option -> field_annot option
val var_to_field_annot : var_annot option -> field_annot option
(** Replace an annotation by its default value if it is [None] *)
val default_annot : default:'a option -> 'a option -> 'a option
(** Generate annotation for field accesses, of the form @var.field1.field2 *)
val gen_access_annot :
var_annot option ->
?default:field_annot option -> field_annot option -> var_annot option
(** Generate a binding annotation, of the form $var.some *)
val gen_binding_access_annot :
var_annot option ->
?default:binding_annot option ->
binding_annot option -> binding_annot option
(** Merge type annotations.
@returns {!Inconsistent_type_annotations} if they are both present and different *)
val merge_type_annot :
type_annot option -> type_annot option -> type_annot option tzresult
(** Merge field annotations, does not fail ([None] if different). *)
val merge_field_annot :
field_annot option -> field_annot option -> field_annot option tzresult
(** Merge variable annotations, does not fail ([None] if different). *)
val merge_var_annot :
var_annot option -> var_annot option -> var_annot option
(** @returns an error {!Unexpected_annotation} in the monad the list is not empty. *)
val error_unexpected_annot : int -> 'a list -> unit tzresult
(** Same as {!error_unexpected_annot} in Lwt. *)
val fail_unexpected_annot : int -> 'a list -> unit tzresult Lwt.t
(** Parse string annotations. *)
val parse_annots : int -> string list -> annot list tzresult
(** Parse a type annotation only. *)
val parse_type_annot : int -> string list -> type_annot option tzresult
(** Parse an annotation for composed types, of the form
[:ty_name %field1 %field2] in any order. *)
val parse_composed_type_annot :
int -> string list ->
(type_annot option * field_annot option * field_annot option) tzresult
(** Check that type annotations are consistent *)
val check_const_type_annot :
int -> string list -> type_annot option -> unit tzresult Lwt.t
(** Extract and remove a field annotation from a node *)
val extract_field_annot :
Script.node -> (Script.node * field_annot option) tzresult
(** Check that field annotations match, used for field accesses. *)
val check_correct_field :
field_annot option -> field_annot option -> unit tzresult
(** Instruction annotations parsing *)
(** Parse a variable annotation, replaced by a default value if [None]. *)
val parse_var_annot :
int ->
?default:var_annot option ->
string list -> var_annot option tzresult Lwt.t
val parse_field_annot :
int -> string list -> field_annot option tzresult Lwt.t
val parse_constr_annot :
int -> string list ->
(var_annot option * type_annot option * field_annot option * field_annot option) tzresult Lwt.t
val parse_map_annot :
int -> string list ->
(var_annot option * type_annot option * binding_annot option * binding_annot option) tzresult Lwt.t
val parse_two_var_annot :
int -> string list -> (var_annot option * var_annot option) tzresult Lwt.t
val parse_two_binding_annot :
int -> string list ->
(binding_annot option * binding_annot option) tzresult Lwt.t
val parse_var_field_annot :
int -> string list -> (var_annot option * field_annot option) tzresult Lwt.t
val parse_var_type_annot :
int -> string list -> (var_annot option * type_annot option) tzresult Lwt.t
val parse_binding_annot :
int -> string list -> binding_annot option tzresult Lwt.t
val parse_var_binding_annot :
int -> string list -> (var_annot option * binding_annot option) tzresult Lwt.t
......@@ -67,7 +67,6 @@ val parse_data :
val unparse_data :
context -> unparsing_mode -> 'a Script_typed_ir.ty -> 'a ->
(Script.node * context) tzresult Lwt.t
val unparse_var_annot : Script_typed_ir.var_annot option -> string list
val parse_ty :
allow_big_map: bool ->
......
......@@ -41,8 +41,6 @@ type error += Bad_stack_length
type error += Bad_stack_item of int
type error += Inconsistent_annotations of string * string
type error += Inconsistent_type_annotations : Script.location * _ ty * _ ty -> error
type error += Invalid_type_annotation : Script.location * annot list -> error
type error += Invalid_var_annotation : Script.location * annot list -> error
type error += Inconsistent_field_annotations of string * string
type error += Unexpected_annotation of Script.location
type error += Invalid_map_body : Script.location * _ stack_ty -> error
......
......@@ -10,27 +10,14 @@
open Alpha_context
open Script_int
(* ---- Auxiliary types -----------------------------------------------------*)
type var_annot = [ `Var_annot of string ]
type type_annot = [ `Type_annot of string ]
type field_annot = [ `Field_annot of string ]
type binding_annot = [ `Binding_annot of string ]
type annot = [ var_annot | type_annot | field_annot ]
(* type 'ty comparable_ty_desc =
* | Int_key : (z num) comparable_ty_desc
* | Nat_key : (n num) comparable_ty_desc
* | String_key : string comparable_ty_desc
* | Mutez_key : Tez.t comparable_ty_desc
* | Bool_key : bool comparable_ty_desc
* | Key_hash_key : public_key_hash comparable_ty_desc
* | Timestamp_key : Script_timestamp.t comparable_ty_desc
* | Address_key : Contract.t comparable_ty_desc
*
* type 'ty comparable_ty =
* { comp_ty_desc : 'ty comparable_ty_desc ; comp_ty_name : type_annot option } *)
type annot = [ var_annot | type_annot | field_annot | binding_annot ]
type 'ty comparable_ty =
| Int_key : type_annot option -> (z num) comparable_ty
......@@ -80,31 +67,6 @@ and ('arg, 'ret) lambda =
and 'arg typed_contract =
'arg ty * Contract.t
(* and 'ty ty_desc =
* | Unit_t : unit ty_desc
* | Int_t : z num ty_desc
* | Nat_t : n num ty_desc
* | Signature_t : signature ty_desc
* | String_t : string ty_desc
* | Mutez_t : Tez.t ty_desc
* | Key_hash_t : public_key_hash ty_desc
* | Key_t : public_key ty_desc
* | Timestamp_t : Script_timestamp.t ty_desc
* | Address_t : Contract.t ty_desc
* | Bool_t : bool ty_desc
* | Pair_t : ('a ty * field_annot option) * ('b ty * field_annot option) -> ('a, 'b) pair ty_desc
* | Union_t : ('a ty * field_annot option) * ('b ty * field_annot option) -> ('a, 'b) union ty_desc
* | Lambda_t : 'arg ty * 'ret ty -> ('arg, 'ret) lambda ty_desc
* | Option_t : ('v ty * field_annot option) * field_annot option -> 'v option ty_desc
* | List_t : 'v ty -> 'v list ty_desc
* | Set_t : 'v comparable_ty -> 'v set ty_desc
* | Map_t : 'k comparable_ty * 'v ty -> ('k, 'v) map ty_desc
* | Big_map_t : 'k comparable_ty * 'v ty -> ('k, 'v) big_map ty_desc
* | Contract_t : 'arg ty -> 'arg typed_contract ty_desc
* | Operation_t : internal_operation ty_desc
*
* and 'ty ty = { ty_desc : 'ty ty_desc ; ty_name : type_annot option } *)
and 'ty ty =
| Unit_t : type_annot option -> unit ty
| Int_t : type_annot option -> z num ty
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment