From ec1004bf2942673bc3542de6f34c5d6a96bbd7a2 Mon Sep 17 00:00:00 2001 From: Markus Mottl Date: Sat, 23 Nov 2024 17:30:46 -0500 Subject: [PATCH] Cleanups --- README.md | 10 +++++----- TODO.md | 8 +++++--- make_terzo.ml | 33 +++++++++++++++------------------ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 105e5aa..4e320d5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -## Fun-trans - A Framework for Transforming Functional Programs +# Fun-trans - A Framework for Transforming Functional Programs + +This source code implements the program transformation framework for a strict and +pure functional language described in the master's thesis +[Automating Functional Program Transformation](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.10.3479). -This source code implements the program transformation -framework for a strict and pure functional language -described in the master's thesis [Automating Functional Program -Transformation](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.10.3479). The implementation language is [LambdaProlog](http://www.lix.polytechnique.fr/~dale/lProlog). diff --git a/TODO.md b/TODO.md index 631668b..21f1e6b 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,5 @@ -* solve problem with recursive types -* common sub-computation elimination for typed terms -* improve simplifier tp_tlet + its inlining +# To do + +- solve problem with recursive types +- common sub-computation elimination for typed terms +- improve simplifier `tp_tlet` + its inlining diff --git a/make_terzo.ml b/make_terzo.ml index b4cd169..e1959d5 100644 --- a/make_terzo.ml +++ b/make_terzo.ml @@ -4,9 +4,7 @@ let sig_stuff = regexp "^(sig|accum_sig)" let module_header = regexp "^module " let imp_accum = regexp "^(accumulate|import)\s+(\w+)\." let imp_accum_repl = subst "$1 tz_$2." - -let print_terzo_stuff oc = - output_string oc "import terzo_stuff.\n" +let print_terzo_stuff oc = output_string oc "import terzo_stuff.\n" let create_terzo name = let md = name ^ ".mod" @@ -17,25 +15,23 @@ let create_terzo name = let in_file = open_in sg in foreach_line ~ic:in_file (fun line -> - if pmatch ~rex:sig_stuff line then () - else sig_lines := (line ^ "\n") :: !sig_lines); + if pmatch ~rex:sig_stuff line then () + else sig_lines := (line ^ "\n") :: !sig_lines); close_in in_file; sig_lines := List.rev !sig_lines; - let sig_ofs = ref 0 - and pos = ref 0 in + let sig_ofs = ref 0 and pos = ref 0 in let in_file = open_in md in foreach_line ~ic:in_file (fun line -> - if pmatch ~rex:module_header line then () - else begin - if pmatch ~rex:imp_accum line then begin - let res = replace ~rex:imp_accum ~itempl:imp_accum_repl line in - mod_lines := (res ^ "\n") :: !mod_lines; - sig_ofs := !pos end - else mod_lines := (line ^ "\n") :: !mod_lines; - incr pos end - ); + if pmatch ~rex:module_header line then () + else ( + if pmatch ~rex:imp_accum line then ( + let res = replace ~rex:imp_accum ~itempl:imp_accum_repl line in + mod_lines := (res ^ "\n") :: !mod_lines; + sig_ofs := !pos) + else mod_lines := (line ^ "\n") :: !mod_lines; + incr pos)); close_in in_file; mod_lines := List.rev !mod_lines; @@ -61,8 +57,9 @@ let _ = let out_file = open_out main_file in output_string out_file "#!/bin/sh\nprintf \"\\\n"; output_string out_file "#load \\\"terzo_stuff.mod\\\".\\n\\\n"; - List.iter (fun m -> - Printf.fprintf out_file "#load \\\"tz_%s.mod\\\".\\n\\\n" m) modules; + List.iter + (fun m -> Printf.fprintf out_file "#load \\\"tz_%s.mod\\\".\\n\\\n" m) + modules; Printf.fprintf out_file "#query tz_main main \\\"$1\\\". \\n\" | Terzo\n"; close_out out_file; Unix.chmod main_file 0o755