-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00fac5f
commit b7410ad
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(library | ||
(name norm) | ||
(libraries sexplib syntax common) | ||
(preprocess | ||
(pps ppx_sexp_conv visitors.ppx))) | ||
|
||
(env | ||
(dev | ||
(flags | ||
(:standard -w -27 -w -32)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module T = Syntax.Parsetree | ||
|
||
type env_t = { | ||
aliases : (string * T.path) list; (* aliases of module path *) | ||
current : T.path option; | ||
(* normalized path to reach module currently transform, it's None when | ||
in the root module *) | ||
} | ||
|
||
let get (name : string) ({ aliases; current } : env_t) : T.path = | ||
List.assoc name aliases | ||
|
||
let rec norm_prog (tr : T.program) (env : env_t) = | ||
match tr with | ||
| [] -> [] | ||
| top :: others -> | ||
let top_normed, env = norm_top_level top env in | ||
top_normed :: norm_prog others env | ||
|
||
and norm_top_level top env : T.top_level * env_t = | ||
match top with | ||
| T.TopLet (x, e) -> norm_let x e env | ||
| T.TopLetRec binds -> norm_let_rec binds env | ||
| T.TopTypeDef ty_def -> norm_top_type_def ty_def env | ||
| T.TopMod (mn, me) -> norm_top_mod mn me env | ||
| T.TopModRec mbinds -> norm_mod_rec mbinds env | ||
|
||
and norm_let p e env = failwith "todo" | ||
|
||
and norm_let_rec binds env = failwith "todo" | ||
|
||
and norm_top_type_def ty_def env = failwith "todo" | ||
|
||
and norm_top_mod mn me env = failwith "todo" | ||
|
||
and norm_mod_rec mbinds env = failwith "todo" | ||
|
||
and norm_path (p : T.path) (env : env_t) = | ||
match p with | ||
| T.PName name -> get name env | ||
| T.PMem (p0, name) -> T.PMem (norm_path p0 env, name) | ||
| T.PApply (p0, p1) -> T.PApply (norm_path p0 env, norm_path p1 env) | ||
|
||
let transfrom (prog : T.program) : T.program = | ||
norm_prog prog { aliases = []; current = None } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val transfrom : Syntax.Parsetree.program -> Syntax.Parsetree.program |