Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 185 lines (161 sloc) 4.667 kb
adda7d2 jslib + changes from my repository
Jake Donham authored
1 (*
2 * This file is part of ocamljs, OCaml to Javascript compiler
3 * Copyright (C) 2007 Skydeck, Inc
4 *
5 * This program is free software released under the QPL.
6 * See LICENSE for more details.
7 *
8 * The Software is provided AS IS with NO WARRANTY OF ANY KIND,
9 * INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND
10 * FITNESS FOR A PARTICULAR PURPOSE.
11 *)
12
13 open Camlp4.PreCast
14 module Jslib_ast =
15 struct
16
17 type loc = Loc.t
18
19 and unop =
20 | Jdelete
21 | Jvoid
22 | Jtypeof
23 | Jadd2_pre
24 | Jsub2_pre
25 | Jadd_pre
26 | Jsub_pre
27 | Jtilde
28 | Jnot
29 | Jadd2_post
30 | Jsub2_post
31
32 and binop =
33 | Jhashref
34 | Jmul
35 | Jdiv
36 | Jmod
37 | Jadd
38 | Jsub
39 | Jlt
40 | Jgt
41 | Jleq
42 | Jgeq
43 | Jlsr
44 | Jlsl
45 | Jasr
46 | Jeq
47 | Jneq
48 | Jinstanceof
49 | Jseq
50 | Jsneq
51 | Jland
52 | Jlor
53 | Jand
54 | Jxor
55 | Jor
56 | Jcomma
57 | Jassign
58 | Jmul_assign
59 | Jdiv_assign
60 | Jmod_assign
61 | Jadd_assign
62 | Jsub_assign
63 | Jlsl_assign
64 | Jlsr_assign
65 | Jasr_assign
66 | Jand_assign
67 | Jxor_assign
68 | Jor_assign
69
70 and exp_list =
71 | Jexp_list of loc * exp list
72 | Jexp_list_Ant of loc * string
73
74 and exp =
75 | Jthis of loc
76 | Jvar of loc * string
77 | Jarray of loc * exp_list
78 | Jobject of loc * (exp * exp) list
79 | Jstring of loc * string * bool (* true if double-quoted *)
80 | Jnum of loc * string
81 | Jnull of loc
82 | Jbool of loc * bool
83 | Jfun of loc * string option * string list * stmt list
84 | Jfieldref of loc * exp * string
85 | Junop of loc * unop * exp
86 | Jbinop of loc * binop * exp * exp
87 | Jite of loc * exp * exp * exp
88 | Jcall of loc * exp * exp_list
89 | Jnew of loc * exp * exp_list option
90 | Jexp_Ant of loc * string
91
92 and stmt =
93 | Jempty of loc
94 | Jvars of loc * (string * exp option) list
95 | Jfuns of loc * string * string list * stmt list
96 | Jreturn of loc * exp option
97 | Jcontinue of loc * string option
98 | Jbreak of loc * string option
99 | Jswitch of loc * exp * (exp * stmt list) list * stmt list option
100 | Jites of loc * exp * stmt * stmt option
101 | Jthrow of loc * exp
102 | Jexps of loc * exp
103 | Jtrycatch of loc * stmt list * string * stmt list
104 | Jtryfinally of loc * stmt list * stmt list
105 | Jtrycatchfinally of loc * stmt list * string * stmt list * stmt list
106 | Jfor of loc * exp option * exp option * exp option * stmt
107 | Jdowhile of loc * stmt * exp
108 | Jwhile of loc * exp * stmt
109 | Jblock of loc * stmt list
110 | Jwith of loc * exp * stmt
111 | Jlabel of loc * string * stmt
112 | Jstmt_Ant of loc * string
113
114 end
115
116 include Jslib_ast
117
118 module Meta =
119 struct
120
121 (* I don't really understand what's going on here but this is how
122 Camlp4Ast.mlast does it. *)
123
124 module type META_LOC =
125 sig
126 val meta_loc_patt : Loc.t -> Loc.t -> Ast.patt
127 val meta_loc_expr : Loc.t -> Loc.t -> Ast.expr
128 end
129
130 module MetaLoc =
131 struct
132 let meta_loc_patt _loc location =
133 let (a, b, c, d, e, f, g, h) = Loc.to_tuple location in
134 <:patt< Loc.of_tuple
135 ($`str:a$, $`int:b$, $`int:c$, $`int:d$,
136 $`int:e$, $`int:f$, $`int:g$,
137 $if h then <:patt< True >> else <:patt< False >> $) >>
138 let meta_loc_expr _loc location =
139 let (a, b, c, d, e, f, g, h) = Loc.to_tuple location in
140 <:expr< Loc.of_tuple
141 ($`str:a$, $`int:b$, $`int:c$, $`int:d$,
142 $`int:e$, $`int:f$, $`int:g$,
143 $if h then <:expr< True >> else <:expr< False >> $) >>
144 end
145
146 module MetaGhostLoc =
147 struct
148 let meta_loc_patt _loc _ = <:patt< Loc.ghost >>
149 let meta_loc_expr _loc _ = <:expr< Loc.ghost >>
150 end
151
152 module MetaLocVar = struct
153 let meta_loc_patt _loc _ = <:patt< $lid:!Loc.name$ >>
154 let meta_loc_expr _loc _ = <:expr< $lid:!Loc.name$ >>
155 end
156
157 module Make (MetaLoc : META_LOC) =
158 struct
159 open MetaLoc
160
161 module Expr =
162 struct
163 let meta_loc = meta_loc_expr
164
165 let meta_option mf_a _loc = function
166 | None -> <:expr< None >>
167 | Some a -> <:expr< Some $mf_a _loc a$ >>
168
169 include Camlp4Filters.MetaGeneratorExpr(Jslib_ast)
170 end
171
172 module Patt =
173 struct
174 let meta_loc = meta_loc_patt
175
176 let meta_option mf_a _loc = function
177 | None -> <:patt< None >>
178 | Some a -> <:patt< Some $mf_a _loc a$ >>
179
180 include Camlp4Filters.MetaGeneratorPatt(Jslib_ast)
181 end
182 end
183
184 end
Something went wrong with that request. Please try again.