Skip to content

Commit 1cc8af5

Browse files
committed
wip
1 parent 58f2369 commit 1cc8af5

17 files changed

+188
-48
lines changed

jscomp/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ COMMON_SRCS= bs_version\
226226
COMMON_CMXS= $(addprefix common/, $(addsuffix .cmx, $(COMMON_SRCS)))
227227
SYNTAX_SRCS= \
228228
bs_syntaxerr\
229+
ast_compatible\
229230
ast_utf8_string\
230231
ast_utf8_string_interp\
231232
ast_derive_constructor \

jscomp/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,25 @@ so that we don't need bootstrap compiler, everytime we deliver a new feature.
4444
## [test](./test)
4545

4646
The directory containing unit-test files, some unit tests are copied from OCaml distribution(4.02)
47+
48+
## compiler sourcetree
49+
50+
- ext
51+
- common
52+
- bsb
53+
- depends
54+
- core
55+
- bspp
56+
- outcome_printer
57+
- stubs
58+
- super_errors
59+
- syntax
60+
## tools (deprecatd code)
61+
## xwatcher (dev tools)
62+
## runtime
63+
## build_tests
64+
## bin
65+
## cmd_tests
66+
## ounit
67+
## ounit_tests
68+
## others (belt/stdlib/node bindings)

jscomp/syntax/ast_comb.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ open Ast_helper
2828
let exp_apply_no_label ?loc ?attrs a b =
2929
Exp.apply ?loc ?attrs a (Ext_list.map (fun x -> "", x) b)
3030

31-
let fun_no_label ?loc ?attrs pat body =
32-
Exp.fun_ ?loc ?attrs "" None pat body
31+
(* let fun_no_label ?loc ?attrs pat body =
32+
Ast_compatible.fun_ ?loc ?attrs pat body *)
3333

3434
let arrow_no_label ?loc ?attrs b c =
3535
Typ.arrow ?loc ?attrs "" b c

jscomp/syntax/ast_comb.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ val exp_apply_no_label :
2828
?attrs:Parsetree.attributes ->
2929
Parsetree.expression -> Parsetree.expression list -> Parsetree.expression
3030

31-
val fun_no_label :
31+
(* val fun_no_label :
3232
?loc:Location.t ->
3333
?attrs:Parsetree.attributes ->
34-
Parsetree.pattern -> Parsetree.expression -> Parsetree.expression
34+
Parsetree.pattern -> Parsetree.expression -> Parsetree.expression *)
3535

3636
val arrow_no_label :
3737
?loc:Location.t ->

