From 1356159281ede12abab00429c4c65c2a24151410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Fri, 11 Oct 2019 04:08:12 -0400 Subject: [PATCH] WIP on integrating typer with the bin / CLI, fixed last API change --- src/main/compile/of_simplified.ml | 13 +++++++++---- src/passes/4-typer/typer.ml | 10 +++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/compile/of_simplified.ml b/src/main/compile/of_simplified.ml index cf8bc00fd..96d1f6836 100644 --- a/src/main/compile/of_simplified.ml +++ b/src/main/compile/of_simplified.ml @@ -14,12 +14,17 @@ let compile_expression_as_function_entry (program : program) entry_point : _ res let%bind typed_program = Typer.type_program program in Of_typed.compile_expression_as_function_entry typed_program entry_point -let compile_expression_as_value ?(env = Ast_typed.Environment.full_empty) ae : Michelson.t result = - let%bind typed = Typer.type_expression env ae in +(* TODO: do we need to thread the state here? Also, make the state arg. optional. *) +let compile_expression_as_value ?(env = Ast_typed.Environment.full_empty) ~(state : Typer.Solver.state) ae : Michelson.t result = + let%bind (typed , state) = Typer.type_expression env state ae in + (* TODO: move this to typer.ml *) + let typed = let () = failwith "TODO : subst all" in let _todo = ignore (env, state) in typed in Of_typed.compile_expression_as_value typed -let compile_expression_as_function ?(env = Ast_typed.Environment.full_empty) ae : _ result = - let%bind typed = Typer.type_expression env ae in +let compile_expression_as_function ?(env = Ast_typed.Environment.full_empty) ~(state : Typer.Solver.state) ae : _ result = + let%bind (typed , state) = Typer.type_expression env state ae in + (* TODO: move this to typer.ml *) + let typed = let () = failwith "TODO : subst all" in let _todo = ignore (env, state) in typed in Of_typed.compile_expression_as_function typed let uncompile_typed_program_entry_expression_result program entry ex_ty_value = diff --git a/src/passes/4-typer/typer.ml b/src/passes/4-typer/typer.ml index f6a9078ff..d209d95aa 100644 --- a/src/passes/4-typer/typer.ml +++ b/src/passes/4-typer/typer.ml @@ -871,10 +871,9 @@ and type_expression : environment -> Solver.state -> I.expression -> (O.annotate let e' = Environment.add_ez_binder (fst binder) fresh e in let%bind (result , state') = type_expression e' state result in - let output_type = result.type_annotation in let wrapped = Wrap.lambda fresh input_type' output_type' in return_wrapped - (E_lambda {binder = fst binder; input_type=fresh;output_type; body=result}) + (E_lambda {binder = fst binder; body=result}) (* TODO: is the type of the entire lambda enough to access the input_type=fresh; ? *) state' wrapped ) @@ -923,7 +922,7 @@ let untype_type_value (t:O.type_value) : (I.type_expression) result = (* Apply type_declaration on all the node of the AST_simplified from the root p *) -let type_program (p:I.program) : (environment * Solver.state * O.program) result = +let type_program_returns_state (p:I.program) : (environment * Solver.state * O.program) result = let env = Ast_typed.Environment.full_empty in let state = Solver.initial_state in let aux ((e : environment), (s : Solver.state) , (ds : O.declaration Location.wrap list)) (d:I.declaration Location.wrap) = @@ -940,6 +939,11 @@ let type_program (p:I.program) : (environment * Solver.state * O.program) result let () = ignore (env' , state') in ok (env', state', declarations) +let type_program (p : I.program) : O.program result = + let%bind (env, state, program) = type_program_returns_state p in + let program = let () = failwith "TODO : subst all" in let _todo = ignore (env, state) in program in + ok program + (* Similar to type_program but use a fold_map_list and List.fold_left and add element to the left or the list which gives a better complexity *)