Skip to content

Commit de04b90

Browse files
author
Hongbo Zhang
committed
provide bs_dict, more error checking on bs_set_index/get_index
1 parent 0322222 commit de04b90

File tree

14 files changed

+357
-226
lines changed

14 files changed

+357
-226
lines changed

jscomp/.watchmanconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"ignore_dirs": ["_build"]
2+
"ignore_dirs": ["_build", "bin"]
33
}

jscomp/bin/bs_ppx.ml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(** Bundled by bspack 08/19-15:31 *)
1+
(** Bundled by bspack 08/22-17:28 *)
22
module String_map : sig
33
#1 "string_map.mli"
44
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -4255,7 +4255,7 @@ type t =
42554255
| Bs of arg_kind list * arg_type * ffi
42564256
| Normal
42574257

4258-
type prim = Primitive.description
4258+
42594259

42604260

42614261

@@ -4349,7 +4349,7 @@ type ffi =
43494349
| Js_get_index
43504350
| Js_set_index
43514351

4352-
type prim = Primitive.description
4352+
43534353

43544354
let valid_js_char =
43554355
let a = Array.init 256 (fun i ->
@@ -4368,7 +4368,7 @@ let valid_first_js_char =
43684368
(** Approximation could be improved *)
43694369
let valid_ident (s : string) =
43704370
let len = String.length s in
4371-
valid_js_char s.[0] && valid_first_js_char s.[0] &&
4371+
len > 0 && valid_js_char s.[0] && valid_first_js_char s.[0] &&
43724372
(let module E = struct exception E end in
43734373
try
43744374
for i = 1 to len - 1 do
@@ -4379,21 +4379,18 @@ let valid_ident (s : string) =
43794379
with E.E -> false )
43804380

43814381
let valid_global_name ?loc txt =
4382-
let error () =
4383-
Location.raise_errorf ?loc "Not a valid name %s" txt in
4384-
if txt = "" then
4385-
error ()
4386-
else
4382+
if not (valid_ident txt) then
43874383
let v = Ext_string.split_by ~keep_empty:true (fun x -> x = '.') txt in
43884384
List.iter
43894385
(fun s ->
4390-
if not (valid_ident s) then error ()
4386+
if not (valid_ident s) then
4387+
Location.raise_errorf ?loc "Not a valid name %s" txt
43914388
) v
43924389

43934390
let valid_method_name ?loc txt =
4394-
let error () =
4395-
Location.raise_errorf ?loc "Not a valid name %s" txt in
4396-
if not (valid_ident txt) then error ()
4391+
if not (valid_ident txt) then
4392+
Location.raise_errorf ?loc "Not a valid name %s" txt
4393+
43974394

43984395

43994396
let check_external_module_name ?loc x =
@@ -4597,13 +4594,17 @@ let handle_attributes
45974594
Obj_create labels(* Need fetch label here, for better error message *)
45984595
| {set_index = true}
45994596
->
4597+
if String.length prim_name <> 0 then
4598+
Location.raise_errorf ~loc "[@@bs.set_index] expect external names to be empty string";
46004599
begin match arg_types with
46014600
| [_obj; _v ; _value]
46024601
->
46034602
Js_set_index
46044603
| _ -> Location.raise_errorf ~loc "Ill defined attribute [@@bs.set_index](arity of 3)"
46054604
end
4606-
| {get_index = true} ->
4605+
| {get_index = true} ->
4606+
if String.length prim_name <> 0 then
4607+
Location.raise_errorf ~loc "[@@bs.get_index] expect external names to be empty string";
46074608
begin match arg_types with
46084609
| [_obj; _v ] ->
46094610
Js_get_index

jscomp/bin/compiler.ml

Lines changed: 108 additions & 107 deletions
Large diffs are not rendered by default.

jscomp/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ echo "Done"
6666

6767
echo "Make pack tools" >> ./build.compile
6868
make _build/bspack 2>> ./build.compile
69+
70+
# make snapshot
71+
# generate new js_cmj_datasets
72+
make snapshotml
6973
echo "Done" >> ./build.compile

jscomp/js_cmj_datasets.ml

Lines changed: 92 additions & 92 deletions
Large diffs are not rendered by default.

jscomp/others/.depend

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
bs_node.cmi : bs_node_process.cmj bs_node_path.cmj bs_node_fs.cmj
2-
bs_node_fs.cmj :
3-
bs_node_fs.cmx :
41
bs_node_path.cmj :
52
bs_node_path.cmx :
3+
bs_node_fs.cmj :
4+
bs_node_fs.cmx :
65
bs_node_process.cmj :
76
bs_node_process.cmx :
8-
bs_node_fs.cmo :
9-
bs_node_fs.cmj :
7+
bs_dict.cmj :
8+
bs_dict.cmx :
9+
bs_node_module.cmj : bs_node.cmi bs_dict.cmj
10+
bs_node_module.cmx : bs_node.cmi bs_dict.cmx
1011
bs_node_path.cmo :
1112
bs_node_path.cmj :
13+
bs_node_fs.cmo :
14+
bs_node_fs.cmj :
1215
bs_node_process.cmo :
1316
bs_node_process.cmj :
17+
bs_dict.cmo :
18+
bs_dict.cmj :
19+
bs_node_module.cmo : bs_node.cmi bs_dict.cmo
20+
bs_node_module.cmj : bs_node.cmi bs_dict.cmj

jscomp/others/Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ include ../Makefile.shared
22

33
COMPILER=../bin/bsc
44

5-
SOURCE_LIST= bs_node bs_node_path bs_node_fs bs_node_process
5+
MAP_FILES= bs_node bs
66

7+
SOURCE_LIST= bs_node_path bs_node_fs bs_node_process bs_dict bs_node_module
8+
9+
$(addsuffix .cmj, $(MAP_FILES)): bs_node.cmj bs.cmj
710

811
RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST))
912

