Skip to content

Commit 754cd80

Browse files
authored
Merge branch 'main' into xxmap-keys-values
2 parents 389ff77 + 3f52062 commit 754cd80

Some content is hidden

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

43 files changed

+2665
-262
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

array/array.mbti

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/moon.pkg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"moonbitlang/core/quickcheck/splitmix"
88
],
99
"test-import": [
10+
"moonbitlang/core/char",
1011
"moonbitlang/core/test",
1112
"moonbitlang/core/random",
1213
"moonbitlang/core/json"

array/view.mbt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,36 @@ pub fn View::iter[A](self : View[A]) -> Iter[A] {
193193
})
194194
}
195195
196+
///|
197+
/// Returns an iterator that yields tuples of index and value
198+
/// indices start from 0.
199+
///
200+
/// Example:
201+
/// ```moonbit
202+
/// test "View::iter" {
203+
/// let arr = [1, 2, 3]
204+
/// let view = arr[1:]
205+
/// let mut sum = 0
206+
/// let mut sum_keys = 0
207+
/// view.iter2().each(fn(i, x) {
208+
/// sum = sum + x
209+
/// sum_keys = sum_keys + i
210+
/// })
211+
/// inspect!(sum, content="5")
212+
/// inspect!(sum_keys, content="1")
213+
/// }
214+
/// ```
215+
pub fn View::iter2[A](self : View[A]) -> Iter2[Int, A] {
216+
Iter2::new(fn(yield_) {
217+
for i, v in self {
218+
guard yield_(i, v) is IterContinue else { break IterEnd }
219+
220+
} else {
221+
IterContinue
222+
}
223+
})
224+
}
225+
196226
///|
197227
/// Fold out values from an View according to certain rules.
198228
///

array/view_test.mbt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ test "iter" {
9292
@json.inspect!(array[5:9].iter().to_array(), content=[5, 6, 7, 8])
9393
}
9494

95+
///|
96+
test "iter2" {
97+
let arr = [1, 2, 3]
98+
let view = arr[1:]
99+
let mut sum = 0
100+
let mut sum_keys = 0
101+
view
102+
.iter2()
103+
.each(fn(i, x) {
104+
sum = sum + x
105+
sum_keys = sum_keys + i
106+
})
107+
inspect!(sum, content="5")
108+
inspect!(sum_keys, content="1")
109+
}
110+
95111
///|
96112
test "to_string" {
97113
let arr = [0, 1, 2, 3, 4]

bigint/moon.pkg.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"import": [
33
"moonbitlang/core/builtin",
4+
"moonbitlang/core/char",
45
"moonbitlang/core/uint",
56
"moonbitlang/core/json",
67
"moonbitlang/core/quickcheck",
@@ -12,4 +13,4 @@
1213
"bigint_js_wbtest.mbt": ["js"],
1314
"bigint_nonjs_wbtest.mbt": ["not", "js"]
1415
}
15-
}
16+
}

bool/moon.pkg.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"import": ["moonbitlang/core/builtin"]
2+
"import": ["moonbitlang/core/builtin"],
3+
"test-import": [ "moonbitlang/core/char" ]
34
}

builtin/array_block.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub fn Array::unsafe_blit_fixed[A](
137137
/// * `len` is negative
138138
/// * `src_offset` is negative
139139
/// * `dst_offset` is negative
140-
/// * `dst_offset + len` exceeds the length of destination array
140+
/// * `dst_offset` exceeds the length of destination array
141141
/// * `src_offset + len` exceeds the length of source array
142142
pub fn Array::blit_to[A](
143143
self : Array[A],

builtin/builtin.mbti

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ pub(open) trait Show {
780780
impl Show for Unit
781781
impl Show for Bool
782782
impl Show for Byte
783-
impl Show for Char
784783
impl Show for Int
785784
impl Show for Int16
786785
impl Show for Int64
@@ -835,7 +834,6 @@ pub(open) trait ToJson {
835834
impl ToJson for Unit
836835
impl ToJson for Bool
837836
impl ToJson for Byte
838-
impl ToJson for Char
839837
impl ToJson for Int
840838
impl ToJson for Int64
841839
impl ToJson for UInt

builtin/intrinsics_test.mbt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,15 @@ test "Int::to_char - Invalid values" {
484484
///|
485485
test "Int::to_char - Valid values" {
486486
inspect!(Int::to_char(0), content="Some('\\u{00}')")
487-
inspect!(Int::to_char(127), content="Some('')")
488-
inspect!(Int::to_char(128), content="Some('€')")
489-
inspect!(Int::to_char(0x7F), content="Some('')")
490-
inspect!(Int::to_char(0x80), content="Some('€')")
487+
inspect!(Int::to_char(127), content="Some('\\u{7f}')")
488+
inspect!(Int::to_char(128), content="Some('\\u{80}')")
489+
inspect!(Int::to_char(0x7F), content="Some('\\u{7f}')")
490+
inspect!(Int::to_char(0x80), content="Some('\\u{80}')")
491491
inspect!(Int::to_char(0xFF), content="Some('ÿ')")
492492
inspect!(Int::to_char(0x100), content="Some('Ā')")
493-
inspect!(Int::to_char(0xFFFF), content="Some('')")
493+
inspect!(Int::to_char(0xFFFF), content="Some('\\u{ffff}')")
494494
inspect!(Int::to_char(0x10000), content="Some('𐀀')")
495-
inspect!(Int::to_char(0x10FFFF), content="Some('􏿿')")
495+
inspect!(Int::to_char(0x10FFFF), content="Some('\\u{10ffff}')")
496496
}
497497

498498
///|
@@ -508,8 +508,8 @@ test "Int::to_char - Invalid values" {
508508
///|
509509
test "Int::to_char - Boundary cases" {
510510
inspect!(Int::to_char(0xD7FF), content="Some('퟿')")
511-
inspect!(Int::to_char(0xE000), content="Some('')")
512-
inspect!(Int::to_char(0x10FFFF), content="Some('􏿿')")
511+
inspect!(Int::to_char(0xE000), content="Some('\\u{e000}')")
512+
inspect!(Int::to_char(0x10FFFF), content="Some('\\u{10ffff}')")
513513
inspect!(Int::to_char(0x10FFFF + 1), content="None")
514514
}
515515

0 commit comments

Comments
 (0)