Skip to content

Commit 40a7e8a

Browse files
committed
add missing bytes primitive
1 parent 9cf3bcd commit 40a7e8a

File tree

10 files changed

+116
-2
lines changed

10 files changed

+116
-2
lines changed

jscomp/core/lam_dispatch_primitive.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ let translate loc (prim_name : string)
120120
| [e] -> e (* TODO: do more checking when [to_int32]*)
121121
| _ -> assert false
122122
end
123+
| "caml_bytes_greaterthan"
124+
| "caml_bytes_greaterequal"
125+
| "caml_bytes_lessthan"
126+
| "caml_bytes_lessequal"
123127
| "caml_bytes_compare"
124128
| "caml_bytes_equal"
125129
->

jscomp/runtime/caml_bytes.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,14 @@ let caml_bytes_equal (s1 : bytes) (s2 : bytes) : bool =
193193
len1 = len2 &&
194194
caml_bytes_equal_aux s1 s2 0 len1
195195

196+
let caml_bytes_greaterthan (s1 : bytes) s2 =
197+
caml_bytes_compare s1 s2 > 0
198+
199+
let caml_bytes_greaterequal (s1 : bytes) s2 =
200+
caml_bytes_compare s1 s2 >= 0
201+
202+
let caml_bytes_lessthan (s1 : bytes) s2 =
203+
caml_bytes_compare s1 s2 < 0
204+
205+
let caml_bytes_lessequal (s1 : bytes) s2 =
206+
caml_bytes_compare s1 s2 <= 0

jscomp/runtime/caml_bytes.mli

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ val caml_blit_string :
4141
int ->
4242
int ->
4343
unit
44+
4445
val bytes_of_string : string -> bytes
45-
val caml_bytes_compare: bytes -> bytes -> int
46-
val caml_bytes_equal : bytes -> bytes -> bool
46+
47+
val caml_bytes_compare:
48+
bytes -> bytes -> int
49+
50+
val caml_bytes_greaterthan:
51+
bytes -> bytes -> bool
52+
53+
val caml_bytes_greaterequal:
54+
bytes -> bytes -> bool
55+
56+
val caml_bytes_lessthan:
57+
bytes -> bytes -> bool
58+
59+
val caml_bytes_lessequal:
60+
bytes -> bytes -> bool
61+
62+
val caml_bytes_equal :
63+
bytes -> bytes -> bool

jscomp/test/ext_bytes_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var Char = require("../../lib/js/char.js");
55
var Bytes = require("../../lib/js/bytes.js");
66
var Curry = require("../../lib/js/curry.js");
77
var Caml_bytes = require("../../lib/js/caml_bytes.js");
8+
var Caml_int64 = require("../../lib/js/caml_int64.js");
89
var Caml_exceptions = require("../../lib/js/caml_exceptions.js");
910
var Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js");
1011

@@ -188,11 +189,33 @@ var s2 = Bytes.of_string(s1);
188189

189190
eq("File \"ext_bytes_test.ml\", line 115, characters 7-14", s, s2);
190191

192+
function f$1(a, b) {
193+
return [
194+
Caml_bytes.caml_bytes_greaterthan(a, b),
195+
Caml_bytes.caml_bytes_greaterequal(a, b),
196+
Caml_bytes.caml_bytes_lessthan(a, b),
197+
Caml_bytes.caml_bytes_lessequal(a, b),
198+
Caml_bytes.caml_bytes_equal(a, b)
199+
];
200+
}
201+
202+
function f_0(a, b) {
203+
return [
204+
Caml_int64.gt(a, b),
205+
Caml_int64.ge(a, b),
206+
Caml_int64.lt(a, b),
207+
Caml_int64.le(a, b),
208+
Caml_int64.eq(a, b)
209+
];
210+
}
211+
191212
Mt.from_pair_suites("Ext_bytes_test", suites.contents);
192213

193214
exports.suites = suites;
194215
exports.test_id = test_id;
195216
exports.eq = eq;
196217
exports.escaped = escaped;
197218
exports.starts_with = starts_with;
219+
exports.f = f$1;
220+
exports.f_0 = f_0;
198221
/* a Not a pure module */

