Skip to content

Commit f3d17d9

Browse files
committed
adapt runtime, fun%raw is not needed any more
1 parent cfd3243 commit f3d17d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+283277
-3350
lines changed

jscomp/others/js_dict.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ external empty : unit -> 'a t = "" [@@bs.obj]
5454

5555

5656
let unsafeDeleteKey : string t -> string -> unit [@bs] =
57-
fun%raw dict key -> {|
57+
[%raw {| function (dict,key){
5858
delete dict[key];
5959
return 0
60-
|}
60+
}
61+
|}]
6162

6263

6364
external unsafeCreate : int -> 'a array = "Array" [@@bs.new]

jscomp/runtime/caml_chrome_debugger.ml

+11-9
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
type obj = Caml_obj_extern.t
26-
27-
let setupChromeDebugger : unit -> unit = fun%raw unit -> {|
25+
type obj = Caml_obj_extern.t
26+
open Js_internalRaw
27+
let setupChromeDebugger : unit -> unit = [%raw{|function(_){
2828

2929
// I don't know how to directly refer to the classes that chrome's built-in
3030
// formatters use. adding "class": "foo" doesn't seem to work
@@ -141,8 +141,8 @@ if (typeof window === "undefined"){
141141
window.devtoolsFormatters = [formatter]
142142
}
143143
return 0
144-
145-
|}
144+
}
145+
|}]
146146

147147

148148
let setup = ref false
@@ -155,10 +155,12 @@ let setupOnce () =
155155

156156
type symbol
157157

158+
type 'a t = { value : 'a}
158159

159160
external cacheSymbol : string -> symbol = "for"
160161
[@@bs.scope "Symbol"] [@@bs.val]
161-
external addProp : 'a -> symbol -> <value: 'b> Js.t -> 'a =
162+
163+
external addProp : 'a -> symbol -> 'b t -> 'a =
162164
"defineProperty" [@@bs.scope "Object"] [@@bs.val]
163165

164166
let __ = Block.__
@@ -167,13 +169,13 @@ let __ = Block.__
167169
let variant meta tag xs =
168170
setupOnce ();
169171
xs |. Caml_obj_extern.set_tag tag;
170-
xs |. addProp (cacheSymbol "BsVariant") [%obj {value = meta }]
172+
xs |. addProp (cacheSymbol "BsVariant") {value = meta }
171173

172174
let simpleVariant meta xs =
173175
setupOnce ();
174-
xs |. addProp (cacheSymbol "BsVariant") [%obj {value = meta }]
176+
xs |. addProp (cacheSymbol "BsVariant") {value = meta }
175177

176178

177179
let polyVar meta xs =
178180
setupOnce ();
179-
xs |. addProp (cacheSymbol "BsPolyVar") [%obj {value = meta}]
181+
xs |. addProp (cacheSymbol "BsPolyVar") {value = meta}

jscomp/runtime/caml_external_polyfill.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24-
25-
let getGlobalThis= fun%raw () -> {|
24+
open Js_internalRaw
25+
let getGlobalThis= [%raw{| function(){
2626
if (typeof globalThis !== 'undefined') return globalThis;
2727
if (typeof self !== 'undefined') return self;
2828
if (typeof window !== 'undefined') return window;
2929
if (typeof global !== 'undefined') return global;
3030
if (typeof this !== 'undefined') return this;
3131
throw new Error('Unable to locate global `this`');
32-
|}
32+
}|}]
3333

34-
let resolve = fun%raw s -> {|
34+
let resolve = [%raw {|function(s){
3535
var myGlobal = getGlobalThis();
3636
if (myGlobal[s] === undefined){
3737
throw new Error(s + " not polyfilled by BuckleScript yet\n")
3838
}
3939
return myGlobal[s]
40-
|}
40+
}|}]
4141

4242
(* FIXME: it does not have to global states *)
4343
type fn
4444

4545

46-
let register : string -> fn -> unit = fun%raw s fn -> {|
46+
let register : string -> fn -> unit = [%raw{| function(s,fn){
4747
var myGlobal = getGlobalThis();
4848
myGlobal[s] = fn
4949
return 0
50-
|}
50+
}|}]

jscomp/runtime/caml_float.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
25+
open Js_internalRaw
2626
(** *)
2727

2828
(* borrowed from others/js_math.ml *)
@@ -37,16 +37,16 @@ external pow_float : base:float -> exp:float -> float = "Math.pow" [@@bs.val]
3737
external int_of_float : float -> int = "%intoffloat"
3838
external float_of_int : int -> float = "%floatofint"
3939

40-
let caml_int32_float_of_bits : int32 -> float = fun%raw x -> {|
40+
let caml_int32_float_of_bits : int32 -> float = [%raw{|function(x){
4141
return new Float32Array(new Int32Array([x]).buffer)[0]
42-
|}
42+
}|}]
4343
(* let int32 = Int32_array.make [| x |] in
4444
let float32 = Float32_array.fromBuffer ( Int32_array.buffer int32) in
4545
Float32_array.unsafe_get float32 0 *)
4646

