Skip to content

Commit 6940388

Browse files
Merge branch 'main' into main
2 parents 622b26f + fbb143f commit 6940388

File tree

386 files changed

+11988
-9722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

386 files changed

+11988
-9722
lines changed

NOTICE

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ File `float/exp.mbt`, `float/log.mbt`, `double/mod_nonjs.mbt` and `double/scalbn
8080
and `src/math/exp2f_data.c`.
8181
- `double/mod_nonjs.mbt` is adapted from `src/math/fmod.c`.
8282
- `double/scalbn.mbt` is adapted from `src/math/scalbn.c`.
83+
- `math/hyperbolic.mbt` is adapted from `src/math/sinh.c`, `src/math/cosh.c`,
84+
`src/math/tanh.c`, `src/math/asinh.c`, `src/math/acosh.c`, and `src/math/atanh.c`.
8385

8486
`float/log.mbt` and `float/exp.mbt` files are Copyright (c) 2017-2018 Arm Limited and licensed under the MIT
8587
license.
@@ -105,7 +107,8 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
105107
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
106108
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
107109

108-
`double/mod_nonjs.mbt` and `double/scalbn.mbt` are licensed under the following license:
110+
`double/mod_nonjs.mbt`, `double/scalbn.mbt`, `math/algebraic.mbt`,
111+
`math/log.mbt` and `math/pow.mbt` are licensed under the following license:
109112

110113
Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
111114

abort/abort.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
///
2424
/// Returns a value of type `T`. However, this function never actually returns a
2525
/// value as it always causes a panic.
26-
pub fn abort[T](msg : String) -> T {
26+
pub fn[T] abort(msg : String) -> T {
2727
let _ = msg
2828
panic_impl()
2929
}
3030

3131
///|
32-
fn panic_impl[T]() -> T = "%panic"
32+
fn[T] panic_impl() -> T = "%panic"

abort/abort.mbti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package "moonbitlang/core/abort"
22

33
// Values
4-
fn abort[T](String) -> T
4+
fn[T] abort(String) -> T
55

66
// Types and methods
77

array/README.mbt.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ test "array creation" {
1616
1717
// Creating from iterator
1818
let arr3 = Array::from_iter("hello".iter())
19-
inspect!(arr1, content="[1, 2, 3]")
20-
inspect!(arr2, content="[0, 2, 4]")
21-
inspect!(arr3, content="['h', 'e', 'l', 'l', 'o']")
19+
inspect(arr1, content="[1, 2, 3]")
20+
inspect(arr2, content="[0, 2, 4]")
21+
inspect(arr3, content="['h', 'e', 'l', 'l', 'o']")
2222
}
2323
```
2424

@@ -44,9 +44,9 @@ test "array operations" {
4444
4545
// Finding last element
4646
let last = nums.last()
47-
inspect!(neg_evens, content="[-2, -4]")
48-
inspect!(sum, content="15")
49-
inspect!(last, content="Some(5)")
47+
inspect(neg_evens, content="[-2, -4]")
48+
inspect(sum, content="15")
49+
inspect(last, content="Some(5)")
5050
}
5151
```
5252

@@ -61,13 +61,13 @@ test "sorting" {
6161
// Basic sorting - creates new sorted array
6262
let sorted1 = arr.copy()
6363
sorted1.sort()
64-
inspect!(sorted1, content="[1, 1, 2, 3, 4, 5, 6, 9]")
64+
inspect(sorted1, content="[1, 1, 2, 3, 4, 5, 6, 9]")
6565
6666
// Custom comparison
6767
let strs = ["aa", "b", "ccc"]
6868
let sorted2 = strs.copy()
6969
sorted2.sort_by(fn(a, b) { a.length().compare(b.length()) })
70-
inspect!(
70+
inspect(
7171
sorted2,
7272
content=
7373
#|["b", "aa", "ccc"]
@@ -78,7 +78,7 @@ test "sorting" {
7878
let pairs = [(2, "b"), (1, "a"), (3, "c")]
7979
let sorted3 = pairs.copy()
8080
sorted3.sort_by_key(fn(p) { p.0 })
81-
inspect!(
81+
inspect(
8282
sorted3,
8383
content=
8484
#|[(1, "a"), (2, "b"), (3, "c")]
@@ -101,8 +101,8 @@ test "array views" {
101101
102102
// Modify view in-place
103103
view.map_inplace(fn(x) { x + 1 })
104-
inspect!(doubled, content="[4, 6, 8]")
105-
inspect!(arr, content="[1, 3, 4, 5, 5]")
104+
inspect(doubled, content="[4, 6, 8]")
105+
inspect(arr, content="[1, 3, 4, 5, 5]")
106106
}
107107
```
108108

