2019-09-10 15:19:15 +02:00
|
|
|
open Mini_c
|
2019-12-04 02:07:39 +01:00
|
|
|
open Proto_alpha_utils
|
|
|
|
open Trace
|
2019-09-10 15:19:15 +02:00
|
|
|
|
2019-12-09 19:51:10 +01:00
|
|
|
let compile_contract : expression -> Compiler.compiled_expression result = fun e ->
|
2020-01-20 19:15:09 +01:00
|
|
|
let%bind e = Self_mini_c.contract_check e in
|
2019-12-06 18:45:22 +01:00
|
|
|
let%bind (input_ty , _) = get_t_function e.type_value in
|
|
|
|
let%bind body = get_function e in
|
|
|
|
let%bind body = Compiler.Program.translate_function_body body [] input_ty in
|
2019-12-06 14:21:49 +01:00
|
|
|
let expr = Self_michelson.optimize body in
|
|
|
|
let%bind expr_ty = Compiler.Type.Ty.type_ e.type_value in
|
|
|
|
let open! Compiler.Program in
|
2019-12-06 15:10:37 +01:00
|
|
|
ok { expr_ty ; expr }
|
2019-12-06 14:21:49 +01:00
|
|
|
|
2019-12-06 18:45:22 +01:00
|
|
|
let compile_expression : expression -> Compiler.compiled_expression result = fun e ->
|
|
|
|
let%bind expr = Compiler.Program.translate_expression e Compiler.Environment.empty in
|
|
|
|
let expr = Self_michelson.optimize expr in
|
|
|
|
let%bind expr_ty = Compiler.Type.Ty.type_ e.type_value in
|
|
|
|
let open! Compiler.Program in
|
|
|
|
ok { expr_ty ; expr }
|
|
|
|
|
2019-12-10 15:55:48 +01:00
|
|
|
let aggregate_and_compile = fun program form ->
|
|
|
|
let%bind aggregated = aggregate_entry program form in
|
|
|
|
let aggregated' = Self_mini_c.all_expression aggregated in
|
|
|
|
match form with
|
|
|
|
| ContractForm _ -> compile_contract aggregated'
|
|
|
|
| ExpressionForm _ -> compile_expression aggregated'
|
|
|
|
|
2020-01-06 17:46:00 +01:00
|
|
|
let aggregate_and_compile_contract = fun (program : Types.program) name ->
|
|
|
|
let%bind (exp, idx) = get_entry program name in
|
2020-01-06 19:24:23 +01:00
|
|
|
let program' = List.take idx program in
|
2020-01-06 17:46:00 +01:00
|
|
|
aggregate_and_compile program' (ContractForm exp)
|
2019-12-10 15:55:48 +01:00
|
|
|
|
2019-12-11 19:15:25 +01:00
|
|
|
let aggregate_and_compile_expression = fun program exp ->
|
|
|
|
aggregate_and_compile program (ExpressionForm exp)
|
2020-01-21 12:24:51 +00:00
|
|
|
|
|
|
|
let pretty_print program =
|
|
|
|
Mini_c.PP.program program
|