47-
let caml_int32_bits_of_float : float -> int32 = fun%raw x -> {|
47+
let caml_int32_bits_of_float : float -> int32 = [%raw{|function(x){
4848
return new Int32Array(new Float32Array([x]).buffer)[0]
49-
|}
49+
}|}]
5050
(* let float32 = Float32_array.make [|x|] in
5151
Int32_array.unsafe_get (Int32_array.fromBuffer (Float32_array.buffer float32)) 0 *)
5252

jscomp/runtime/caml_format.ml

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828

29-
29+
open Js_internalRaw
3030

3131
(** *)
3232

@@ -581,8 +581,11 @@ let caml_format_float fmt x =
581581
end;
582582
finish_formatting f s.contents
583583

584+
585+
586+
584587
let caml_hexstring_of_float : float -> int -> char -> string =
585-
fun%raw x prec style -> {|
588+
[%raw{|function(x,prec,style){
586589
if (!isFinite(x)) {
587590
if (isNaN(x)) return "nan";
588591
return x > 0 ? "infinity":"-infinity";
@@ -626,11 +629,11 @@ let caml_hexstring_of_float : float -> int -> char -> string =
626629
}
627630
}
628631
return (sign_str + '0x' + x_str + 'p' + exp_sign + exp.toString(10));
629-
|}
632+
}|}]
630633

631634

632635
let float_of_string : string -> exn -> float =
633-
fun%raw s exn -> {|
636+
[%raw{|function(s,exn){
634637

635638
var res = +s;
636639
if ((s.length > 0) && (res === res))
@@ -654,8 +657,8 @@ let float_of_string : string -> exn -> float =
654657
if (/^-inf(inity)?$/i.test(s))
655658
return -Infinity;
656659
throw exn;
657-
658-
|}
660+
}
661+
|}]
659662

660663

661664

jscomp/runtime/caml_int64.ml

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626

27-
27+
open Js_internalRaw
2828

2929
(* This module would only work with js backend, since it requires
3030
[nativeint] behaves as js numbers
@@ -429,9 +429,7 @@ let discard_sign (x : int64) : int64 =
429429
*)
430430

431431
let float_of_bits ( x : t) : float =
432-
(fun%raw lo hi -> {|
433-
return (new Float64Array(new Int32Array([lo,hi]).buffer))[0]
434-
|} : _ -> _ -> _ ) x.lo x.hi
432+
([%raw{|function(lo,hi){ return (new Float64Array(new Int32Array([lo,hi]).buffer))[0]}|}] : _ -> _ -> _ ) x.lo x.hi
435433

436434
(* let to_int32 (x : nativeint) = x |> Caml_nativeint_extern.to_int32
437435
in
@@ -444,7 +442,7 @@ let float_of_bits ( x : t) : float =
444442
Float64_array.unsafe_get (Float64_array.fromBuffer (Int32_array.buffer int32)) 0 *)
445443

446444
let bits_of_float : float -> t = fun x ->
447-
let buf = [%raw{|new Int32Array(new Float64Array([x]).buffer)|}] in
445+
let buf = ([%raw{|function(x){return new Int32Array(new Float64Array([x]).buffer)}|}] : _ -> _) x in
448446
mk ~lo:(fst buf) ~hi:(snd buf)
449447
(* let to_nat (x : int32) = x |> Caml_int32_extern.to_int |> Caml_nativeint_extern.of_int in
450448

jscomp/runtime/caml_io.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
26+
open Js_internalRaw
2727

2828
let stdin = Caml_undefined_extern.empty
2929
let stderr = Caml_undefined_extern.empty
@@ -77,9 +77,9 @@ let caml_ml_flush (oc : out_channel) : unit =
7777
oc.buffer <- ""
7878
end
7979

80-
let node_std_output : string -> bool = fun%raw s -> {|
81-
return (typeof process !== "undefined") && process.stdout && (process.stdout.write(s), true);
82-
|}
80+
let node_std_output : string -> bool =
81+
[%raw{|function(s){ return (typeof process !== "undefined") && process.stdout && (process.stdout.write(s), true);}
82+
|}]
8383

8484

8585
(** note we need provide both [bytes] and [string] version
@@ -88,9 +88,9 @@ let caml_ml_output (oc : out_channel) (str : string) offset len =
8888
let str =
8989
if offset = 0 && len =Caml_string_extern.length str then str
9090
else Caml_string_extern.slice str offset len in
91-
if [%bs.raw{| (typeof process !== "undefined") && process.stdout && process.stdout.write |}] &&
91+
if [%raw{| (typeof process !== "undefined") && process.stdout && process.stdout.write |}] &&
9292
oc == stdout then
93-
([%bs.raw{| process.stdout.write |}] : string -> unit [@bs] ) str [@bs]
93+
([%raw{| process.stdout.write |}] : string -> unit [@bs] ) str [@bs]
9494

9595
else
9696
begin

jscomp/runtime/caml_lexer.ml

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
26+
open Js_internalRaw
2727

2828
type lex_tables
2929
type lexbuf
@@ -104,7 +104,7 @@ function caml_lex_array(s) {
104104
* @param lexbuf
105105
* @returns {any}
106106
*)
107-
let caml_lex_engine_aux : lex_tables -> int -> lexbuf -> exn -> int = fun%raw tbl start_state lexbuf exn -> {|
107+
let caml_lex_engine_aux : lex_tables -> int -> lexbuf -> exn -> int = [%raw{|function (tbl, start_state, lexbuf, exn){
108108
// Lexing.lexbuf
109109
var lex_buffer = 'lex_buffer';
110110
var lex_buffer_len = 'lex_buffer_len';
@@ -186,7 +186,8 @@ let caml_lex_engine_aux : lex_tables -> int -> lexbuf -> exn -> int = fun%raw tb
186186
lexbuf[lex_eof_reached] = 0;
187187
}
188188
}
189-
|}
189+
}
190+
|}]
190191

