Michelson: rename void into unit.

This commit is contained in:
Benjamin Canou 2017-01-11 16:15:38 +01:00
parent 98859dbf30
commit 26e1adc143
11 changed files with 46 additions and 46 deletions

View File

@ -27,12 +27,12 @@ let fee_arg =
default: \'0.05\"\n\ default: \'0.05\"\n\
text format: D,DDD,DDD.DD (centiles are optional, comas are optional)" text format: D,DDD,DDD.DD (centiles are optional, comas are optional)"
let init = ref "void" let init = ref "Unit"
let init_arg = let init_arg =
"-init", "-init",
Arg.Set_string init, Arg.Set_string init,
"The initial value of the contract's storage.\n\ "The initial value of the contract's storage.\n\
default: void" default: unit"
let arg = ref None let arg = ref None
let arg_arg = let arg_arg =

View File

@ -221,7 +221,7 @@ let commands () =
@@ prefix "running" @@ prefix "running"
@@ Program.source_param @@ Program.source_param
~name:"prg" ~desc: "script of the account\n\ ~name:"prg" ~desc: "script of the account\n\
combine with -init if the storage type is non void" combine with -init if the storage type is not unit"
@@ stop) @@ stop)
(fun neu (_, manager) balance (_, source) code cctxt -> (fun neu (_, manager) balance (_, source) code cctxt ->
check_contract cctxt neu >>= fun () -> check_contract cctxt neu >>= fun () ->

View File

@ -55,7 +55,7 @@ let apply_manager_operation_content ctxt accept_failing_script source = function
Contract.get_script ctxt destination >>=? function Contract.get_script ctxt destination >>=? function
| No_script -> begin | No_script -> begin
match parameters with match parameters with
| None | Some (Prim (_, "void", [])) -> return ctxt | None | Some (Prim (_, "Unit", [])) -> return ctxt
| Some _ -> fail Non_scripted_contract_with_parameter | Some _ -> fail Non_scripted_contract_with_parameter
end end
| Script { code ; storage } -> | Script { code ; storage } ->

View File

@ -77,7 +77,7 @@ with the following JSON script description.
"retType": "uint8", "retType": "uint8",
"storageType": "unit" }, "storageType": "unit" },
"storage": "storage":
{ "storage": "unit", { "storage": "Unit",
"storageType": "unit" } } "storageType": "unit" } }
### Full grammar ### Full grammar

View File

