Fix bug for compile-parameter and compile-storage

This commit is contained in:
Tom Jack 2019-09-25 13:29:00 -05:00
parent be75fd4830
commit 8a04ee8097
3 changed files with 18 additions and 10 deletions

View File

@ -1,11 +1,6 @@
open Trace
open Ast_simplified
let get_final_environment program =
let last_declaration = Location.unwrap List.(hd @@ rev program) in
let (Ast_typed.Declaration_constant (_ , (_ , post_env))) = last_declaration in
post_env
let compile_expression ?(value = false) ?env expr =
if value
then (
@ -22,7 +17,7 @@ let run_typed_program
(input : expression) : expression result =
let%bind code = Compile.Of_typed.compile_function_entry program entry in
let%bind input =
let env = get_final_environment program in
let env = Ast_typed.program_environment program in
compile_expression ?value:input_to_value ~env input
in
let%bind ex_ty_value = Of_michelson.run ?options code input in

View File

@ -50,15 +50,19 @@ end
let compile_file_contract_parameter : string -> string -> string -> Compile.Helpers.s_syntax -> Michelson.t result =
fun source_filename _entry_point expression syntax ->
let%bind program = Compile.Of_source.type_file syntax source_filename in
let env = Ast_typed.program_environment program in
let%bind syntax = Compile.Helpers.syntax_to_variant syntax (Some source_filename) in
let%bind simplified = Compile.Helpers.parsify_expression syntax expression in
Of_simplified.compile_expression simplified
Of_simplified.compile_expression simplified ~env
let compile_file_expression : string -> string -> string -> Compile.Helpers.s_syntax -> Michelson.t result =
fun source_filename _entry_point expression syntax ->
let%bind program = Compile.Of_source.type_file syntax source_filename in
let env = Ast_typed.program_environment program in
let%bind syntax = Compile.Helpers.syntax_to_variant syntax (Some source_filename) in
let%bind simplified = Compile.Helpers.parsify_expression syntax expression in
Of_simplified.compile_expression simplified
Of_simplified.compile_expression simplified ~env
let compile_expression : string -> Compile.Helpers.s_syntax -> Michelson.t result =
fun expression syntax ->
@ -68,17 +72,21 @@ let compile_expression : string -> Compile.Helpers.s_syntax -> Michelson.t resul
let compile_file_contract_storage ~value : string -> string -> string -> Compile.Helpers.s_syntax -> Michelson.t result =
fun source_filename _entry_point expression syntax ->
let%bind program = Compile.Of_source.type_file syntax source_filename in
let env = Ast_typed.program_environment program in
let%bind syntax = Compile.Helpers.syntax_to_variant syntax (Some source_filename) in
let%bind simplified = Compile.Helpers.parsify_expression syntax expression in
Of_simplified.compile_expression ~value simplified
Of_simplified.compile_expression ~value simplified ~env
let compile_file_contract_args =
fun ?value source_filename _entry_point storage parameter syntax ->
let%bind program = Compile.Of_source.type_file syntax source_filename in
let env = Ast_typed.program_environment program in
let%bind syntax = Compile.Helpers.syntax_to_variant syntax (Some source_filename) in
let%bind storage_simplified = Compile.Helpers.parsify_expression syntax storage in
let%bind parameter_simplified = Compile.Helpers.parsify_expression syntax parameter in
let args = Ast_simplified.e_pair storage_simplified parameter_simplified in
Of_simplified.compile_expression ?value args
Of_simplified.compile_expression ?value args ~env
let run_contract ?amount ?storage_value source_filename entry_point storage parameter syntax =

View File

@ -500,3 +500,8 @@ let get_entry (lst : program) (name : string) : annotated_expression result =
else None
in
List.find_map aux lst
let program_environment (program : program) : full_environment =
let last_declaration = Location.unwrap List.(hd @@ rev program) in
match last_declaration with
| Declaration_constant (_ , (_ , post_env)) -> post_env