-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpervasives.ml
80 lines (74 loc) · 3.36 KB
/
pervasives.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
let list_id = Id.from_strlist ["list"]
let ref_id = Id.from_strlist ["ref"]
let array_id = Id.from_strlist ["array"]
let ctors =
[ ( Id.from_strlist ["[]"]
, ((1, [])
, (1, Types.Variant ([Types.Poly 0], list_id))) )
; ( Id.from_strlist ["::"]
, ((1, [Types.Poly 0; Types.Variant ([Types.Poly 0], list_id)])
, (1, Types.Variant ([Types.Poly 0], list_id)) )) ]
let types =
[ (list_id, (1, Types.Variant ([Types.Poly 0], list_id)))
; (array_id, (1, Types.Variant ([Types.Poly 0], array_id)))
; (ref_id, (1, Types.Variant ([Types.Poly 0], ref_id))) ]
let vars =
[ ( Id.from_strlist ["="]
, (1, Types.Fun (Types.Poly 0, Types.Fun (Types.Poly 0, Types.Bool))) )
; ( Id.from_strlist ["<>"]
, (1, Types.Fun (Types.Poly 0, Types.Fun (Types.Poly 0, Types.Bool))) )
; ( Id.from_strlist [";"]
, (2, Types.Fun (Types.Poly 0, Types.Fun (Types.Poly 1, Types.Poly 1))) )
; ( Id.from_strlist ["+"]
, (0, Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Int))) )
; ( Id.from_strlist ["-"]
, (0, Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Int))) )
; (Id.from_strlist ["<neg>"], (0, Types.Fun (Types.Int, Types.Int)))
; (Id.from_strlist ["!"], (0, Types.Fun (Types.Variant ([Types.Poly 0], ref_id), Types.Poly 0)))
; (Id.from_strlist ["not"], (0, Types.Fun (Types.Bool, Types.Bool)))
; ( Id.from_strlist ["*"]
, (0, Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Int))) )
; ( Id.from_strlist ["/"]
, (0, Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Int))) )
; ( Id.from_strlist [">"]
, (0, Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Bool))) )
; ( Id.from_strlist ["<"]
, (0, Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Bool))) )
; ( Id.from_strlist ["mod"]
, (0, Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Int))) )
; ( Id.from_strlist ["||"]
, (0, Types.Fun (Types.Bool, Types.Fun (Types.Bool, Types.Bool))) )
; ( Id.from_strlist ["&&"]
, (0, Types.Fun (Types.Bool, Types.Fun (Types.Bool, Types.Bool))) )
; ( Id.from_strlist ["@"]
, ( 1
, Types.Fun
( Types.Variant ([Types.Poly 0], list_id)
, Types.Fun
( Types.Variant ([Types.Poly 0], list_id)
, Types.Variant ([Types.Poly 0], list_id) ) ) ) )
; ( Id.from_strlist ["<-"]
, ( 1
, Types.Fun
( Types.Variant ([Types.Poly 0], array_id)
, Types.Fun (Types.Int, Types.Fun (Types.Poly 0, Types.unit)) ) ) )
; ( Id.from_strlist [":="]
, ( 1
, Types.Fun
( Types.Variant ([Types.Poly 0], array_id)
, Types.Fun (Types.Poly 0, Types.unit) ) ) )
; ( Id.from_strlist ["ref"], (1, Types.Fun (Types.Poly 0, Types.Variant ([Types.Poly 0], ref_id))))
; ( Id.from_strlist ["."]
, ( 1
, Types.Fun
( Types.Variant ([Types.Poly 0], array_id)
, Types.Fun (Types.Int, Types.Poly 0) ) ) )
; (Id.from_strlist ["print_string"], (0, Types.Fun (Types.Str, Types.unit)))
; (Id.from_strlist ["print_int"], (0, Types.Fun (Types.Int, Types.unit)))
; (Id.from_strlist ["failwith"], (1, Types.Fun (Types.Str, Types.Poly 0)))
]
let names =
List.map (fun (n, (_, _)) -> n) ctors @ List.map fst vars @ List.map fst types
let vars = Env.make vars
let ctors = Env.make ctors
let types = Env.make types