@ -392,7 +392,7 @@ let rec interp
Contract.get_manager ctxt contract >>=? fun manager -> Contract.get_manager ctxt contract >>=? fun manager ->
logged_return (Item (manager, rest), qta - 1, ctxt) logged_return (Item (manager, rest), qta - 1, ctxt)
| Transfer_tokens storage_type, | Transfer_tokens storage_type,
Item (p, Item (amount, Item ((tp, Void_t, destination), Item (sto, Empty)))) -> begin Item (p, Item (amount, Item ((tp, Unit_t, destination), Item (sto, Empty)))) -> begin
Contract.unconditional_spend ctxt source amount >>=? fun ctxt -> Contract.unconditional_spend ctxt source amount >>=? fun ctxt ->
Contract.credit ctxt destination amount >>=? fun ctxt -> Contract.credit ctxt destination amount >>=? fun ctxt ->
Contract.get_script ctxt destination >>=? fun destination_script -> Contract.get_script ctxt destination >>=? fun destination_script ->
@ -400,8 +400,8 @@ let rec interp
Contract.update_script_storage ctxt source sto >>=? fun ctxt -> Contract.update_script_storage ctxt source sto >>=? fun ctxt ->
begin match destination_script with begin match destination_script with
| No_script -> | No_script ->
(* we see non scripted contracts as (void, void) contract *) (* we see non scripted contracts as (unit, unit) contract *)
Lwt.return (ty_eq tp Void_t |> Lwt.return (ty_eq tp Unit_t |>
record_trace (Invalid_contract (loc, destination))) >>=? fun (Eq _) -> record_trace (Invalid_contract (loc, destination))) >>=? fun (Eq _) ->
return (ctxt, qta) return (ctxt, qta)
| Script { code ; storage } -> | Script { code ; storage } ->
@ -412,7 +412,7 @@ let rec interp
ctxt destination csto >>=? fun ctxt -> ctxt destination csto >>=? fun ctxt ->
trace trace
(Invalid_contract (loc, destination)) (Invalid_contract (loc, destination))
(parse_untagged_data ctxt Void_t ret) >>=? fun () -> (parse_untagged_data ctxt Unit_t ret) >>=? fun () ->
return (ctxt, qta) return (ctxt, qta)
end >>=? fun (ctxt, qta) -> end >>=? fun (ctxt, qta) ->
Contract.get_script ctxt source >>=? (function Contract.get_script ctxt source >>=? (function
@ -451,7 +451,7 @@ let rec interp
Contract.originate ctxt Contract.originate ctxt
~manager ~delegate ~balance ~manager ~delegate ~balance
~script:No_script ~spendable:true ~delegatable >>=? fun (ctxt, contract) -> ~script:No_script ~spendable:true ~delegatable >>=? fun (ctxt, contract) ->
logged_return (Item ((Void_t, Void_t, contract), rest), qta - 1, ctxt) logged_return (Item ((Unit_t, Unit_t, contract), rest), qta - 1, ctxt)
| Create_contract (g, p, r), | Create_contract (g, p, r),
Item (manager, Item (delegate, Item (delegatable, Item (credit, Item (manager, Item (delegate, Item (delegatable, Item (credit,
Item (Lam (_, code), Item (init, rest)))))) -> Item (Lam (_, code), Item (init, rest)))))) ->

View File

@ -137,7 +137,7 @@ let rec ty_eq
: type ta tb. ta ty -> tb ty -> (ta ty, tb ty) eq tzresult : type ta tb. ta ty -> tb ty -> (ta ty, tb ty) eq tzresult
= fun ta tb -> = fun ta tb ->
match ta, tb with match ta, tb with
| Void_t, Void_t -> eq ta tb | Unit_t, Unit_t -> eq ta tb
| Int_t ka, Int_t kb -> | Int_t ka, Int_t kb ->
(int_kind_eq ka kb >>? fun (Eq _) -> (int_kind_eq ka kb >>? fun (Eq _) ->
(eq ta tb : (ta ty, tb ty) eq tzresult)) |> (eq ta tb : (ta ty, tb ty) eq tzresult)) |>
@ -355,7 +355,7 @@ let parse_comparable_ty : Script.expr -> ex_comparable_ty tzresult Lwt.t = funct
fail @@ Invalid_arity (loc, Type, prim, 0, List.length l) fail @@ Invalid_arity (loc, Type, prim, 0, List.length l)
| Prim (loc, ("pair" | "union" | "set" | "map" | Prim (loc, ("pair" | "union" | "set" | "map"
| "list" | "option" | "lambda" | "list" | "option" | "lambda"
| "void" | "signature" | "contract"), _) -> | "unit" | "signature" | "contract"), _) ->
fail @@ Comparable_type_expected loc fail @@ Comparable_type_expected loc
| Prim (loc, prim, _) -> | Prim (loc, prim, _) ->
fail @@ Invalid_primitive (loc, Type, prim) fail @@ Invalid_primitive (loc, Type, prim)
@ -365,7 +365,7 @@ let parse_comparable_ty : Script.expr -> ex_comparable_ty tzresult Lwt.t = funct
type ex_ty = Ex : 'a ty -> ex_ty type ex_ty = Ex : 'a ty -> ex_ty
let rec parse_ty : Script.expr -> ex_ty tzresult Lwt.t = function let rec parse_ty : Script.expr -> ex_ty tzresult Lwt.t = function
| Prim (_, "void", []) -> return @@ Ex Void_t | Prim (_, "unit", []) -> return @@ Ex Unit_t
| Prim (_, "int8", []) -> return @@ Ex (Int_t Int8) | Prim (_, "int8", []) -> return @@ Ex (Int_t Int8)
| Prim (_, "int16", []) -> return @@ Ex (Int_t Int16) | Prim (_, "int16", []) -> return @@ Ex (Int_t Int16)
| Prim (_, "int32", []) -> return @@ Ex (Int_t Int32) | Prim (_, "int32", []) -> return @@ Ex (Int_t Int32)
@ -411,7 +411,7 @@ let rec parse_ty : Script.expr -> ex_ty tzresult Lwt.t = function
return @@ Ex (Map_t (ta, tr)) return @@ Ex (Map_t (ta, tr))
| Prim (loc, ("pair" | "union" | "set" | "map" | Prim (loc, ("pair" | "union" | "set" | "map"
| "list" | "option" | "lambda" | "list" | "option" | "lambda"
| "void" | "signature" | "contract" | "unit" | "signature" | "contract"
| "int8" | "int16" | "int32" | "int64" | "int8" | "int16" | "int32" | "int64"
| "uint8" | "uint16" | "uint32" | "uint64" | "uint8" | "uint16" | "uint32" | "uint64"
| "string" | "tez" | "bool" | "string" | "tez" | "bool"
@ -447,10 +447,10 @@ let rec parse_tagged_data
: context -> Script.expr -> ex_tagged_data tzresult Lwt.t : context -> Script.expr -> ex_tagged_data tzresult Lwt.t
= fun ctxt script_data -> = fun ctxt script_data ->
match script_data with match script_data with
| Prim (_, "Void", []) -> | Prim (_, "Unit", []) ->
return @@ Ex (Void_t, ()) return @@ Ex (Unit_t, ())
| Prim (loc, "Void", l) -> | Prim (loc, "Unit", l) ->
fail @@ Invalid_arity (loc, Constant, "Void", 0, List.length l) fail @@ Invalid_arity (loc, Constant, "Unit", 0, List.length l)
| String (_, v) -> | String (_, v) ->
return @@ Ex (String_t, v) return @@ Ex (String_t, v)
| Prim (_, "String", [ arg ]) -> | Prim (_, "String", [ arg ]) ->
@ -628,10 +628,10 @@ and parse_untagged_data
: type a. context -> a ty -> Script.expr -> a tzresult Lwt.t : type a. context -> a ty -> Script.expr -> a tzresult Lwt.t
= fun ctxt ty script_data -> = fun ctxt ty script_data ->
match ty, script_data with match ty, script_data with
(* Void *) (* Unit *)
| Void_t, Prim (_, "Void", []) -> return () | Unit_t, Prim (_, "Unit", []) -> return ()
| Void_t, (Prim (loc, _, _) | Int (loc, _) | String (loc, _) | Seq (loc, _)) -> | Unit_t, (Prim (loc, _, _) | Int (loc, _) | String (loc, _) | Seq (loc, _)) ->
fail @@ Invalid_constant (loc, "void") fail @@ Invalid_constant (loc, "unit")
(* Strings *) (* Strings *)
| String_t, String (_, v) -> return v | String_t, String (_, v) -> return v
| String_t, (Prim (loc, _, _) | Int (loc, _) | Seq (loc, _)) -> | String_t, (Prim (loc, _, _) | Int (loc, _) | Seq (loc, _)) ->
@ -1291,7 +1291,7 @@ and parse_instr
(Bool_t, Item_t (Bool_t, Item_t
(Tez_t, rest)))) -> (Tez_t, rest)))) ->
return (typed loc (Create_account, return (typed loc (Create_account,
Item_t (Contract_t (Void_t, Void_t), rest))) Item_t (Contract_t (Unit_t, Unit_t), rest)))
| Prim (loc, "CREATE_CONTRACT", []), | Prim (loc, "CREATE_CONTRACT", []),
Item_t Item_t
(Key_t, Item_t (Key_t, Item_t
@ -1417,8 +1417,8 @@ and parse_contract
Contract.get_script ctxt contract >>=? function Contract.get_script ctxt contract >>=? function
| No_script -> | No_script ->
(Lwt.return (Lwt.return
(ty_eq arg Void_t >>? fun (Eq _) -> (ty_eq arg Unit_t >>? fun (Eq _) ->
ty_eq ret Void_t >>? fun (Eq _) -> ty_eq ret Unit_t >>? fun (Eq _) ->
let contract : (arg, ret) typed_contract = let contract : (arg, ret) typed_contract =
(arg, ret, contract) in (arg, ret, contract) in
ok contract)) ok contract))
@ -1452,7 +1452,7 @@ let unparse_comparable_ty
let rec unparse_ty let rec unparse_ty
: type a. a ty -> Script.expr = function : type a. a ty -> Script.expr = function
| Void_t -> Prim (-1, "void", []) | Unit_t -> Prim (-1, "unit", [])
| Int_t Int8 -> Prim (-1, "int8", []) | Int_t Int8 -> Prim (-1, "int8", [])
| Int_t Int16 -> Prim (-1, "int16", []) | Int_t Int16 -> Prim (-1, "int16", [])
| Int_t Int32 -> Prim (-1, "int32", []) | Int_t Int32 -> Prim (-1, "int32", [])
@ -1500,8 +1500,8 @@ let rec unparse_ty
let rec unparse_untagged_data let rec unparse_untagged_data
: type a. a ty -> a -> Script.expr : type a. a ty -> a -> Script.expr
= fun ty a -> match ty, a with = fun ty a -> match ty, a with
| Void_t, () -> | Unit_t, () ->
Prim (-1, "Void", []) Prim (-1, "Unit", [])
| Int_t k, v -> | Int_t k, v ->
Int (-1, Int64.to_string (to_int64 k v)) Int (-1, Int64.to_string (to_int64 k v))
| String_t, s -> | String_t, s ->
@ -1565,8 +1565,8 @@ let rec unparse_untagged_data
let rec unparse_tagged_data let rec unparse_tagged_data
: type a. a ty -> a -> Script.expr : type a. a ty -> a -> Script.expr
= fun ty a -> match ty, a with = fun ty a -> match ty, a with
| Void_t, () -> | Unit_t, () ->
Prim (-1, "Void", []) Prim (-1, "Unit", [])
| Int_t k, v -> | Int_t k, v ->
Prim (-1, string_of_int_kind k, [ String (-1, Int64.to_string (to_int64 k v))]) Prim (-1, string_of_int_kind k, [ String (-1, Int64.to_string (to_int64 k v))])
| String_t, s -> | String_t, s ->

View File

@ -59,7 +59,7 @@ and ('arg, 'ret) typed_contract =
'arg ty * 'ret ty * Contract.t 'arg ty * 'ret ty * Contract.t
and 'ty ty = and 'ty ty =
| Void_t : unit ty | Unit_t : unit ty
| Int_t : ('s, 'l) int_kind -> ('s, 'l) int_val ty | Int_t : ('s, 'l) int_kind -> ('s, 'l) int_val ty
| Signature_t : signature ty | Signature_t : signature ty
| String_t : string ty | String_t : string ty

View File

@ -1,9 +1,9 @@
parameter void parameter unit
code code
{ # This contract will never accept a incoming transaction { # This contract will never accept a incoming transaction
FAIL ; FAIL ;
# Alas, FAIL is not (yet?) polymorphic, and we need to keep unused # Alas, FAIL is not (yet?) polymorphic, and we need to keep unused
# instructions for the sake of typing... # instructions for the sake of typing...
CDR ; PUSH VOID ; PAIR } CDR ; UNIT ; PAIR }
return void return unit
storage VOID storage unit

View File

@ -1,8 +1,8 @@
parameter void parameter unit
code code
{ # This contract stop to accept transactions after N incoming transactions { # This contract stop to accept transactions after N incoming transactions
CDR ; PUSH (Uint32 1) ; SWAP ; SUB ; CDR ; PUSH (Uint32 1) ; SWAP ; SUB ;
DUP ; PUSH (Uint32 0) ; COMPARE ; EQ ; IF { FAIL } {} ; DUP ; PUSH (Uint32 0) ; COMPARE ; EQ ; IF { FAIL } {} ;
PUSH VOID ; PAIR } UNIT ; PAIR }
return void return unit
storage uint32 storage uint32

View File

@ -1,7 +1,7 @@
parameter void parameter unit
code code
{ # This is a noop contract { # This is a noop contract
CDR ; PUSH VOID ; PAIR CDR ; UNIT ; PAIR
} }
return void return unit
storage VOID storage unit

View File

@ -65,14 +65,14 @@ ${CLIENT} typecheck program noop
${CLIENT} originate contract noop \ ${CLIENT} originate contract noop \
for ${KEY1} transfering 1000 from bootstrap1 \ for ${KEY1} transfering 1000 from bootstrap1 \
running noop running noop
${CLIENT} transfer 10 from bootstrap1 to noop -arg "void" ${CLIENT} transfer 10 from bootstrap1 to noop -arg "Unit"
${CLIENT} originate contract hardlimit \ ${CLIENT} originate contract hardlimit \
for ${KEY1} transfering 1000 from bootstrap1 \ for ${KEY1} transfering 1000 from bootstrap1 \
running file:scripts/hardlimit.tez -init "3" running file:scripts/hardlimit.tez -init "3"
${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "void" ${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "Unit"
${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "void" ${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "Unit"
# ${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "void" # should fail # ${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "unit" # should fail
echo echo
echo End of test echo End of test