From 26e1adc14377e1217bca2a8186425407f0b11e21 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Wed, 11 Jan 2017 16:15:38 +0100 Subject: [PATCH] Michelson: rename void into unit. --- .../embedded/bootstrap/client_proto_args.ml | 4 +- .../bootstrap/client_proto_context.ml | 2 +- src/proto/bootstrap/apply.ml | 2 +- src/proto/bootstrap/docs/json-notations.md | 2 +- src/proto/bootstrap/script_interpreter.ml | 10 ++--- src/proto/bootstrap/script_ir_translator.ml | 40 +++++++++---------- src/proto/bootstrap/script_typed_ir.ml | 2 +- test/scripts/fail.tez | 8 ++-- test/scripts/hardlimit.tez | 6 +-- test/scripts/noop.tez | 8 ++-- test/test-basic.sh | 8 ++-- 11 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/client/embedded/bootstrap/client_proto_args.ml b/src/client/embedded/bootstrap/client_proto_args.ml index f09a7d3c7..24f3cb36f 100644 --- a/src/client/embedded/bootstrap/client_proto_args.ml +++ b/src/client/embedded/bootstrap/client_proto_args.ml @@ -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 = diff --git a/src/client/embedded/bootstrap/client_proto_context.ml b/src/client/embedded/bootstrap/client_proto_context.ml index d9fab7bff..0456526f1 100644 --- a/src/client/embedded/bootstrap/client_proto_context.ml +++ b/src/client/embedded/bootstrap/client_proto_context.ml @@ -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 () -> diff --git a/src/proto/bootstrap/apply.ml b/src/proto/bootstrap/apply.ml index 531498e4e..a91c574de 100644 --- a/src/proto/bootstrap/apply.ml +++ b/src/proto/bootstrap/apply.ml @@ -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 } -> diff --git a/src/proto/bootstrap/docs/json-notations.md b/src/proto/bootstrap/docs/json-notations.md index 0623b43b1..6e54ce317 100644 --- a/src/proto/bootstrap/docs/json-notations.md +++ b/src/proto/bootstrap/docs/json-notations.md @@ -77,7 +77,7 @@ with the following JSON script description. "retType": "uint8", "storageType": "unit" }, "storage": - { "storage": "unit", + { "storage": "Unit", "storageType": "unit" } } ### Full grammar diff --git a/src/proto/bootstrap/script_interpreter.ml b/src/proto/bootstrap/script_interpreter.ml index 94f05e6cf..9d0069c1d 100644 --- a/src/proto/bootstrap/script_interpreter.ml +++ b/src/proto/bootstrap/script_interpreter.ml @@ -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)))))) -> diff --git a/src/proto/bootstrap/script_ir_translator.ml b/src/proto/bootstrap/script_ir_translator.ml index aab4e7591..f360e6f47 100644 --- a/src/proto/bootstrap/script_ir_translator.ml +++ b/src/proto/bootstrap/script_ir_translator.ml @@ -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 -> diff --git a/src/proto/bootstrap/script_typed_ir.ml b/src/proto/bootstrap/script_typed_ir.ml index 864372364..918270526 100644 --- a/src/proto/bootstrap/script_typed_ir.ml +++ b/src/proto/bootstrap/script_typed_ir.ml @@ -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 diff --git a/test/scripts/fail.tez b/test/scripts/fail.tez index 1ac2a4188..69825ee91 100644 --- a/test/scripts/fail.tez +++ b/test/scripts/fail.tez @@ -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 \ No newline at end of file + CDR ; UNIT ; PAIR } +return unit +storage unit \ No newline at end of file diff --git a/test/scripts/hardlimit.tez b/test/scripts/hardlimit.tez index 3d47d9c88..481d692ce 100644 --- a/test/scripts/hardlimit.tez +++ b/test/scripts/hardlimit.tez @@ -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 \ No newline at end of file diff --git a/test/scripts/noop.tez b/test/scripts/noop.tez index 72c865098..2346162f5 100644 --- a/test/scripts/noop.tez +++ b/test/scripts/noop.tez @@ -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 \ No newline at end of file +return unit +storage unit \ No newline at end of file diff --git a/test/test-basic.sh b/test/test-basic.sh index 5ca301f7b..61c81d20f 100755 --- a/test/test-basic.sh +++ b/test/test-basic.sh @@ -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