10-
BS_COMMON_FLAGS= -bs-no-version-header -bs-diagnose -bs-no-check-div-by-zero -bs-cross-module-opt -bs-package-name $(npm_package_name)
13+
BS_COMMON_FLAGS= -no-alias-deps -bs-no-version-header -bs-diagnose -bs-no-check-div-by-zero -bs-cross-module-opt -bs-package-name $(npm_package_name)
1114

1215
ifdef BS_RELEASE_BUILD
1316
BS_FLAGS= $(BS_COMMON_FLAGS) -bs-package-output lib/js -bs-package-output goog:lib/goog -bs-package-output amdjs:lib/amdjs
1417
else
1518
BS_FLAGS= $(BS_COMMON_FLAGS) -bs-package-output lib/js
1619
endif
1720

18-
COMPFLAGS += $(BS_FLAGS) -I ../runtime -I ../stdlib -w -40
21+
COMPFLAGS += $(BS_FLAGS) -I ../runtime -I ../stdlib -w -40 -w -49
1922

2023

2124

@@ -35,9 +38,12 @@ clean::
3538
.ml.cmj:
3639
$(COMPILER) $(INCLUDES) $(COMPFLAGS) -c $<
3740

41+
3842
-include .depend
3943

44+
ML_SOURCES=$(addsuffix .ml, $(SOURCE_LIST))
45+
MLI_SOURCES=$(addsuffix .mli, $(SOURCE_LIST))
4046
depend:
41-
$(CAMLDEP) $(INCLUDES) *.mli *.ml | sed -e 's/\.cmo/.cmj/g' > .depend
42-
$(CAMLDEP) $(INCLUDES) *.ml | sed -e 's/\.cmx/.cmj/g' >>.depend
47+
$(CAMLDEP) $(INCLUDES) $(ML_SOURCES) $(MLI_SOURCES) | sed -e 's/\.cmo/.cmj/g' > .depend
48+
$(CAMLDEP) $(INCLUDES) $(ML_SOURCES) | sed -e 's/\.cmx/.cmj/g' >>.depend
4349

jscomp/others/bs.ml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
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+
27+
28+
module Dict = Bs_dict
29+
30+
module Node = Bs_node

jscomp/others/bs_dict.ml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
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 'a t
27+
type key = string
28+
29+
external get : 'a t -> key -> 'a = ""
30+
[@@bs.get_index]
31+
32+
external set : 'a t -> key -> 'a -> unit = ""
33+
[@@bs.set_index]
34+
35+
external keys : 'a t -> string array = "Object.keys"
36+
[@@bs.val]
37+
38+
external empty : unit -> 'a t = "" [@@bs.obj]
39+
40+

jscomp/others/bs_node.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module Path = Bs_node_path
2929
module Fs = Bs_node_fs
3030

3131
module Process = Bs_node_process
32-
32+
33+
module Module = Bs_node_module
3334
type node_exports
3435
type node_module = <
3536
id : string ;

0 commit comments

Comments
 (0)