jscomp/syntax/ast_compatible.ml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
(* Copyright (C) 2018 Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
type loc = Location.t
26+
type attrs = Parsetree.attribute list
27+
open Parsetree
28+
let default_loc = Location.none
29+
30+
#if OCAML_VERSION =~ ">4.03.0" then
31+
32+
#else
33+
34+
let const_exp_string
35+
?(loc = default_loc)
36+
?(attrs = [])
37+
?delimiter
38+
(s : string) : expression =
39+
{
40+
pexp_loc = loc;
41+
pexp_attributes = attrs;
42+
pexp_desc = Pexp_constant(Const_string(s,delimiter))
43+
}
44+
45+
let apply_simple
46+
?(loc = default_loc)
47+
?(attrs = [])
48+
fn args : expression =
49+
{ pexp_loc = loc;
50+
pexp_attributes = attrs;
51+
pexp_desc =
52+
Pexp_apply(
53+
fn,
54+
(Ext_list.map (fun x -> "",x) args) ) }
55+
56+
let fun_
57+
?(loc = default_loc)
58+
?(attrs = [])
59+
pat
60+
exp =
61+
{
62+
pexp_loc = loc;
63+
pexp_attributes = attrs;
64+
pexp_desc = Pexp_fun("",None, pat, exp)
65+
}
66+
#end

jscomp/syntax/ast_compatible.mli

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
(* Copyright (C) 2018 Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+
type loc = Location.t
27+
type attrs = Parsetree.attribute list
28+
open Parsetree
29+
30+
31+
val const_exp_string:
32+
?loc:Location.t ->
33+
?attrs:attrs ->
34+
?delimiter:string ->
35+
string ->
36+
expression
37+
38+
val const_exp_int:
39+
?loc:Location.t ->
40+
?attrs:attrs ->
41+
42+
val apply_simple:
43+
?loc:Location.t ->
44+
?attrs:attrs ->
45+
expression ->
46+
expression list ->
47+
expression
48+
49+
50+
val fun_ :
51+
?loc:Location.t ->
52+
?attrs:attrs ->
53+
pattern ->
54+
expression ->
55+
expression

jscomp/syntax/ast_derive_dyn.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ let record args =
220220

221221

222222
let fun_1 name =
223-
Exp.fun_ "" None ~attrs:bs_attrs
223+
Ast_compatible.fun_ ~attrs:bs_attrs
224224
(Pat.var {txt = "x"; loc})
225225
(Exp.apply (Exp.ident name)
226226
["",(Exp.ident {txt = Lident "x"; loc})])

jscomp/syntax/ast_derive_js_mapper.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ let init () =
187187
let newTypeStr = Str.type_ [newTdcl] in
188188
let toJsBody body =
189189
Ast_comb.single_non_rec_value patToJs
190-
(Exp.fun_ "" None (Pat.constraint_ (Pat.var pat_param) core_type)
190+
(Ast_compatible.fun_ (Pat.constraint_ (Pat.var pat_param) core_type)
191191
body )
192192
in
193193
let (+>) a ty =
@@ -229,7 +229,7 @@ let init () =
229229
) label_declarations) None in
230230
let fromJs =
231231
Ast_comb.single_non_rec_value patFromJs
232-
(Exp.fun_ "" None (Pat.var pat_param)
232+
(Ast_compatible.fun_ (Pat.var pat_param)
233233
(if createType then
234234
(Exp.let_ Nonrecursive
235235
[Vb.mk
@@ -280,7 +280,7 @@ let init () =
280280
);
281281
Ast_comb.single_non_rec_value
282282
patFromJs
283-
(Exp.fun_ "" None
283+
(Ast_compatible.fun_
284284
(Pat.var pat_param)
285285
(if createType then
286286
revSearchAssert
@@ -334,7 +334,7 @@ let init () =
334334
;
335335
Ast_comb.single_non_rec_value
336336
patFromJs
337-
(Exp.fun_ "" None
337+
(Ast_compatible.fun_
338338
(Pat.var pat_param)
339339
(
340340
if createType then
@@ -370,7 +370,7 @@ let init () =
370370

371371
Ast_comb.single_non_rec_value
372372
{loc ; txt = fromJs}
373-
(Exp.fun_ "" None
373+
(Ast_compatible.fun_
374374
(Pat.var pat_param)
375375
(if createType then
376376
(Exp.let_ Nonrecursive

jscomp/syntax/ast_derive_projector.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let init () =
2828
fun ({pld_name = {loc; txt = pld_label} as pld_name} : Parsetree.label_declaration) ->
2929
let txt = "param" in
3030
Ast_comb.single_non_rec_value pld_name
31-
(Exp.fun_ "" None
31+
(Ast_compatible.fun_
3232
(Pat.constraint_ (Pat.var {txt ; loc}) core_type )
3333
(Exp.field (Exp.ident {txt = Lident txt ; loc})
3434
{txt = Longident.Lident pld_label ; loc}) )
@@ -69,7 +69,7 @@ let init () =
6969
) )) core_type
7070
in
7171
Ext_list.fold_right (fun var b ->
72-
Exp.fun_ "" None (Pat.var {loc ; txt = var}) b
72+
Ast_compatible.fun_ (Pat.var {loc ; txt = var}) b
7373
) vars exp
7474

7575
end)

jscomp/syntax/ast_derive_util.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,20 @@ let new_type_of_type_declaration
5454

5555
let lift_string_list_to_array (labels : string list) =
5656
Exp.array
57-
(Ext_list.map (fun s -> Exp.constant (Const_string (s, None)))
58-
labels)
57+
(Ext_list.map
58+
(* Exp.constant (Const_string (s, None)) *)
59+
(fun s -> Ast_compatible.const_exp_string s )
60+
labels)
5961

60-
let lift_int i = Exp.constant (Const_int i)
62+
(* let lift_int i = Exp.constant (Const_int i)
6163
let lift_int_list_to_array (labels : int list) =
6264
Exp.array (Ext_list.map lift_int labels)
63-
65+
*)
6466

6567
let mk_fun ~loc (typ : Parsetree.core_type)
6668
(value : string) body
6769
: Parsetree.expression =
68-
Exp.fun_
69-
"" None
70+
Ast_compatible.fun_
7071
(Pat.constraint_ (Pat.var {txt = value ; loc}) typ)
7172
body
7273

0 commit comments

Comments
 (0)