24
24
25
25
26
26
27
- external (.! [] ) : string -> int -> int = " %string_unsafe_get"
27
+ external (.! [] ) : string -> int -> int = " %string_unsafe_get"
28
+ external (.! () ) : string -> int -> char = " %string_unsafe_get"
28
29
29
30
let code_0 = " 0" .! [0 ]
30
31
let code_a = " a" .! [0 ]
@@ -35,7 +36,7 @@ module Caml_char = struct
35
36
external unsafe_chr : int -> char = " %identity"
36
37
end
37
38
38
- let caml_failwith s = raise (Failure s)
39
+ let failwith s = raise (Failure s)
39
40
(* let caml_invalid_argument s= raise (Invalid_argument s ) *)
40
41
41
42
let (>>> ) = Caml_nativeint_extern. shift_right_logical
@@ -94,41 +95,39 @@ let parse_sign_and_base (s : string) =
94
95
95
96
96
97
let caml_int_of_string s =
97
- let module String = Caml_string_extern in
98
98
let i, sign, hbase = parse_sign_and_base s in
99
99
let base = Caml_nativeint_extern. of_int (int_of_string_base hbase) in
100
100
let threshold = (- 1n >>> 0 ) in
101
101
let len = Caml_string_extern. length s in
102
- let c = if i < len then s.[i] else '\000' in
102
+ let c = if i < len then s.! (i) else '\000' in
103
103
let d = to_nat (parse_digit c) in
104
104
let () =
105
105
if d < 0n || d > = base then
106
- caml_failwith " int_of_string" in
106
+ failwith " int_of_string" in
107
107
(* let () = [%bs.debugger] in *)
108
108
let rec aux acc k =
109
109
if k = len then acc
110
110
else
111
- let a = s.[k] in
111
+ let a = s.! (k) in
112
112
if a = '_' then aux acc ( k + 1 )
113
113
else
114
114
let v = to_nat (parse_digit a) in
115
115
if v < 0n || v > = base then
116
- caml_failwith " int_of_string"
116
+ failwith " int_of_string"
117
117
else
118
118
let acc = base *~ acc +~ v in
119
119
if acc > threshold then
120
- caml_failwith " int_of_string"
120
+ failwith " int_of_string"
121
121
else aux acc ( k + 1 )
122
122
in
123
123
let res = sign *~ aux d (i + 1 ) in
124
124
let or_res = Caml_nativeint_extern. logor res 0n in
125
125
(if base = 10n && res <> or_res then
126
- caml_failwith " int_of_string" );
126
+ failwith " int_of_string" );
127
127
or_res
128
128
129
129
130
130
let caml_int64_of_string s =
131
- let module String = Caml_string_extern in
132
131
let i, sign, hbase = parse_sign_and_base s in
133
132
let base = Caml_int64_extern. of_int (int_of_string_base hbase) in
134
133
let sign = Caml_int64_extern. of_nativeint sign in
@@ -144,31 +143,31 @@ let caml_int64_of_string s =
144
143
9223372036854775807L
145
144
in
146
145
let len = Caml_string_extern. length s in
147
- let c = if i < len then s.[i] else '\000' in
146
+ let c = if i < len then s.! (i) else '\000' in
148
147
let d = Caml_int64_extern. of_int (parse_digit c) in
149
148
let () =
150
149
if d < 0L || d > = base then
151
- caml_failwith " int64_of_string" in
150
+ failwith " int64_of_string" in
152
151
let (+~ ) = Caml_int64_extern. add in
153
152
let ( *~ ) = Caml_int64_extern. mul in
154
153
155
154
let rec aux acc k =
156
155
if k = len then acc
157
156
else
158
- let a = s.[k] in
157
+ let a = s.! (k) in
159
158
if a = '_' then aux acc ( k + 1 )
160
159
else
161
160
let v = Caml_int64_extern. of_int (parse_digit a) in
162
161
if v < 0L || v > = base || acc > threshold then
163
- caml_failwith " int64_of_string"
162
+ failwith " int64_of_string"
164
163
else
165
164
let acc = base *~ acc +~ v in
166
165
aux acc ( k + 1 )
167
166
in
168
167
let res = sign *~ aux d (i + 1 ) in
169
168
let or_res = Caml_int64_extern. logor res 0L in
170
169
(if base = 10L && res <> or_res then
171
- caml_failwith " int64_of_string" );
170
+ failwith " int64_of_string" );
172
171
or_res
173
172
174
173
type base =
0 commit comments