Skip to content

Commit

Permalink
fix generated lean project
Browse files Browse the repository at this point in the history
  • Loading branch information
javra committed Dec 16, 2024
1 parent 725cbde commit 0ff6402
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,6 @@
(%{workspace_root}/src/gen_lib/sail2_values.lem
as
src/gen_lib/sail2_values.lem)
(%{workspace_root}/src/sail_lean_backend/Sail/sail.lean
(%{workspace_root}/src/sail_lean_backend/Sail/Sail.lean
as
src/sail_lean_backend/Sail/sail.lean)))
src/sail_lean_backend/Sail/Sail.lean)))
File renamed without changes.
3 changes: 2 additions & 1 deletion src/sail_lean_backend/pretty_print_lean.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ open PPrint
open Pretty_print_common

let implicit_parens x = enclose (string "{") (string "}") x

let doc_id_ctor (Id_aux (i, _)) =
match i with Id i -> string i | Operator x -> string (Util.zencode_string ("op " ^ x))

let doc_kid (Kid_aux (Var x, _)) = string ("k_" ^ String.sub x 1 (String.length x - 1))
(* TODO do a proper renaming and keep track of it *)

Expand Down Expand Up @@ -298,6 +300,5 @@ let rec remove_imports (defs : (Libsail.Type_check.tannot, Libsail.Type_check.en
let pp_ast_lean ({ defs; _ } as ast : Libsail.Type_check.typed_ast) o =
let defs = remove_imports defs 0 in
let output : document = separate_map empty doc_def defs in
output_string o "import Sail.sail\n\n";
print o output;
()
15 changes: 8 additions & 7 deletions src/sail_lean_backend/sail_plugin_lean.ml
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ let create_lake_project (out_name : string) default_sail_dir =
(* Change the base directory if the option '--lean-output-dir' is set *)
let base_dir = match !opt_lean_output_dir with Some dir -> dir | None -> "." in
let project_dir = Filename.concat base_dir out_name in
if !opt_lean_force_output && Sys.is_directory project_dir then (
let _ = Unix.system ("rm -r " ^ Filename.quote project_dir ^ "/*") in
if !opt_lean_force_output && Sys.file_exists project_dir && Sys.is_directory project_dir then (
let _ = Unix.system ("rm -r " ^ project_dir ^ "/*") in
()
)
else Unix.mkdir project_dir 0o775;
Expand All @@ -174,15 +174,16 @@ let create_lake_project (out_name : string) default_sail_dir =
let out_name_camel = Libsail.Util.to_upper_camel_case out_name in
let lakefile = open_out (Filename.concat project_dir "lakefile.toml") in
output_string lakefile
("name = \"" ^ out_name ^ "\"\ndefaultTargets = [\"" ^ out_name_camel
^ "\"]\n\n[[lean_lib]]\nname = \"Sail\"\n\n[[lean_lib]]\nname = \"" ^ out_name_camel ^ "\""
("name = \"" ^ out_name ^ "\"\ndefaultTargets = [\"" ^ out_name_camel ^ "\"]\n\n[[lean_lib]]\nname = \""
^ out_name_camel ^ "\""
);
close_out lakefile;
let lean_src_dir = Filename.concat project_dir out_name_camel in
if not (Sys.file_exists lean_src_dir) then Unix.mkdir lean_src_dir 0o775;
let sail_dir = Reporting.get_sail_dir default_sail_dir in
let _ =
Unix.system ("cp -r " ^ Filename.quote (sail_dir ^ "/src/sail_lean_backend/Sail") ^ " " ^ Filename.quote project_dir)
in
let _ = Unix.system ("cp -r " ^ sail_dir ^ "/src/sail_lean_backend/Sail " ^ lean_src_dir) in
let project_main = open_out (Filename.concat project_dir (out_name_camel ^ ".lean")) in
output_string project_main ("import " ^ out_name_camel ^ ".Sail.Sail\n\n");
project_main

let output (out_name : string) ast default_sail_dir =
Expand Down
3 changes: 1 addition & 2 deletions test/lean/struct.expected.lean
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Sail.sail
import My_Project.Sail.sail

structure My_struct where
field1 : Int
Expand All @@ -10,4 +10,3 @@ def undefined_My_struct (lit : Unit) : My_struct :=

def initialize_registers : Unit :=
()

0 comments on commit 0ff6402

Please sign in to comment.