-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShared.ml
107 lines (82 loc) · 2.33 KB
/
Shared.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(*
* Copyright (c) 2015 Stefan Krah. All rights reserved.
*
* This file is distributed under the terms of the Q Public License
* version 1.0.
*)
(**********************************************************************)
(* Error handlers *)
(**********************************************************************)
let internal_error = Location.internal_error
let error = Location.error
(**********************************************************************)
(* Variants shared by different trees *)
(**********************************************************************)
type level = int
type rec_flag
= Nonrecursive
| Recursive
type mutable_flag
= Immutable
| Mutable
type value_kind
= Vardec
| Parameter
| Loopvar
| External
| Ignore
type param_kind
= Param_tuple
| Param_curried
type binary_operator
= Op_plus | Op_minus | Op_times | Op_divide
| Op_plusdot | Op_minusdot | Op_timesdot | Op_dividedot
| Op_eq | Op_eqeq | Op_ne | Op_lt | Op_le | Op_gt | Op_ge
| Op_and | Op_or
type assign_operator
= Op_assign_arrow | Op_assign_ref
(**********************************************************************)
(* Representations *)
(**********************************************************************)
let var_kind_repr = function
Vardec -> "Vardec"
| Parameter -> "Parameter"
| Loopvar -> "Loopvar"
| External -> "External"
| Ignore -> "Ignore"
let op_repr = function
Op_plus -> "+"
| Op_minus -> "-"
| Op_times -> "*"
| Op_divide -> "/"
| Op_plusdot -> "+."
| Op_minusdot -> "-."
| Op_timesdot -> "*."
| Op_dividedot -> "/."
| Op_eq -> "="
| Op_eqeq -> "=="
| Op_ne -> "<>"
| Op_lt -> "<"
| Op_le -> "<="
| Op_gt -> ">"
| Op_ge -> ">="
| Op_and -> "&&"
| Op_or -> "||"
let assign_op_repr = function
Op_assign_arrow -> "<-"
| Op_assign_ref -> ":="
let is_boolop = function
Op_and | Op_or -> true
| _ -> false
let is_intop = function
Op_plus | Op_minus | Op_times | Op_divide -> true
| _ -> false
let is_floatop = function
Op_plusdot | Op_minusdot | Op_timesdot | Op_dividedot -> true
| _ -> false
let is_cmpop = function
Op_eq | Op_eqeq | Op_ne | Op_lt | Op_le | Op_gt | Op_ge -> true
| _ -> false
let is_eqop = function
Op_eq | Op_eqeq | Op_ne -> true
| _ -> false