Skip to content

Commit 1a2a528

Browse files
committed
[fix] fix playground issues and add missing caml_weak (#283)
1 parent 4402210 commit 1a2a528

14 files changed

+143
-22
lines changed

jscomp/Makefile.shared

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CAMLOPT=ocamlopt.opt
55

66

77

8+
89
.SUFFIXES: .mli .ml .cmi .cmo .cmx .p.cmx .cmj .js
910

1011
print-% : ; @echo $* = $($*)

jscomp/js_config.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ let float = "Caml_float"
137137
let hash = "Caml_hash"
138138
let oo = "Caml_oo"
139139
let curry = "Curry"
140-
let internalMod = "Caml_internalMod"
141140
let bigarray = "Caml_bigarray"
142141
let unix = "Caml_unix"
143142
let int64 = "Caml_int64"
@@ -161,7 +160,6 @@ let runtime_set =
161160
hash ;
162161
oo ;
163162
curry ;
164-
internalMod ;
165163
bigarray ;
166164
unix ;
167165
int64 ;

jscomp/js_config.mli

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,19 @@ val runtime_set : String_set.t
3535
val stdlib_set : String_set.t
3636

3737
val prim : string
38-
3938
val builtin_exceptions : string
4039
val exceptions : string
4140
val io : string
42-
4341
val oo : string
44-
4542
val sys : string
46-
4743
val lexer : string
4844
val parser : string
4945
val obj_runtime : string
50-
5146
val array : string
52-
5347
val format : string
54-
5548
val string : string
56-
5749
val float : string
58-
5950
val curry : string
60-
61-
val internalMod : string
62-
6351
val bigarray : string
6452
val unix : string
6553
val int64 : string

jscomp/js_dump.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
12871287
P.string f " ";
12881288
let id = Ext_ident.create (Ident.name id ^ "_finish") in
12891289
let cxt = ident cxt f id in
1290-
P.string f " = ";
1290+
P.string f " = "; (* FIXME: space *)
12911291
expression 15 cxt f finish, Some id
12921292
) in
12931293
semi f ;
@@ -1585,7 +1585,6 @@ let amd_program f
15851585
) in
15861586
P.string f ")";
15871587
v
1588-
;;
15891588

15901589
let pp_deps_program ( program : J.deps_program) (f : Ext_pp.t) =
15911590
begin

jscomp/js_dump.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828

29-
29+
val pp_deps_program : J.deps_program -> Ext_pp.t -> unit
3030

3131
val dump_deps_program : J.deps_program -> out_channel -> unit
3232

jscomp/js_program_loader.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ let string_of_module_id (x : Lam_module_ident.t) : string =
4848
| Browser
4949
(* In browser *)
5050
->
51-
let target = String.uncapitalize file in
51+
let target = Filename.chop_extension @@ String.uncapitalize file in
5252
if String_set.mem target Js_config.runtime_set then
53-
"./runtime/" ^ Filename.chop_extension target
53+
"./runtime/" ^ target
5454
else
55-
"./stdlib/" ^ Filename.chop_extension target
55+
"./stdlib/" ^ target
5656
| AmdJS
5757
| NodeJS ->
5858
let filename = String.uncapitalize id.name in

jscomp/jsoo_driver.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let implementation non_export ppf str =
5050
|> Translmod.transl_implementation modulename
5151
|> (* Printlambda.lambda ppf *) (fun lam ->
5252
let buffer = Buffer.create 1000 in
53-
let () = Js_dump.(pp_program
53+
let () = Js_dump.(pp_deps_program
5454
(Lam_compile_group.compile ~filename:"" non_export
5555
!finalenv !types_signature lam)
5656
(Ext_pp.from_buffer buffer)) in

jscomp/lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SOURCE_LIST := $(shell cat lib.mllib)
77
RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST))
88

99
INCLUDES := -I ../runtime
10+
# COMPFLAGS := -js-module amdjs
1011
# COMPFLAGS += -js-module goog:buckle.js
1112

1213
$(RUNTIME): $(CAMLC)

jscomp/runtime/.depend

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ caml_queue.cmi :
1616
caml_string.cmi :
1717
caml_sys.cmi :
1818
caml_utils.cmi :
19+
caml_weak.cmi :
1920
caml_array.cmo : js.cmo caml_array.cmi
2021
caml_array.cmx : js.cmx caml_array.cmi
2122
caml_bigarray.cmo : caml_bigarray.cmi
@@ -54,6 +55,8 @@ caml_sys.cmo : js.cmo caml_sys.cmi
5455
caml_sys.cmx : js.cmx caml_sys.cmi
5556
caml_utils.cmo : caml_utils.cmi
5657
caml_utils.cmx : caml_utils.cmi
58+
caml_weak.cmo : js.cmo caml_array.cmi caml_weak.cmi
59+
caml_weak.cmx : js.cmx caml_array.cmx caml_weak.cmi
5760
curry.cmo : js.cmo caml_oo.cmi
5861
curry.cmx : js.cmx caml_oo.cmx
5962
fn.cmo :
@@ -102,6 +105,8 @@ caml_sys.cmo : js.cmo caml_sys.cmi
102105
caml_sys.cmj : js.cmj caml_sys.cmi
103106
caml_utils.cmo : caml_utils.cmi
104107
caml_utils.cmj : caml_utils.cmi
108+
caml_weak.cmo : js.cmo caml_array.cmi caml_weak.cmi
109+
caml_weak.cmj : js.cmj caml_array.cmj caml_weak.cmi
105110
curry.cmo : js.cmo caml_oo.cmi
106111
curry.cmj : js.cmj caml_oo.cmj
107112
fn.cmo :

