-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslationUnit.ml
34 lines (29 loc) · 1004 Bytes
/
translationUnit.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
open MyUtil
type t = Syntax.t list
let read_sexprs : char Stream.t -> Sexpr.t list = fun stm ->
let f stm =
try
Some (Sexpr.read stm)
with
| Stream.Failure -> None
in
let rec g es =
match f stm with
| None -> es
| Some e -> g (e :: es)
in
List.rev (g [])
let add_def teenv m = function
| Syntax.TopLet (Syntax.P_Ident x, e) ->
Module.add_expr_with_env teenv m (x, (TypingExpr.from_syntax e))
| Syntax.TopLet (pat, e) ->
undefined ()
| Syntax.TopLetSimp ((x, t), e) ->
Module.add_expr_with_env teenv m (x, (TypingExpr.from_syntax e))
| Syntax.TopLetRec ((x, t), e) ->
Module.add_expr_with_env teenv m (x, (TypingExpr.E_Fix (x, (TypingExpr.from_syntax e))))
| _ -> invalid_arg "unexpected keyword"
let read : char Stream.t -> Syntax.t list = fun stm ->
List.map Sread.change (read_sexprs stm)
let modulize : TypingExpr.exprEnv -> Syntax.t list -> Module.t = fun teenv es ->
List.fold_left (add_def teenv) Module.empty es