diff --git a/src/compiler/compiler_program.ml b/src/compiler/compiler_program.ml index 20ec11cb9..2e572fe98 100644 --- a/src/compiler/compiler_program.ml +++ b/src/compiler/compiler_program.ml @@ -338,6 +338,18 @@ and translate_expression ?(first=false) (expr:expression) (env:environment) : (m set_code ; ] ) + | E_while (expr, block) -> ( + let%bind (expr' , env') = translate_expression expr env in + let%bind (block' , env'') = translate_expression block env' in + let%bind restrict_block = Compiler_environment.select_env env'' env' in + return @@ seq [ + expr' ; + prim ~children:[seq [ + block' ; + restrict_block ; + expr']] I_LOOP ; + ] + ) and translate_statement ((s', w_env) as s:statement) : michelson result = let error_message () = Format.asprintf "%a" PP.statement s in diff --git a/src/mini_c/PP.ml b/src/mini_c/PP.ml index 01c058891..6209a624a 100644 --- a/src/mini_c/PP.ml +++ b/src/mini_c/PP.ml @@ -80,6 +80,8 @@ and expression' ppf (e:expression') = match e with fprintf ppf "let %s = %a in %a" name expression expr expression body | E_assignment (r , path , e) -> fprintf ppf "%s.%a := %a" r (list_sep lr (const ".")) path expression e + | E_while (e , b) -> + fprintf ppf "while (%a) %a" expression e expression b and expression : _ -> expression -> _ = fun ppf e -> expression' ppf e.content diff --git a/src/mini_c/types.ml b/src/mini_c/types.ml index dfe4066ab..456770d23 100644 --- a/src/mini_c/types.ml +++ b/src/mini_c/types.ml @@ -68,6 +68,7 @@ and expression' = | E_let_in of ((var_name * type_value) * expression * expression) | E_sequence of (expression * expression) | E_assignment of (string * [`Left | `Right] list * expression) + | E_while of expression * expression and expression = { content : expression' ;