jscomp/runtime/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ CAMLC=../bin/bsc
55
SOURCE_LIST := $(shell cat runtime.mllib)
66

77
RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST))
8-
COMPFLAGS := -w -40 -safe-string
8+
9+
# COMPFLAGS := -js-module amdjs
10+
COMPFLAGS += -w -40 -safe-string
911
# COMPFLAGS += -js-module goog:buckle.runtime
1012

13+
1114
$(RUNTIME): $(CAMLC)
1215

1316
all: $(RUNTIME)

jscomp/runtime/caml_weak.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Generated CODE, PLEASE EDIT WITH CARE
2+
'use strict';
3+
4+
var Caml_obj = require("./caml_obj");
5+
var Caml_array = require("./caml_array");
6+
7+
function caml_weak_create(n) {
8+
return new Array(n);
9+
}
10+
11+
function caml_weak_set(xs, i, v) {
12+
if (v) {
13+
xs[i] = v[0];
14+
return /* () */0;
15+
}
16+
else {
17+
return /* () */0;
18+
}
19+
}
20+
21+
function caml_weak_get(xs, i) {
22+
v = xs[i];
23+
if (v === undefined) {
24+
return /* None */0;
25+
}
26+
else {
27+
return [v];
28+
}
29+
}
30+
31+
function caml_weak_get_copy(xs, i) {
32+
var match = xs[i];
33+
if (match === undefined) {
34+
return /* None */0;
35+
}
36+
else {
37+
return /* Some */[Caml_obj.caml_obj_dup(match)];
38+
}
39+
}
40+
41+
function caml_weak_check(xs, i) {
42+
return xs[i] !== undefined;
43+
}
44+
45+
var caml_weak_blit = Caml_array.caml_array_blit;
46+
47+
exports.caml_weak_create = caml_weak_create;
48+
exports.caml_weak_set = caml_weak_set;
49+
exports.caml_weak_get = caml_weak_get;
50+
exports.caml_weak_get_copy = caml_weak_get_copy;
51+
exports.caml_weak_check = caml_weak_check;
52+
exports.caml_weak_blit = caml_weak_blit;
53+
/* No side effect */

jscomp/runtime/caml_weak.ml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(* BuckleScript compiler
2+
* Copyright (C) 2015-2016 Bloomberg Finance L.P.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, with linking exception;
7+
* either version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
*)
18+
19+
(* Author: Hongbo Zhang *)
20+
21+
type 'a t = 'a Js.def array
22+
23+
let caml_weak_create n =
24+
Js.Array.new_uninitialized n
25+
26+
let caml_weak_set xs i v =
27+
match v with
28+
| Some x -> xs.(i) <- Js.to_def x
29+
| None -> ()
30+
31+
let caml_weak_get xs i =
32+
Js.from_def xs.(i)
33+
34+
let caml_weak_get_copy xs i =
35+
match Js.from_def xs.(i) with
36+
| None -> None
37+
| Some x -> Some (Obj.magic (Obj.dup (Obj.repr x) ))
38+
39+
let caml_weak_check xs i =
40+
not @@ Js.is_undef xs.(i)
41+
42+
let caml_weak_blit = Caml_array.caml_array_blit

jscomp/runtime/caml_weak.mli

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(* BuckleScript compiler
2+
* Copyright (C) 2015-2016 Bloomberg Finance L.P.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, with linking exception;
7+
* either version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
*)
18+
19+
(* Author: Hongbo Zhang *)
20+
21+
22+
type 'a t
23+
24+
val caml_weak_create : int -> 'a t
25+
val caml_weak_set : 'a t -> int -> 'a option -> unit
26+
val caml_weak_get : 'a t -> int -> 'a option
27+
val caml_weak_get_copy : 'a t -> int -> 'a option
28+
val caml_weak_check : 'a t -> int -> bool
29+
val caml_weak_blit : 'a t -> int -> 'a t -> int -> int -> unit

jscomp/stdlib/Makefile.shared

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ CAMLC=$(CAMLRUN) $(COMPILER)
2323
# -safe-string
2424
COMPFLAGS=-strict-sequence -w +33..39 -g -warn-error A -nostdlib \
2525
-safe-string
26+
27+
# COMPFLAGS += -js-module amdjs
2628
# COMPFLAGS+= -js-module goog:buckle.std
2729

2830
# OPTCOMPILER=ocamlopt.opt

0 commit comments

Comments
 (0)