Skip to content

Commit 34afbe8

Browse files
authored
[hl] replace hl_ver string cmp to Semver cmp (#12360)
1 parent 52034a0 commit 34afbe8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/generators/genhl.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ type context = {
122122
mutable ct_depth : int;
123123
}
124124

125+
let compare_version v1 v2 =
126+
Semver.compare_version (Semver.parse_version v1) (Semver.parse_version v2)
127+
125128
(* --- *)
126129

127130
type access =
@@ -1122,11 +1125,11 @@ let rec eval_to ctx e (t:ttype) =
11221125
let r = alloc_tmp ctx t in
11231126
op ctx (OFloat (r,alloc_float ctx (Int32.to_float i)));
11241127
r
1125-
| TConst (TInt i), HF32 when ctx.hl_ver >= "1.15" ->
1128+
| TConst (TInt i), HF32 when compare_version ctx.hl_ver "1.15.0" >= 0 ->
11261129
let r = alloc_tmp ctx t in
11271130
op ctx (OFloat (r, alloc_float ctx (Int32.to_float i)));
11281131
r
1129-
| TConst (TFloat f), HF32 when ctx.hl_ver >= "1.15" ->
1132+
| TConst (TFloat f), HF32 when compare_version ctx.hl_ver "1.15.0" >= 0 ->
11301133
let r = alloc_tmp ctx t in
11311134
op ctx (OFloat (r, alloc_float ctx (float_of_string f)));
11321135
r
@@ -3045,7 +3048,7 @@ and eval_expr ctx e =
30453048
let rtrap = alloc_tmp ctx HDyn in
30463049
op ctx (OTrap (rtrap,-1)); (* loop *)
30473050
ctx.m.mtrys <- ctx.m.mtrys + 1;
3048-
if ctx.hl_ver >= "1.16" then begin
3051+
if compare_version ctx.hl_ver "1.16.0" >= 0 then begin
30493052
let catched_types = ref [] in
30503053
let rec find_meta e =
30513054
(match e.eexpr with
@@ -3513,7 +3516,7 @@ let generate_static ctx c f =
35133516
| (Meta.HlNative,[(EConst(String(lib,_)),_)] ,_ ) :: _ ->
35143517
add_native lib f.cf_name
35153518
| (Meta.HlNative,[(EConst(Float(ver,_)),_)] ,_ ) :: _ ->
3516-
if ctx.hl_ver < ver then
3519+
if compare_version ctx.hl_ver (ver ^ ".0") < 0 then
35173520
let gen_content() =
35183521
op ctx (OThrow (make_string ctx ("Requires compiling with -D hl-ver=" ^ ver ^ ".0 or higher") null_pos));
35193522
in
@@ -4219,7 +4222,7 @@ let create_context com =
42194222
af64 = get_class "ArrayBytes_Float";
42204223
ai64 =
42214224
if Gctx.raw_defined com "hl_legacy32"
4222-
|| hl_ver <> "" && (Semver.compare_version (Semver.parse_version hl_ver) (Semver.parse_version "1.13.0")) = -1
4225+
|| hl_ver <> "" && compare_version hl_ver "1.13.0" < 0
42234226
then
42244227
None
42254228
else

0 commit comments

Comments
 (0)