jscomp/test/ext_bytes_test.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,12 @@ let () =
113113
let s1 = Bytes.to_string s in
114114
let s2 = Bytes.of_string s1 in
115115
eq __LOC__ s s2
116+
117+
let f (a : bytes) b =
118+
a > b, a >= b , a < b, a <= b, a = b
119+
120+
let f_0 (a : int64) b =
121+
a > b, a >= b , a < b, a <= b, a = b
122+
116123
let () =
117124
Mt.from_pair_suites __MODULE__ !suites

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110712,6 +110712,10 @@ let translate loc (prim_name : string)
110712110712
| [e] -> e (* TODO: do more checking when [to_int32]*)
110713110713
| _ -> assert false
110714110714
end
110715+
| "caml_bytes_greaterthan"
110716+
| "caml_bytes_greaterequal"
110717+
| "caml_bytes_lessthan"
110718+
| "caml_bytes_lessequal"
110715110719
| "caml_bytes_compare"
110716110720
| "caml_bytes_equal"
110717110721
->

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110712,6 +110712,10 @@ let translate loc (prim_name : string)
110712110712
| [e] -> e (* TODO: do more checking when [to_int32]*)
110713110713
| _ -> assert false
110714110714
end
110715+
| "caml_bytes_greaterthan"
110716+
| "caml_bytes_greaterequal"
110717+
| "caml_bytes_lessthan"
110718+
| "caml_bytes_lessequal"
110715110719
| "caml_bytes_compare"
110716110720
| "caml_bytes_equal"
110717110721
->

lib/4.06.1/whole_compiler.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392804,6 +392804,10 @@ let translate loc (prim_name : string)
392804392804
| [e] -> e (* TODO: do more checking when [to_int32]*)
392805392805
| _ -> assert false
392806392806
end
392807+
| "caml_bytes_greaterthan"
392808+
| "caml_bytes_greaterequal"
392809+
| "caml_bytes_lessthan"
392810+
| "caml_bytes_lessequal"
392807392811
| "caml_bytes_compare"
392808392812
| "caml_bytes_equal"
392809392813
->

lib/es6/caml_bytes.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,22 @@ function caml_bytes_equal(s1, s2) {
195195
}
196196
}
197197

198+
function caml_bytes_greaterthan(s1, s2) {
199+
return caml_bytes_compare(s1, s2) > 0;
200+
}
201+
202+
function caml_bytes_greaterequal(s1, s2) {
203+
return caml_bytes_compare(s1, s2) >= 0;
204+
}
205+
206+
function caml_bytes_lessthan(s1, s2) {
207+
return caml_bytes_compare(s1, s2) < 0;
208+
}
209+
210+
function caml_bytes_lessequal(s1, s2) {
211+
return caml_bytes_compare(s1, s2) <= 0;
212+
}
213+
198214
export {
199215
caml_create_bytes ,
200216
caml_fill_bytes ,
@@ -205,6 +221,10 @@ export {
205221
caml_blit_string ,
206222
bytes_of_string ,
207223
caml_bytes_compare ,
224+
caml_bytes_greaterthan ,
225+
caml_bytes_greaterequal ,
226+
caml_bytes_lessthan ,
227+
caml_bytes_lessequal ,
208228
caml_bytes_equal ,
209229

210230
}

lib/js/caml_bytes.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,22 @@ function caml_bytes_equal(s1, s2) {
195195
}
196196
}
197197

198+
function caml_bytes_greaterthan(s1, s2) {
199+
return caml_bytes_compare(s1, s2) > 0;
200+
}
201+
202+
function caml_bytes_greaterequal(s1, s2) {
203+
return caml_bytes_compare(s1, s2) >= 0;
204+
}
205+
206+
function caml_bytes_lessthan(s1, s2) {
207+
return caml_bytes_compare(s1, s2) < 0;
208+
}
209+
210+
function caml_bytes_lessequal(s1, s2) {
211+
return caml_bytes_compare(s1, s2) <= 0;
212+
}
213+
198214
exports.caml_create_bytes = caml_create_bytes;
199215
exports.caml_fill_bytes = caml_fill_bytes;
200216
exports.get = get;
@@ -204,5 +220,9 @@ exports.caml_blit_bytes = caml_blit_bytes;
204220
exports.caml_blit_string = caml_blit_string;
205221
exports.bytes_of_string = bytes_of_string;
206222
exports.caml_bytes_compare = caml_bytes_compare;
223+
exports.caml_bytes_greaterthan = caml_bytes_greaterthan;
224+
exports.caml_bytes_greaterequal = caml_bytes_greaterequal;
225+
exports.caml_bytes_lessthan = caml_bytes_lessthan;
226+
exports.caml_bytes_lessequal = caml_bytes_lessequal;
207227
exports.caml_bytes_equal = caml_bytes_equal;
208228
/* No side effect */

0 commit comments

Comments
 (0)