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\
text format: D,DDD,DDD.DD (centiles are optional, comas are optional)"
let init = ref "void"
let init = ref "Unit"
let init_arg =
"-init",
Arg.Set_string init,
"The initial value of the contract's storage.\n\
default: void"
default: unit"
let arg = ref None
let arg_arg =

View File

@ -221,7 +221,7 @@ let commands () =
@@ prefix "running"
@@ Program.source_param
~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)
(fun neu (_, manager) balance (_, source) code cctxt ->
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
| No_script -> begin
match parameters with
| None | Some (Prim (_, "void", [])) -> return ctxt
| None | Some (Prim (_, "Unit", [])) -> return ctxt
| Some _ -> fail Non_scripted_contract_with_parameter
end
| Script { code ; storage } ->

View File

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

View File

@ -392,7 +392,7 @@ let rec interp
Contract.get_manager ctxt contract >>=? fun manager ->
logged_return (Item (manager, rest), qta - 1, ctxt)
| 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.credit ctxt destination amount >>=? fun ctxt ->
Contract.get_script ctxt destination >>=? fun destination_script ->
@ -400,8 +400,8 @@ let rec interp
Contract.update_script_storage ctxt source sto >>=? fun ctxt ->
begin match destination_script with
| No_script ->
(* we see non scripted contracts as (void, void) contract *)
Lwt.return (ty_eq tp Void_t |>
(* we see non scripted contracts as (unit, unit) contract *)
Lwt.return (ty_eq tp Unit_t |>
record_trace (Invalid_contract (loc, destination))) >>=? fun (Eq _) ->
return (ctxt, qta)
| Script { code ; storage } ->
@ -412,7 +412,7 @@ let rec interp
ctxt destination csto >>=? fun ctxt ->
trace
(Invalid_contract (loc, destination))
(parse_untagged_data ctxt Void_t ret) >>=? fun () ->
(parse_untagged_data ctxt Unit_t ret) >>=? fun () ->
return (ctxt, qta)
end >>=? fun (ctxt, qta) ->
Contract.get_script ctxt source >>=? (function
@ -451,7 +451,7 @@ let rec interp
Contract.originate ctxt
~manager ~delegate ~balance
~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),
Item (manager, Item (delegate, Item (delegatable, Item (credit,
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
= fun ta tb ->
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_kind_eq ka kb >>? fun (Eq _) ->
(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)
| Prim (loc, ("pair" | "union" | "set" | "map"
| "list" | "option" | "lambda"
| "void" | "signature" | "contract"), _) ->
| "unit" | "signature" | "contract"), _) ->
fail @@ Comparable_type_expected loc
| Prim (loc, 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
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 (_, "int16", []) -> return @@ Ex (Int_t Int16)
| 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))
| Prim (loc, ("pair" | "union" | "set" | "map"
| "list" | "option" | "lambda"
| "void" | "signature" | "contract"
| "unit" | "signature" | "contract"
| "int8" | "int16" | "int32" | "int64"
| "uint8" | "uint16" | "uint32" | "uint64"
| "string" | "tez" | "bool"
@ -447,10 +447,10 @@ let rec parse_tagged_data
: context -> Script.expr -> ex_tagged_data tzresult Lwt.t
= fun ctxt script_data ->
match script_data with
| Prim (_, "Void", []) ->
return @@ Ex (Void_t, ())
| Prim (loc, "Void", l) ->
fail @@ Invalid_arity (loc, Constant, "Void", 0, List.length l)
| Prim (_, "Unit", []) ->
return @@ Ex (Unit_t, ())
| Prim (loc, "Unit", l) ->
fail @@ Invalid_arity (loc, Constant, "Unit", 0, List.length l)
| String (_, v) ->
return @@ Ex (String_t, v)
| Prim (_, "String", [ arg ]) ->
@ -628,10 +628,10 @@ and parse_untagged_data
: type a. context -> a ty -> Script.expr -> a tzresult Lwt.t
= fun ctxt ty script_data ->
match ty, script_data with
(* Void *)
| Void_t, Prim (_, "Void", []) -> return ()
| Void_t, (Prim (loc, _, _) | Int (loc, _) | String (loc, _) | Seq (loc, _)) ->
fail @@ Invalid_constant (loc, "void")
(* Unit *)
| Unit_t, Prim (_, "Unit", []) -> return ()
| Unit_t, (Prim (loc, _, _) | Int (loc, _) | String (loc, _) | Seq (loc, _)) ->
fail @@ Invalid_constant (loc, "unit")
(* Strings *)
| String_t, String (_, v) -> return v
| String_t, (Prim (loc, _, _) | Int (loc, _) | Seq (loc, _)) ->
@ -1291,7 +1291,7 @@ and parse_instr
(Bool_t, Item_t
(Tez_t, rest)))) ->
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", []),
Item_t
(Key_t, Item_t
@ -1417,8 +1417,8 @@ and parse_contract
Contract.get_script ctxt contract >>=? function
| No_script ->
(Lwt.return
(ty_eq arg Void_t >>? fun (Eq _) ->
ty_eq ret Void_t >>? fun (Eq _) ->
(ty_eq arg Unit_t >>? fun (Eq _) ->
ty_eq ret Unit_t >>? fun (Eq _) ->
let contract : (arg, ret) typed_contract =
(arg, ret, contract) in
ok contract))
@ -1452,7 +1452,7 @@ let unparse_comparable_ty
let rec unparse_ty
: 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 Int16 -> Prim (-1, "int16", [])
| Int_t Int32 -> Prim (-1, "int32", [])
@ -1500,8 +1500,8 @@ let rec unparse_ty
let rec unparse_untagged_data
: type a. a ty -> a -> Script.expr
= fun ty a -> match ty, a with
| Void_t, () ->
Prim (-1, "Void", [])
| Unit_t, () ->
Prim (-1, "Unit", [])
| Int_t k, v ->
Int (-1, Int64.to_string (to_int64 k v))
| String_t, s ->
@ -1565,8 +1565,8 @@ let rec unparse_untagged_data
let rec unparse_tagged_data
: type a. a ty -> a -> Script.expr
= fun ty a -> match ty, a with
| Void_t, () ->
Prim (-1, "Void", [])
| Unit_t, () ->
Prim (-1, "Unit", [])
| Int_t k, v ->
Prim (-1, string_of_int_kind k, [ String (-1, Int64.to_string (to_int64 k v))])
| String_t, s ->

View File

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

View File

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

View File

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

View File

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

View File

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