Skip to content

Commit

Permalink
normalization skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
butterunderflow committed Mar 24, 2024
1 parent 00fac5f commit b7410ad
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/norm/dune
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))))
45 changes: 45 additions & 0 deletions lib/norm/normalize.ml
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 }
1 change: 1 addition & 0 deletions lib/norm/normalize.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val transfrom : Syntax.Parsetree.program -> Syntax.Parsetree.program

0 comments on commit b7410ad

Please sign in to comment.