@@ -123,10 +123,10 @@ test "fixed arrays" {
123123
// Check if array starts/ends with sequence
124124
let starts = fixed.starts_with([1, 2])
125125
let ends = fixed.ends_with([2, 3])
126-
inspect!(combined, content="[1, 2, 3, 4, 5]")
127-
inspect!(has_two, content="true")
128-
inspect!(starts, content="true")
129-
inspect!(ends, content="true")
126+
inspect(combined, content="[1, 2, 3, 4, 5]")
127+
inspect(has_two, content="true")
128+
inspect(starts, content="true")
129+
inspect(ends, content="true")
130130
}
131131
```
132132

@@ -145,7 +145,7 @@ test "utilities" {
145145
// Using deterministic `rand` function below for demonstration
146146
// NOTE: When using a normal `rand` function, the actual result may vary
147147
let shuffled = nums.shuffle(rand=fn(_) { 1 })
148-
inspect!(joined, content="hello world")
149-
inspect!(shuffled, content="[1, 3, 4, 5, 2]")
148+
inspect(joined, content="hello world")
149+
inspect(shuffled, content="[1, 3, 4, 5, 2]")
150150
}
151151
```

array/array.mbt

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
/// test "Array::from_iter" {
2929
/// let iter = Iter::singleton(42)
3030
/// let arr = Array::from_iter(iter)
31-
/// inspect!(arr, content="[42]")
31+
/// inspect(arr, content="[42]")
3232
/// }
3333
/// ```
34-
pub fn Array::from_iter[T](iter : Iter[T]) -> Array[T] {
34+
pub fn[T] Array::from_iter(iter : Iter[T]) -> Array[T] {
3535
iter.collect()
3636
}
3737
@@ -48,7 +48,7 @@ pub fn Array::from_iter[T](iter : Iter[T]) -> Array[T] {
4848
/// u.push_iter(v.iter())
4949
/// assert_eq!(u, [1, 2, 3, 4, 5, 6])
5050
/// ```
51-
pub fn push_iter[T](self : Array[T], iter : Iter[T]) -> Unit {
51+
pub fn[T] push_iter(self : Array[T], iter : Iter[T]) -> Unit {
5252
for x in iter {
5353
self.push(x)
5454
}
@@ -74,10 +74,10 @@ pub fn push_iter[T](self : Array[T], iter : Iter[T]) -> Unit {
7474
/// ```moonbit
7575
/// test "Array::makei" {
7676
/// let arr = Array::makei(3, fn(i) { i * 2 })
77-
/// inspect!(arr, content="[0, 2, 4]")
77+
/// inspect(arr, content="[0, 2, 4]")
7878
/// }
7979
/// ```
80-
pub fn Array::makei[T](length : Int, value : (Int) -> T) -> Array[T] {
80+
pub fn[T] Array::makei(length : Int, value : (Int) -> T) -> Array[T] {
8181
if length <= 0 {
8282
[]
8383
} else {
@@ -105,7 +105,7 @@ pub fn Array::makei[T](length : Int, value : (Int) -> T) -> Array[T] {
105105
/// }
106106
/// Array::shuffle_in_place(arr, rand=rand)
107107
/// ```
108-
pub fn shuffle_in_place[T](self : Array[T], rand~ : (Int) -> Int) -> Unit {
108+
pub fn[T] shuffle_in_place(self : Array[T], rand~ : (Int) -> Int) -> Unit {
109109
let n = self.length()
110110
for i = n - 1; i > 0; i = i - 1 {
111111
let j = rand(i + 1) % (i + 1)
@@ -131,7 +131,7 @@ pub fn shuffle_in_place[T](self : Array[T], rand~ : (Int) -> Int) -> Unit {
131131
/// }
132132
/// let _shuffled = Array::shuffle(arr, rand=rand)
133133
/// ```
134-
pub fn shuffle[T](self : Array[T], rand~ : (Int) -> Int) -> Array[T] {
134+
pub fn[T] shuffle(self : Array[T], rand~ : (Int) -> Int) -> Array[T] {
135135
let new_arr = self.copy()
136136
Array::shuffle_in_place(new_arr, rand~)
137137
new_arr
@@ -147,7 +147,7 @@ pub fn shuffle[T](self : Array[T], rand~ : (Int) -> Int) -> Array[T] {
147147
///
148148
/// # Returns
149149
///
150-
pub fn filter_map[A, B](self : Array[A], f : (A) -> B?) -> Array[B] {
150+
pub fn[A, B] filter_map(self : Array[A], f : (A) -> B?) -> Array[B] {
151151
let result = []
152152
for x in self {
153153
if f(x) is Some(x) {
@@ -173,12 +173,12 @@ pub fn filter_map[A, B](self : Array[A], f : (A) -> B?) -> Array[B] {
173173
/// ```moonbit
174174
/// test "last" {
175175
/// let arr = [1, 2, 3]
176-
/// inspect!(arr.last(), content="Some(3)")
176+
/// inspect(arr.last(), content="Some(3)")
177177
/// let empty : Array[Int] = []
178-
/// inspect!(empty.last(), content="None")
178+
/// inspect(empty.last(), content="None")
179179
/// }
180180
/// ```
181-
pub fn last[A](self : Array[A]) -> A? {
181+
pub fn[A] last(self : Array[A]) -> A? {
182182
match self {
183183
[] => None
184184
[.., last] => Some(last)
@@ -202,10 +202,10 @@ pub fn last[A](self : Array[A]) -> A? {
202202
/// test "zip" {
203203
/// let arr1 = [1, 2, 3]
204204
/// let arr2 = ['a', 'b', 'c']
205-
/// inspect!(arr1.zip(arr2), content="[(1, 'a'), (2, 'b'), (3, 'c')]")
205+
/// inspect(arr1.zip(arr2), content="[(1, 'a'), (2, 'b'), (3, 'c')]")
206206
/// }
207207
/// ```
208-
pub fn zip[A, B](self : Array[A], other : Array[B]) -> Array[(A, B)] {
208+
pub fn[A, B] zip(self : Array[A], other : Array[B]) -> Array[(A, B)] {
209209
let length = if self.length() < other.length() {
210210
self.length()
211211
} else {
@@ -237,10 +237,10 @@ pub fn zip[A, B](self : Array[A], other : Array[B]) -> Array[(A, B)] {
237237
/// let arr1 = [1, 2, 3]
238238
/// let arr2 = [4, 5, 6]
239239
/// let add = fn(a, b) { a + b }
240-
/// inspect!(zip_with(arr1, arr2, add), content="[5, 7, 9]")
240+
/// inspect(zip_with(arr1, arr2, add), content="[5, 7, 9]")
241241
/// }
242242
/// ```
243-
pub fn zip_with[A, B, C](
243+
pub fn[A, B, C] zip_with(
244244
l : Array[A],
245245
r : Array[B],
246246
merge : (A, B) -> C
@@ -271,10 +271,10 @@ pub fn zip_with[A, B, C](
271271
/// test "zip_to_iter2" {
272272
/// let arr1 = [1, 2, 3]
273273
/// let arr2 = ['a', 'b', 'c']
274-
/// inspect!(arr1.zip_to_iter2(arr2).to_array(), content="[(1, 'a'), (2, 'b'), (3, 'c')]")
274+
/// inspect(arr1.zip_to_iter2(arr2).to_array(), content="[(1, 'a'), (2, 'b'), (3, 'c')]")
275275
/// }
276276
/// ```
277-
pub fn zip_to_iter2[A, B](self : Array[A], other : Array[B]) -> Iter2[A, B] {
277+
pub fn[A, B] zip_to_iter2(self : Array[A], other : Array[B]) -> Iter2[A, B] {
278278
Iter2::new(fn(yield_) {
279279
let length = if self.length() < other.length() {
280280
self.length()
@@ -302,5 +302,27 @@ pub impl[X : @quickcheck.Arbitrary] @quickcheck.Arbitrary for Array[X] with arbi
302302
303303
///|
304304
pub fn join(self : Array[String], separator : String) -> String {
305-
@string.concat(self, separator~)
305+
match self {
306+
[] => ""
307+
[hd, .. tl] => {
308+
let mut size_hint = hd.length()
309+
for s in tl {
310+
size_hint += s.length() + separator.length()
311+
}
312+
size_hint = size_hint << 1
313+
let buf = StringBuilder::new(size_hint~)
314+
buf.write_string(hd)
315+
if separator == "" {
316+
for s in tl {
317+
buf.write_string(s)
318+
}
319+
} else {
320+
for s in tl {
321+
buf.write_string(separator)
322+
buf.write_string(s)
323+
}
324+
}
325+
buf.to_string()
326+
}
327+
}
306328
}

array/array.mbti

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ import(
66
)
77

88
// Values
9-
fn copy[T](Array[T]) -> Array[T]
9+
fn[T] copy(Array[T]) -> Array[T]
1010

11-
fn filter_map[A, B](Array[A], (A) -> B?) -> Array[B]
11+
fn[A, B] filter_map(Array[A], (A) -> B?) -> Array[B]
1212

1313
fn join(Array[String], String) -> String
1414

15-
fn last[A](Array[A]) -> A?
15+
fn[A] last(Array[A]) -> A?
1616

17-
fn push_iter[T](Array[T], Iter[T]) -> Unit
17+
fn[T] push_iter(Array[T], Iter[T]) -> Unit
1818

19-
fn shuffle[T](Array[T], rand~ : (Int) -> Int) -> Array[T]
19+
fn[T] shuffle(Array[T], rand~ : (Int) -> Int) -> Array[T]
2020

21-
fn shuffle_in_place[T](Array[T], rand~ : (Int) -> Int) -> Unit
21+
fn[T] shuffle_in_place(Array[T], rand~ : (Int) -> Int) -> Unit
2222

23-
fn sort[T : Compare](Array[T]) -> Unit
23+
fn[T : Compare] sort(Array[T]) -> Unit
2424

25-
fn sort_by[T](Array[T], (T, T) -> Int) -> Unit
25+
fn[T] sort_by(Array[T], (T, T) -> Int) -> Unit
2626

27-
fn sort_by_key[T, K : Compare](Array[T], (T) -> K) -> Unit
27+
fn[T, K : Compare] sort_by_key(Array[T], (T) -> K) -> Unit
2828

29-
fn zip[A, B](Array[A], Array[B]) -> Array[(A, B)]
29+
fn[A, B] zip(Array[A], Array[B]) -> Array[(A, B)]
3030

31-
fn zip_to_iter2[A, B](Array[A], Array[B]) -> Iter2[A, B]
31+
fn[A, B] zip_to_iter2(Array[A], Array[B]) -> Iter2[A, B]
3232

33-
fn zip_with[A, B, C](Array[A], Array[B], (A, B) -> C) -> Array[C]
33+
fn[A, B, C] zip_with(Array[A], Array[B], (A, B) -> C) -> Array[C]
3434

3535
// Types and methods
3636
impl FixedArray {
@@ -99,6 +99,7 @@ impl ArrayView {
9999
fold[A, B](Self[A], init~ : B, (B, A) -> B) -> B
100100
foldi[A, B](Self[A], init~ : B, (Int, B, A) -> B) -> B
101101
iter[A](Self[A]) -> Iter[A]
102+
iter2[A](Self[A]) -> Iter2[Int, A]
102103
map[T, U](Self[T], (T) -> U) -> Array[U]
103104
map_inplace[T](Self[T], (T) -> T) -> Unit
104105
mapi[T, U](Self[T], (Int, T) -> U) -> Array[U]

array/array_js.mbt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
priv extern type JSArray
1717

1818
///|
19-
fn JSArray::ofAnyArray[T](array : Array[T]) -> JSArray = "%identity"
19+
fn[T] JSArray::ofAnyArray(array : Array[T]) -> JSArray = "%identity"
2020

2121
///|
22-
fn JSArray::toAnyArray[T](self : JSArray) -> Array[T] = "%identity"
22+
fn[T] JSArray::toAnyArray(self : JSArray) -> Array[T] = "%identity"
2323

2424
///|
25-
fn JSArray::ofAnyFixedArray[T](array : FixedArray[T]) -> JSArray = "%identity"
25+
fn[T] JSArray::ofAnyFixedArray(array : FixedArray[T]) -> JSArray = "%identity"
2626

2727
///|
28-
fn JSArray::toAnyFixedArray[T](self : JSArray) -> FixedArray[T] = "%identity"
28+
fn[T] JSArray::toAnyFixedArray(self : JSArray) -> FixedArray[T] = "%identity"
2929

3030
///|
3131
extern "js" fn JSArray::copy(self : JSArray) -> JSArray =
@@ -47,10 +47,10 @@ extern "js" fn JSArray::copy(self : JSArray) -> JSArray =
4747
/// test "copy" {
4848
/// let original = [1, 2, 3]
4949
/// let copied = original.copy()
50-
/// inspect!(copied, content="[1, 2, 3]")
51-
/// inspect!(physical_equal(original, copied), content="false")
50+
/// inspect(copied, content="[1, 2, 3]")
51+
/// inspect(physical_equal(original, copied), content="false")
5252
/// }
5353
/// ```
54-
pub fn copy[T](self : Array[T]) -> Array[T] {
54+
pub fn[T] copy(self : Array[T]) -> Array[T] {
5555
JSArray::ofAnyArray(self).copy().toAnyArray()
5656
}

array/array_nonjs.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
/// test "copy" {
2929
/// let original = [1, 2, 3]
3030
/// let copied = original.copy()
31-
/// inspect!(copied, content="[1, 2, 3]")
32-
/// inspect!(physical_equal(original, copied), content="false")
31+
/// inspect(copied, content="[1, 2, 3]")
32+
/// inspect(physical_equal(original, copied), content="false")
3333
/// }
3434
/// ```
35-
pub fn copy[T](self : Array[T]) -> Array[T] {
35+
pub fn[T] copy(self : Array[T]) -> Array[T] {
3636
let len = self.length()
3737
if len == 0 {
3838
[]

0 commit comments

Comments
 (0)