Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mmottl committed Nov 23, 2024
1 parent f6b98de commit ec1004b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
8 changes: 5 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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
33 changes: 15 additions & 18 deletions make_terzo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

Expand All @@ -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

0 comments on commit ec1004b

Please sign in to comment.