Skip to content

Commit 6adc517

Browse files
Change char payload (#5759)
* change Pconst_char payload (WIP) * tweak * tweak * representation of char for lambda * lib * bugfix: replace wrong pp * libs * bugfix: replace wrong print * use unsafe_chr to handle possible overflow char * safe print int as char * reduce duplication * (re)use encodeCodepoint to support string_of_int_as_char * some refactor * libs * changelog
1 parent f10725b commit 6adc517

Some content is hidden

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

42 files changed

+28927
-25690
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
- Add `loading`, `aria-*` DOM element attributes in `JsxDOM.domProps`: `ariaCurrent`, `ariaInvalid`, `ariaAutocomplete`, etc.
5858
- Change the internal representation of props for the lowercase components to record. https://github.com/rescript-lang/syntax/pull/665
59+
- Change the payload of Pconst_char for type safety. https://github.com/rescript-lang/syntax/pull/709
5960

6061
# 10.1.0-alpha.2
6162

jscomp/core/js_dump.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
630630
match v with
631631
| Float { f } -> Js_number.caml_float_literal_to_js_string f
632632
(* attach string here for float constant folding?*)
633-
| Int { i; c = Some c } -> Format.asprintf "/* %C */%ld" c i
633+
| Int { i; c = Some c } -> Format.asprintf "/* %s */%ld" (Ext_util.string_of_int_as_char c) i
634634
| Int { i; c = None } ->
635635
Int32.to_string i
636636
(* check , js convention with ocaml lexical convention *)

jscomp/core/js_exp_make.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ val method_ :
103103

104104
val econd : ?comment:string -> t -> t -> t -> t
105105

106-
val int : ?comment:string -> ?c:char -> int32 -> t
106+
val int : ?comment:string -> ?c:int -> int32 -> t
107107

108108
val uint32 : ?comment:string -> int32 -> t
109109

jscomp/core/js_of_lam_string.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module E = Js_exp_make
2929
currently, it follows the same patten of ocaml, [char] is [int]
3030
*)
3131

32-
let const_char (i : char) = E.int ~c:i (Int32.of_int @@ Char.code i)
32+
let const_char (i : int) = E.int ~c:i (Int32.of_int @@ i)
3333

3434
(* string [s[i]] expects to return a [ocaml_char] *)
3535
let ref_string e e1 = E.string_index e e1

jscomp/core/js_of_lam_string.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ val ref_byte : J.expression -> J.expression -> J.expression
3434

3535
val set_byte : J.expression -> J.expression -> J.expression -> J.expression
3636

37-
val const_char : char -> J.expression
37+
val const_char : int -> J.expression
3838

3939
val bytes_to_string : J.expression -> J.expression

jscomp/core/js_op.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ type float_lit = { f : string } [@@unboxed]
126126

127127
type number =
128128
| Float of float_lit
129-
| Int of { i : int32; c : char option }
129+
| Int of { i : int32; c : int option }
130130
| Uint of int32
131131

132132
(* becareful when constant folding +/-,

jscomp/core/lam.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
562562
| ( (Pstringrefs | Pstringrefu),
563563
Const_string { s = a; unicode = false },
564564
Const_int { i = b } ) -> (
565-
try Lift.char (String.get a (Int32.to_int b)) with _ -> default ())
565+
try Lift.char (Char.code (String.get a (Int32.to_int b))) with _ -> default ())
566566
| _ -> default ())
567567
| _ -> (
568568
match prim with
@@ -633,7 +633,7 @@ let rec complete_range (sw_consts : (int * _) list) ~(start : int) ~finish =
633633
let rec eval_const_as_bool (v : Lam_constant.t) : bool =
634634
match v with
635635
| Const_int { i = x } -> x <> 0l
636-
| Const_char x -> Char.code x <> 0
636+
| Const_char x -> x <> 0
637637
| Const_int64 x -> x <> 0L
638638
| Const_js_false | Const_js_null | Const_module_alias | Const_js_undefined ->
639639
false

jscomp/core/lam_constant.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type t =
4242
| Const_js_true
4343
| Const_js_false
4444
| Const_int of { i : int32; comment : pointer_info }
45-
| Const_char of char
45+
| Const_char of int
4646
| Const_string of { s : string; unicode : bool }
4747
| Const_float of string
4848
| Const_int64 of int64

jscomp/core/lam_constant.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type t =
3838
| Const_js_true
3939
| Const_js_false
4040
| Const_int of { i : int32; comment : pointer_info }
41-
| Const_char of char
41+
| Const_char of int
4242
| Const_string of { s : string; unicode : bool }
4343
| Const_float of string
4444
| Const_int64 of int64

jscomp/core/lam_pass_lets_dce.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
209209
|Lconst((Const_int {i})) ->
210210
let i = Int32.to_int i in
211211
if i < String.length l_s && i >= 0 then
212-
Lam.const ((Const_char l_s.[i]))
212+
Lam.const ((Const_char (Char.code l_s.[i])))
213213
else
214214
Lam.prim ~primitive ~args:[l';r'] loc
215215
| _ ->

0 commit comments

Comments
 (0)