Skip to content

Convert most of jscomp/runtime to .res #6318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
77 changes: 0 additions & 77 deletions jscomp/runtime/bs_stdlib_mini.mli

This file was deleted.

70 changes: 70 additions & 0 deletions jscomp/runtime/bs_stdlib_mini.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
Since [others] depend on this file, its public mli files **should not
export types** introduced here, otherwise it would cause
conflicts here.

If the type exported here is also exported in modules from others,
you will get a type not equivalent.


Types defined here but should not export:
- ref (make sure not exported in *.mli in others folder)
*/
external \"^": (string, string) => string = "#string_append"
external \"=": ('a, 'a) => bool = "%equal"
external \"<>": ('a, 'a) => bool = "%notequal"
external \"==": ('a, 'a) => bool = "%eq"
external \"!=": ('a, 'a) => bool = "%noteq"
external \"<": ('a, 'a) => bool = "%lessthan"
external \">": ('a, 'a) => bool = "%greaterthan"
external \"<=": ('a, 'a) => bool = "%lessequal"
external \">=": ('a, 'a) => bool = "%greaterequal"
external \"+": (int, int) => int = "%addint"
external \"-": (int, int) => int = "%subint"
external \"~-": int => int = "%negint"
external \"*": (int, int) => int = "%mulint"
external \"/": (int, int) => int = "%divint"
external lsl: (int, int) => int = "%lslint"
external lor: (int, int) => int = "%orint"
external land: (int, int) => int = "%andint"
external mod: (int, int) => int = "%modint"
external lsr: (int, int) => int = "%lsrint"
external lxor: (int, int) => int = "%xorint"
external asr: (int, int) => int = "%asrint"
type ref<'a> = {mutable contents: 'a}
external ref: 'a => ref<'a> = "%makemutable"

external \"||": (bool, bool) => bool = "%sequor"
external \"&&": (bool, bool) => bool = "%sequand"
external not: bool => bool = "%boolnot"

external raise: exn => 'a = "%raise"
external ignore: 'a => unit = "%ignore"
external \"|>": ('a, 'a => 'b) => 'b = "%revapply"
external \"@@": ('a => 'b, 'a) => 'b = "%apply"

@val @scope("Math") external \"**": (float, float) => float = "pow"
external \"~-.": float => float = "%negfloat"
external \"+.": (float, float) => float = "%addfloat"
external \"-.": (float, float) => float = "%subfloat"
external \"*.": (float, float) => float = "%mulfloat"
external \"/.": (float, float) => float = "%divfloat"

module Obj: {
type t
external field: (t, int) => t = "%obj_field"
external set_field: (t, int, t) => unit = "%obj_set_field"
external tag: t => int = "?obj_tag"
external repr: 'a => t = "%identity"
external obj: t => 'a = "%identity"
external magic: 'a => 'b = "%identity"
external size: t => int = "#obj_length"
}

module Pervasives: {
external compare: ('a, 'a) => int = "%compare"
external not: bool => bool = "%boolnot"
external min: ('a, 'a) => 'a = "%bs_min"
external max: ('a, 'a) => 'a = "%bs_max"
external \"=": ('a, 'a) => bool = "%equal"
}
94 changes: 0 additions & 94 deletions jscomp/runtime/caml.ml

This file was deleted.

153 changes: 153 additions & 0 deletions jscomp/runtime/caml.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

let int_compare = (x: int, y: int): int =>
if x < y {
-1
} else if x == y {
0
} else {
1
}
let bool_compare = (x: bool, y: bool): int =>
switch (x, y) {
| (true, true) | (false, false) => 0
| (true, false) => 1
| (false, true) => -1
}

let float_compare = (x: float, y: float) =>
if x == y {
0
} else if x < y {
-1
} else if x > y {
1
} else if x == x {
1
} else if y == y {
-1
} else {
0
}

/* Lexical order */
let string_compare = (s1: string, s2: string): int =>
if s1 == s2 {
0
} else if s1 < s2 {
-1
} else {
1
}

type selector<'a> = ('a, 'a) => 'a

/* could be replaced by [Math.min], but it seems those built-ins are slower */
let bool_min = (x: bool, y): bool =>
if x {
y
} else {
x
}
let int_min = (x: int, y: int): int =>
if x < y {
x
} else {
y
}
let float_min = (x: float, y) =>
if x < y {
x
} else {
y
}
let string_min = (x: string, y) =>
if x < y {
x
} else {
y
}

let bool_max = (x: bool, y): bool =>
if x {
x
} else {
y
}
let int_max = (x: int, y: int): int =>
if x > y {
x
} else {
y
}
let float_max = (x: float, y) =>
if x > y {
x
} else {
y
}
let string_max = (x: string, y) =>
if x > y {
x
} else {
y
}
type i64 = Caml_int64_extern.t
let i64_eq = (x: i64, y: i64) => x.lo == y.lo && x.hi == y.hi

let i64_ge = ({hi, lo}: i64, {hi: other_hi, lo: other_lo}: i64): bool =>
if hi > other_hi {
true
} else if hi < other_hi {
false
} else {
lo >= other_lo
}

let i64_neq = (x, y) => Pervasives.not(i64_eq(x, y))
let i64_lt = (x, y) => Pervasives.not(i64_ge(x, y))
let i64_gt = (x: i64, y: i64) =>
if x.hi > y.hi {
true
} else if x.hi < y.hi {
false
} else {
x.lo > y.lo
}

let i64_le = (x, y) => Pervasives.not(i64_gt(x, y))

let i64_min = (x, y) =>
if i64_lt(x, y) {
x
} else {
y
}
let i64_max = (x, y) =>
if i64_gt(x, y) {
x
} else {
y
}
Loading