191192
let empty_token_lit = "lexing: empty token"
192193

@@ -252,7 +253,7 @@ function caml_lex_run_tag(s, i, mem) {
252253
*)
253254

254255

255-
let caml_new_lex_engine_aux : lex_tables -> int -> lexbuf -> exn -> int= fun%raw tbl start_state lexbuf exn -> {|
256+
let caml_new_lex_engine_aux : lex_tables -> int -> lexbuf -> exn -> int= [%raw{|function (tbl, start_state, lexbuf, exn) {
256257
// Lexing.lexbuf
257258
var lex_buffer = 'lex_buffer';
258259
var lex_buffer_len = 'lex_buffer_len';
@@ -357,7 +358,8 @@ let caml_new_lex_engine_aux : lex_tables -> int -> lexbuf -> exn -> int= fun%raw
357358
lexbuf[lex_eof_reached] = 0;
358359
}
359360
}
360-
|}
361+
}
362+
|}]
361363

362364

363365

jscomp/runtime/caml_obj.ml

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
26+
open Js_internalRaw
2727

2828

2929

@@ -36,9 +36,9 @@ module O = struct
3636
external isArray : 'a -> bool = "Array.isArray" [@@bs.val]
3737
type key = string
3838
let for_in : (Caml_obj_extern.t -> (key -> unit) -> unit) =
39-
fun%raw o foo -> {|
40-
for (var x in o) { foo(x) }
41-
|}
39+
[%raw{|function(o,foo){
40+
for (var x in o) { foo(x) }}
41+
|}]
4242

4343
let hasOwnProperty (o: Caml_obj_extern.t) (key: key) : bool = (Obj.magic o)##hasOwnProperty(key)
4444
external get_value : Caml_obj_extern.t -> key -> Caml_obj_extern.t = ""[@@bs.get_index]
@@ -135,12 +135,13 @@ let caml_lazy_make (fn : _ -> _) =
135135
In most cases, rec value comes from record/modules,
136136
whose tag is 0, we optimize that case
137137
*)
138-
let caml_update_dummy : _ -> _ -> unit= fun%raw x y -> {|
138+
let caml_update_dummy : _ -> _ -> unit= [%raw{|function(x,y){
139139
for (var k in y){
140140
x[k] = y[k]
141141
}
142142
return 0;
143-
|}
143+
}
144+
|}]
144145

145146
(* Caml_obj_extern.set_length x (Caml_obj_extern.length y) *)
146147
(* [set_length] seems redundant here given that it is initialized as an array

jscomp/runtime/caml_parser.ml

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* along with this program; if not, write to the Free Software
2525
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2626

27-
27+
open Js_internalRaw
2828

2929
(** *)
3030

@@ -156,7 +156,8 @@ type parse_tables
156156
type parser_env
157157

158158

159-
let caml_parse_engine : parse_tables -> parser_env -> (*Parsing.parser_input *)Caml_obj_extern.t -> Caml_obj_extern.t -> Caml_obj_extern.t = fun%raw tables (* parser_table *) env (* parser_env *) cmd (* parser_input*) arg (* Caml_obj_extern.t*) -> {|
159+
let caml_parse_engine : parse_tables -> parser_env -> (*Parsing.parser_input *)Caml_obj_extern.t -> Caml_obj_extern.t -> Caml_obj_extern.t =
160+
[%raw{|function (tables /* parser_table */, env /* parser_env */, cmd /* parser_input*/, arg /* Caml_obj_extern.t*/) {
160161
var ERRCODE = 256;
161162
//var START = 0;
162163
//var TOKEN_READ = 1;
@@ -379,7 +380,7 @@ let caml_parse_engine : parse_tables -> parser_env -> (*Parsing.parser_input *)C
379380
env[env_state] = state;
380381
env[env_errflag] = errflag;
381382
return res;
382-
|}
383+
}|}]
383384

384385

385386
(**
@@ -388,8 +389,8 @@ let caml_parse_engine : parse_tables -> parser_env -> (*Parsing.parser_input *)C
388389
* @param {boolean}
389390
* @returns {boolean}
390391
*)
391-
let caml_set_parser_trace : bool -> bool = fun%raw v -> {|
392+
let caml_set_parser_trace : bool -> bool = [%raw{|function (v) {
392393
var old = PARSER_TRACE;
393394
PARSER_TRACE = v;
394395
return old;
395-
|}
396+
}|}]

0 commit comments

Comments
 (0)