Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
match v with
| Float { f } -> Js_number.caml_float_literal_to_js_string f
(* attach string here for float constant folding?*)
| Int { i; c = Some c } -> Format.asprintf "/* %C */%ld" c i
| Int { i; c = Some c } -> Format.asprintf "/* %C */%ld" (Char.unsafe_chr c) i
| Int { i; c = None } ->
Int32.to_string i
(* check , js convention with ocaml lexical convention *)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_exp_make.mli
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ val method_ :

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_of_lam_string.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module E = Js_exp_make
currently, it follows the same patten of ocaml, [char] is [int]
*)

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

(* string [s[i]] expects to return a [ocaml_char] *)
let ref_string e e1 = E.string_index e e1
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_of_lam_string.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ val ref_byte : J.expression -> J.expression -> J.expression

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

val const_char : char -> J.expression
val const_char : int -> J.expression

val bytes_to_string : J.expression -> J.expression
2 changes: 1 addition & 1 deletion jscomp/core/js_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type float_lit = { f : string } [@@unboxed]

type number =
| Float of float_lit
| Int of { i : int32; c : char option }
| Int of { i : int32; c : int option }
| Uint of int32

(* becareful when constant folding +/-,
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
| ( (Pstringrefs | Pstringrefu),
Const_string { s = a; unicode = false },
Const_int { i = b } ) -> (
try Lift.char (String.get a (Int32.to_int b)) with _ -> default ())
try Lift.char (Char.code (String.get a (Int32.to_int b))) with _ -> default ())
| _ -> default ())
| _ -> (
match prim with
Expand Down Expand Up @@ -633,7 +633,7 @@ let rec complete_range (sw_consts : (int * _) list) ~(start : int) ~finish =
let rec eval_const_as_bool (v : Lam_constant.t) : bool =
match v with
| Const_int { i = x } -> x <> 0l
| Const_char x -> Char.code x <> 0
| Const_char x -> x <> 0
| Const_int64 x -> x <> 0L
| Const_js_false | Const_js_null | Const_module_alias | Const_js_undefined ->
false
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_constant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type t =
| Const_js_true
| Const_js_false
| Const_int of { i : int32; comment : pointer_info }
| Const_char of char
| Const_char of int
| Const_string of { s : string; unicode : bool }
| Const_float of string
| Const_int64 of int64
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_constant.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type t =
| Const_js_true
| Const_js_false
| Const_int of { i : int32; comment : pointer_info }
| Const_char of char
| Const_char of int
| Const_string of { s : string; unicode : bool }
| Const_float of string
| Const_int64 of int64
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_pass_lets_dce.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
|Lconst((Const_int {i})) ->
let i = Int32.to_int i in
if i < String.length l_s && i >= 0 then
Lam.const ((Const_char l_s.[i]))
Lam.const ((Const_char (Char.code l_s.[i])))
else
Lam.prim ~primitive ~args:[l';r'] loc
| _ ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_pass_lets_dce.pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
|Lconst((Const_int {i})) ->
let i = Int32.to_int i in
if i < String.length l_s && i >= 0 then
Lam.const ((Const_char l_s.[i]))
Lam.const ((Const_char (Char.code l_s.[i])))
else
Lam.prim ~primitive ~args:[l';r'] loc
| _ ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let rec struct_const ppf (cst : Lam_constant.t) =
| Const_module_alias -> fprintf ppf "#alias"
| Const_js_undefined -> fprintf ppf "#undefined"
| Const_int { i } -> fprintf ppf "%ld" i
| Const_char c -> fprintf ppf "%C" c
| Const_char c -> fprintf ppf "%C" (Char.unsafe_chr c)
| Const_string { s } -> fprintf ppf "%S" s
| Const_float f -> fprintf ppf "%s" f
| Const_int64 n -> fprintf ppf "%LiL" n
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module Const = struct
let int64 ?(suffix='L') i = integer ~suffix (Int64.to_string i)
let nativeint ?(suffix='n') i = integer ~suffix (Nativeint.to_string i)
let float ?suffix f = Pconst_float (f, suffix)
let char c = Pconst_char c
let char c = Pconst_char (Char.code c)
let string ?quotation_delimiter s = Pconst_string (s, quotation_delimiter)
end

Expand Down
4 changes: 2 additions & 2 deletions jscomp/ml/asttypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

type constant =
Const_int of int
| Const_char of char
| Const_char of int
| Const_string of string * string option
| Const_float of string
| Const_int32 of int32
Expand Down Expand Up @@ -70,4 +70,4 @@ let same_arg_label (x : arg_label) y =
begin match y with
| Optional s0 -> s = s0
| _ -> false
end
end
2 changes: 1 addition & 1 deletion jscomp/ml/matching.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ let combine_constant names loc arg cst partial ctx def
call_switcher loc fail arg min_int max_int int_lambda_list names
| Const_char _ ->
let int_lambda_list =
List.map (function Const_char c, l -> (Char.code c, l)
List.map (function Const_char c, l -> (c, l)
| _ -> assert false)
const_lambda_list in
call_switcher loc fail arg 0 max_int int_lambda_list names
Expand Down
6 changes: 3 additions & 3 deletions jscomp/ml/parmatch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ let is_cons = function

let pretty_const c = match c with
| Const_int i -> Printf.sprintf "%d" i
| Const_char c -> Printf.sprintf "%C" c
| Const_char i -> Printf.sprintf "%C" (Char.unsafe_chr i)
| Const_string (s, _) -> Printf.sprintf "%S" s

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printast.string_of_int_as_char vs Ext_util.string_of_int_as_char?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems they are the same but shared across two repos

| Const_float f -> Printf.sprintf "%s" f
| Const_int32 i -> Printf.sprintf "%ldl" i
Expand Down Expand Up @@ -1088,9 +1088,9 @@ let build_other ext env : Typedtree.pattern = match env with
| ({pat_desc=(Tpat_constant (Const_char _ ))} as p,_) :: _ ->
build_other_constant
(function
| Tpat_constant (Const_char i) -> Char.code i
| Tpat_constant (Const_char i) -> i
| _ -> assert false)
(function i -> Tpat_constant(Const_char (Obj.magic (i:int) : char)))
(function i -> Tpat_constant(Const_char (i)))
0 succ p env
| ({pat_desc=(Tpat_constant (Const_int32 _))} as p,_) :: _ ->
build_other_constant
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11015,7 +11015,7 @@ let yyact = [|
let _1 = (Parsing.peek_val __caml_parser_env 0 : char) in
Obj.repr(
# 2155 "ml/parser.mly"
( Pconst_char _1 )
( Pconst_char (Char.code _1) )
# 11020 "ml/parser.ml"
: 'constant))
; (fun __caml_parser_env ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ label:

constant:
| INT { let (n, m) = $1 in Pconst_integer (n, m) }
| CHAR { Pconst_char $1 }
| CHAR { Pconst_char (Char.code $1) }
| STRING { let (s, d) = $1 in Pconst_string (s, d) }
| FLOAT { let (f, m) = $1 in Pconst_float (f, m) }
;
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/parsetree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type constant =
Suffixes [g-z][G-Z] are accepted by the parser.
Suffixes except 'l', 'L' and 'n' are rejected by the typechecker
*)
| Pconst_char of char
| Pconst_char of int
(* 'c' *)
| Pconst_string of string * string option
(* "constant"
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ let rec longident f = function
let longident_loc f x = pp f "%a" longident x.txt

let constant f = function
| Pconst_char i -> pp f "%C" i
| Pconst_char i -> pp f "%C" (Char.unsafe_chr i)
| Pconst_string (i, None) -> pp f "%S" i
| Pconst_string (i, Some delim) -> pp f "{%s|%s|%s}" delim i delim
| Pconst_integer (i, None) -> paren (i.[0]='-') (fun f -> pp f "%s") f i
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/pprintast.pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ let rec longident f = function
let longident_loc f x = pp f "%a" longident x.txt

let constant f = function
| Pconst_char i -> pp f "%C" i
| Pconst_char i -> pp f "%C" (Char.chr i)
| Pconst_string (i, None) -> pp f "%S" i
| Pconst_string (i, Some delim) -> pp f "{%s|%s|%s}" delim i delim
| Pconst_integer (i, None) -> paren (i.[0]='-') (fun f -> pp f "%s") f i
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/printast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let fmt_char_option f = function
let fmt_constant f x =
match x with
| Pconst_integer (i,m) -> fprintf f "PConst_int (%s,%a)" i fmt_char_option m;
| Pconst_char (c) -> fprintf f "PConst_char %02x" (Char.code c);
| Pconst_char (c) -> fprintf f "PConst_char %02x" c;
| Pconst_string (s, None) -> fprintf f "PConst_string(%S,None)" s;
| Pconst_string (s, Some delim) ->
fprintf f "PConst_string (%S,Some %S)" s delim;
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/printlambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open Lambda

let rec struct_const ppf = function
| Const_base(Const_int n) -> fprintf ppf "%i" n
| Const_base(Const_char c) -> fprintf ppf "%C" c
| Const_base(Const_char i) -> fprintf ppf "%C" (Char.unsafe_chr i)
| Const_base(Const_string (s, _)) -> fprintf ppf "%S" s

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be adapted, '%C' may not apply any more

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'm fixing this.

| Const_immstring s -> fprintf ppf "#%S" s
| Const_base(Const_float f) -> fprintf ppf "%s" f
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/printtyped.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let fmt_path f x = fprintf f "\"%a\"" fmt_path_aux x;;
let fmt_constant f x =
match x with
| Const_int (i) -> fprintf f "Const_int %d" i;
| Const_char (c) -> fprintf f "Const_char %02x" (Char.code c);
| Const_char (c) -> fprintf f "Const_char %02x" c;
| Const_string (s, None) -> fprintf f "Const_string(%S,None)" s;
| Const_string (s, Some delim) ->
fprintf f "Const_string (%S,Some %S)" s delim;
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
else
or_ ~loc:gloc
(constant ~loc:gloc (Pconst_char c1))
(loop (Char.chr(Char.code c1 + 1)) c2)
(loop (c1 + 1) c2)
in
let p = if c1 <= c2 then loop c1 c2 else loop c2 c1 in
let p = {p with ppat_loc=loc} in
Expand Down
11 changes: 6 additions & 5 deletions lib/4.06.1/unstable/all_ounit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10698,7 +10698,7 @@ module Asttypes

type constant =
Const_int of int
| Const_char of char
| Const_char of int
| Const_string of string * string option
| Const_float of string
| Const_int32 of int32
Expand Down Expand Up @@ -10752,6 +10752,7 @@ let same_arg_label (x : arg_label) y =
| Optional s0 -> s = s0
| _ -> false
end

end
module Longident : sig
#1 "longident.mli"
Expand Down Expand Up @@ -10879,7 +10880,7 @@ type constant =
Suffixes [g-z][G-Z] are accepted by the parser.
Suffixes except 'l', 'L' and 'n' are rejected by the typechecker
*)
| Pconst_char of char
| Pconst_char of int
(* 'c' *)
| Pconst_string of string * string option
(* "constant"
Expand Down Expand Up @@ -13983,7 +13984,7 @@ module Const = struct
let int64 ?(suffix='L') i = integer ~suffix (Int64.to_string i)
let nativeint ?(suffix='n') i = integer ~suffix (Nativeint.to_string i)
let float ?suffix f = Pconst_float (f, suffix)
let char c = Pconst_char c
let char c = Pconst_char (Char.code c)
let string ?quotation_delimiter s = Pconst_string (s, quotation_delimiter)
end

Expand Down Expand Up @@ -25657,7 +25658,7 @@ let yyact = [|
let _1 = (Parsing.peek_val __caml_parser_env 0 : char) in
Obj.repr(
# 2155 "ml/parser.mly"
( Pconst_char _1 )
( Pconst_char (Char.code _1) )
# 11020 "ml/parser.ml"
: 'constant))
; (fun __caml_parser_env ->
Expand Down Expand Up @@ -51154,7 +51155,7 @@ type float_lit = { f : string } [@@unboxed]

type number =
| Float of float_lit
| Int of { i : int32; c : char option }
| Int of { i : int32; c : int option }
| Uint of int32

(* becareful when constant folding +/-,
Expand Down
Loading