From 68f37e14aab4251fb35b9dd20928a2cda484f937 Mon Sep 17 00:00:00 2001 From: Galfour Date: Mon, 15 Apr 2019 05:26:04 +0000 Subject: [PATCH] rename Mini_c statements --- src/ligo/mini_c/PP.ml | 10 +++++----- src/ligo/mini_c/combinators.ml | 10 +++++----- src/ligo/mini_c/compiler.ml | 10 +++++----- src/ligo/mini_c/types.ml | 10 +++++----- src/ligo/test/compiler_tests.ml | 10 +++++----- src/ligo/transpiler.ml | 10 +++++----- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/ligo/mini_c/PP.ml b/src/ligo/mini_c/PP.ml index 6c7f49149..8e3d0e630 100644 --- a/src/ligo/mini_c/PP.ml +++ b/src/ligo/mini_c/PP.ml @@ -90,13 +90,13 @@ and function_ ppf ({binder ; input ; output ; body ; result ; capture_type}:anon and assignment ppf ((n, e):assignment) = fprintf ppf "let %s = %a;" n expression e and statement ppf ((s, _) : statement) = match s with - | Assignment ass -> assignment ppf ass - | I_Cond (expr, i, e) -> fprintf ppf "if (%a) %a %a" expression expr block i block e - | I_patch (r, path, e) -> + | S_assignment ass -> assignment ppf ass + | S_cond (expr, i, e) -> fprintf ppf "if (%a) %a %a" expression expr block i block e + | S_patch (r, path, e) -> let aux = fun ppf -> function `Left -> fprintf ppf ".L" | `Right -> fprintf ppf ".R" in fprintf ppf "%s%a := %a" r (list aux) path expression e - | If_None (expr, none, (name, some)) -> fprintf ppf "if (%a) %a %s.%a" expression expr block none name block some - | While (e, b) -> fprintf ppf "while (%a) %a" expression e block b + | S_if_none (expr, none, (name, some)) -> fprintf ppf "if (%a) %a %s.%a" expression expr block none name block some + | S_while (e, b) -> fprintf ppf "while (%a) %a" expression e block b and block ppf ((b, _):block) = fprintf ppf "{ @;@[%a@]@;}" (pp_print_list ~pp_sep:(tag "@;") statement) b diff --git a/src/ligo/mini_c/combinators.ml b/src/ligo/mini_c/combinators.ml index d6f328ba3..7304be3ed 100644 --- a/src/ligo/mini_c/combinators.ml +++ b/src/ligo/mini_c/combinators.ml @@ -109,11 +109,11 @@ let id_environment_wrap e = environment_wrap e e let statement s' e : statement = match s' with - | I_Cond _ -> s', id_environment_wrap e - | If_None _ -> s', id_environment_wrap e - | While _ -> s', id_environment_wrap e - | I_patch _ -> s', id_environment_wrap e - | Assignment (name, (_, t, _)) -> s', environment_wrap e (Compiler_environment.add (name, t) e) + | S_cond _ -> s', id_environment_wrap e + | S_if_none _ -> s', id_environment_wrap e + | S_while _ -> s', id_environment_wrap e + | S_patch _ -> s', id_environment_wrap e + | S_assignment (name, (_, t, _)) -> s', environment_wrap e (Compiler_environment.add (name, t) e) let block (statements:statement list) : block result = match statements with diff --git a/src/ligo/mini_c/compiler.ml b/src/ligo/mini_c/compiler.ml index 4630b218e..13ce7e4c1 100644 --- a/src/ligo/mini_c/compiler.ml +++ b/src/ligo/mini_c/compiler.ml @@ -291,7 +291,7 @@ and translate_statement ((s', w_env) as s:statement) : michelson result = let error_message () = Format.asprintf "%a" PP.statement s in let%bind (code : michelson) = trace (fun () -> error (thunk "translating statement") error_message ()) @@ match s' with - | Assignment (s, ((_, tv, _) as expr)) -> + | S_assignment (s, ((_, tv, _) as expr)) -> let%bind expr = translate_expression expr in let%bind add = if Environment.has s w_env.pre_environment @@ -309,7 +309,7 @@ and translate_statement ((s', w_env) as s:statement) : michelson result = add ; ]; ]) - | I_Cond (expr, a, b) -> + | S_cond (expr, a, b) -> let%bind expr = translate_expression expr in let%bind a = translate_regular_block a in let%bind b = translate_regular_block b in @@ -320,7 +320,7 @@ and translate_statement ((s', w_env) as s:statement) : michelson result = dip Environment.to_michelson_extend ; prim ~children:[seq [a ; Environment.to_michelson_restrict];seq [b ; Environment.to_michelson_restrict]] I_IF ; ]) - | If_None (expr, none, (_, some)) -> + | S_if_none (expr, none, (_, some)) -> let%bind expr = translate_expression expr in let%bind none' = translate_regular_block none in let%bind some' = translate_regular_block some in @@ -335,7 +335,7 @@ and translate_statement ((s', w_env) as s:statement) : michelson result = seq [add ; some' ; Environment.to_michelson_restrict] ; ] I_IF_NONE ]) - | While ((_, _, _) as expr, block) -> + | S_while ((_, _, _) as expr, block) -> let%bind expr = translate_expression expr in let%bind block = translate_regular_block block in ok @@ (seq [ @@ -346,7 +346,7 @@ and translate_statement ((s', w_env) as s:statement) : michelson result = Environment.to_michelson_restrict ; i_push_unit ; expr ; i_car]] I_LOOP ; ]) - | I_patch (name, lrs, expr) -> + | S_patch (name, lrs, expr) -> let%bind expr' = translate_expression expr in let%bind (name_path, _) = Environment.get_path name w_env.pre_environment in let path = name_path @ lrs in diff --git a/src/ligo/mini_c/types.ml b/src/ligo/mini_c/types.ml index 03731894b..fb1d8bf1c 100644 --- a/src/ligo/mini_c/types.ml +++ b/src/ligo/mini_c/types.ml @@ -70,11 +70,11 @@ and expression = expression' * type_value * environment (* Environment in which and assignment = var_name * expression and statement' = - | Assignment of assignment - | I_Cond of expression * block * block - | I_patch of string * [`Left | `Right] list * expression - | If_None of expression * block * (var_name * block) - | While of expression * block + | S_assignment of assignment + | S_cond of expression * block * block + | S_patch of string * [`Left | `Right] list * expression + | S_if_none of expression * block * (var_name * block) + | S_while of expression * block and statement = statement' * environment_wrap diff --git a/src/ligo/test/compiler_tests.ml b/src/ligo/test/compiler_tests.ml index 93b8c17f0..6f97a7df6 100644 --- a/src/ligo/test/compiler_tests.ml +++ b/src/ligo/test/compiler_tests.ml @@ -12,7 +12,7 @@ let run_entry_int (e:anon_function) (n:int) : int result = let identity () : unit result = let e = basic_int_quote_env in - let s = statement (Assignment ("output", e_var_int "input" e)) e in + let s = statement (S_assignment ("output", e_var_int "input" e)) e in let%bind b = block [s] in let%bind f = basic_int_quote b in let%bind result = run_entry_int f 42 in @@ -27,10 +27,10 @@ let multiple_vars () : unit result = Yes. One could do a monad. Feel free when we have the time. *) let ss = statements [ - (fun e -> statement (Assignment ("a", e_var_int "input" e)) e) ; - (fun e -> statement (Assignment ("b", e_var_int "input" e)) e) ; - (fun e -> statement (Assignment ("c", e_var_int "a" e)) e) ; - (fun e -> statement (Assignment ("output", e_var_int "c" e)) e) ; + (fun e -> statement (S_assignment ("a", e_var_int "input" e)) e) ; + (fun e -> statement (S_assignment ("b", e_var_int "input" e)) e) ; + (fun e -> statement (S_assignment ("c", e_var_int "a" e)) e) ; + (fun e -> statement (S_assignment ("output", e_var_int "c" e)) e) ; ] e in let%bind b = block ss in let%bind f = basic_int_quote b in diff --git a/src/ligo/transpiler.ml b/src/ligo/transpiler.ml index 1b4a5c704..e21c68f45 100644 --- a/src/ligo/transpiler.ml +++ b/src/ligo/transpiler.ml @@ -126,7 +126,7 @@ and translate_instruction (env:Environment.t) (i:AST.instruction) : statement op match Environment.has name env with | true -> env | false -> Environment.add (name, t) env in - return ~env' (Assignment (name, expression)) + return ~env' (S_assignment (name, expression)) | I_patch (r, s, v) -> ( let ty = r.type_value in let aux : ((AST.type_value * [`Left | `Right] list) as 'a) -> AST.access -> 'a result = @@ -148,7 +148,7 @@ and translate_instruction (env:Environment.t) (i:AST.instruction) : statement op in let%bind (_, path) = bind_fold_list aux (ty, []) s in let%bind v' = translate_annotated_expression env v in - return (I_patch (r.type_name, path, v')) + return (S_patch (r.type_name, path, v')) ) | I_matching (expr, m) -> ( let%bind expr' = translate_annotated_expression env expr in @@ -157,7 +157,7 @@ and translate_instruction (env:Environment.t) (i:AST.instruction) : statement op | Match_bool {match_true ; match_false} -> ( let%bind true_branch = translate_block env' match_true in let%bind false_branch = translate_block env' match_false in - return (I_Cond (expr', true_branch, false_branch)) + return (S_cond (expr', true_branch, false_branch)) ) | Match_option {match_none ; match_some = ((name, t), sm)} -> ( let%bind none_branch = translate_block env' match_none in @@ -165,7 +165,7 @@ and translate_instruction (env:Environment.t) (i:AST.instruction) : statement op let%bind t' = translate_type t in let env' = Environment.add (name, t') env' in translate_block env' sm in - return (If_None (expr', none_branch, (name, some_branch))) + return (S_if_none (expr', none_branch, (name, some_branch))) ) | _ -> simple_fail "todo : match" ) @@ -173,7 +173,7 @@ and translate_instruction (env:Environment.t) (i:AST.instruction) : statement op let%bind expr' = translate_annotated_expression env expr in let env' = Environment.extend env in let%bind body' = translate_block env' body in - return (While (expr', body')) + return (S_while (expr', body')) | I_skip -> ok None | I_fail _ -> simple_fail "todo : fail"