From 02c9589ab980719716f8bd4e39541f7e8ed2c81c Mon Sep 17 00:00:00 2001 From: Xenia Lu Date: Mon, 29 Sep 2025 07:34:16 +0800 Subject: [PATCH 1/3] feat: add new target "moongres" --- bench/moon.pkg.json | 2 +- builtin/moon.pkg.json | 8 ++++---- double/moon.pkg.json | 8 ++++---- env/moon.pkg.json | 2 +- float/moon.pkg.json | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bench/moon.pkg.json b/bench/moon.pkg.json index 3ae9b3588..7df80944b 100644 --- a/bench/moon.pkg.json +++ b/bench/moon.pkg.json @@ -1,7 +1,7 @@ { "targets": { "monotonic_clock_js.mbt": ["js"], - "monotonic_clock_wasm.mbt": ["wasm", "wasm-gc"], + "monotonic_clock_wasm.mbt": ["wasm", "wasm-gc", "moongres"], "monotonic_clock_native.mbt": ["native", "llvm"] }, "import": [ diff --git a/builtin/moon.pkg.json b/builtin/moon.pkg.json index 46be3e247..f91460409 100644 --- a/builtin/moon.pkg.json +++ b/builtin/moon.pkg.json @@ -22,14 +22,14 @@ "arraycore_nonjs.mbt": ["not", "js"], "panic_test.mbt": ["not", "native", "llvm"], "panic_wbtest.mbt": ["not", "native", "llvm"], - "panic_nonjs_test.mbt": ["wasm", "wasm-gc"], + "panic_nonjs_test.mbt": ["wasm", "wasm-gc", "moongres"], "array_nonjs_test.mbt": ["not", "js"], "stringbuilder_buffer.mbt": ["not", "js"], "stringbuilder_concat.mbt": ["js"], "double_to_int64_js.mbt": ["js"], "double_to_int64_native.mbt": ["native", "llvm"], - "double_to_int64_wasm.mbt": ["wasm", "wasm-gc"], - "double_to_int.mbt": ["not", "wasm", "wasm-gc"], - "double_to_int_wasm.mbt": ["wasm", "wasm-gc"] + "double_to_int64_wasm.mbt": ["wasm", "wasm-gc", "moongres"], + "double_to_int.mbt": ["not", "wasm", "wasm-gc", "moongres"], + "double_to_int_wasm.mbt": ["wasm", "wasm-gc", "moongres"] } } diff --git a/double/moon.pkg.json b/double/moon.pkg.json index a72fdce17..b7784cb48 100644 --- a/double/moon.pkg.json +++ b/double/moon.pkg.json @@ -17,10 +17,10 @@ "trig_js.mbt" : ["js"], "trig_nonjs.mbt" : ["not", "js"], "round_js.mbt": ["js"], - "round_wasm.mbt": ["wasm", "wasm-gc"], - "round.mbt": ["not", "js", "wasm", "wasm-gc"], - "to_uint_wasm.mbt": ["wasm", "wasm-gc"], - "to_uint.mbt": ["not", "wasm", "wasm-gc"], + "round_wasm.mbt": ["wasm", "wasm-gc", "moongres"], + "round.mbt": ["not", "js", "wasm", "wasm-gc", "moongres"], + "to_uint_wasm.mbt": ["wasm", "wasm-gc", "moongres"], + "to_uint.mbt": ["not", "wasm", "wasm-gc", "moongres"], "hyperbolic_js.mbt": ["js"], "hyperbolic_nonjs.mbt": ["not", "js"], "cbrt_js.mbt" : ["js"], diff --git a/env/moon.pkg.json b/env/moon.pkg.json index ba6658a8d..24ead7634 100644 --- a/env/moon.pkg.json +++ b/env/moon.pkg.json @@ -7,7 +7,7 @@ "moonbitlang/core/option" ], "targets": { - "env_wasm.mbt": ["wasm", "wasm-gc"], + "env_wasm.mbt": ["wasm", "wasm-gc", "moongres"], "env_js.mbt": ["js"], "env_native.mbt": ["native", "llvm"] } diff --git a/float/moon.pkg.json b/float/moon.pkg.json index 241bb9058..3171e2a0f 100644 --- a/float/moon.pkg.json +++ b/float/moon.pkg.json @@ -2,9 +2,9 @@ "import": ["moonbitlang/core/builtin", "moonbitlang/core/double", "moonbitlang/core/uint"], "targets": { "round_js.mbt": ["js"], - "round_wasm.mbt": ["wasm", "wasm-gc"], - "round.mbt": ["not", "js", "wasm", "wasm-gc"], - "to_int.mbt": ["not", "wasm", "wasm-gc"], - "to_int_wasm.mbt": ["wasm", "wasm-gc"] + "round_wasm.mbt": ["wasm", "wasm-gc", "moongres"], + "round.mbt": ["not", "js", "wasm", "wasm-gc", "moongres"], + "to_int.mbt": ["not", "wasm", "wasm-gc", "moongres"], + "to_int_wasm.mbt": ["wasm", "wasm-gc", "moongres"] } } From edce290e88f6d9861c23d683e508c0232fbf6a4f Mon Sep 17 00:00:00 2001 From: Xenia Lu Date: Fri, 17 Oct 2025 17:04:57 +0800 Subject: [PATCH 2/3] feat: panic in String::from_array() https://github.com/moonbitlang/core/issues/2838 --- string/additional_coverage_test.mbt | 8 -------- string/view_test.mbt | 19 ++----------------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/string/additional_coverage_test.mbt b/string/additional_coverage_test.mbt index 211ed8b90..8cbc6fbdf 100644 --- a/string/additional_coverage_test.mbt +++ b/string/additional_coverage_test.mbt @@ -73,11 +73,3 @@ test "View::default and hash" { let v2 = "abc".view() assert_eq(v1.hash(), v2.hash()) } - -///| -test "get_char invalid surrogate pair" { - let s = String::from_array([(0xD800).unsafe_to_char(), 'A']) - inspect(s.get_char(0), content="None") - let v = s[:] - inspect(v.get_char(0), content="None") -} diff --git a/string/view_test.mbt b/string/view_test.mbt index c3ece3f1c..c398b6198 100644 --- a/string/view_test.mbt +++ b/string/view_test.mbt @@ -380,25 +380,10 @@ test "panic on invalid end index" { } ///| -test "panic length_eq should panic on invalid surrogate pair" { +test "panic on invalid surrogate pair" { // Create a string with an invalid surrogate pair: // 0xD800 is a leading surrogate, but followed by a non-trailing surrogate character 'A' - let str = String::from_array([(0xD800).unsafe_to_char(), 'A']) - let view = str[:] - // This will trigger abort("invalid surrogate pair") in length_eq - ignore(view.char_length_eq(1)) -} - -///| -test "panic_length_ge invalid surrogate pair" { - let invalid_surrogate_pair = String::from_array([ - (0xD800).unsafe_to_char(), // Leading surrogate - (0x0041).unsafe_to_char(), // Invalid trailing surrogate (just a regular 'A') - ]) - let view = invalid_surrogate_pair[:] - // This should abort with "invalid surrogate pair" - let _ = view.char_length_ge(1) - + ignore(String::from_array([(0xD800).unsafe_to_char(), 'A'])) } ///| From f84434ca0e627e186317a8f37699d8fed6112b90 Mon Sep 17 00:00:00 2001 From: Xenia Lu Date: Sat, 18 Oct 2025 10:02:54 +0800 Subject: [PATCH 3/3] fix: use MoonGRES FFIs for env and bench --- bench/monotonic_clock_moongres.mbt | 17 +++++++++++++++++ bench/moon.pkg.json | 3 ++- env/env_moongres.mbt | 20 ++++++++++++++++++++ env/env_test.mbt | 7 +++---- env/moon.pkg.json | 3 ++- 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 bench/monotonic_clock_moongres.mbt create mode 100644 env/env_moongres.mbt diff --git a/bench/monotonic_clock_moongres.mbt b/bench/monotonic_clock_moongres.mbt new file mode 100644 index 000000000..dfa5cbc65 --- /dev/null +++ b/bench/monotonic_clock_moongres.mbt @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2025 燕几(北京)科技有限公司 +// SPDX-License-Identifier: Apache-2.0 OR MulanPSL-2.0 + +///| +#external +type Timestamp + +///| +fn monotonic_nanos_since(x : Timestamp) -> UInt64 = "env" "monotonic_nanos_since" + +///| +pub fn monotonic_clock_start() -> Timestamp = "env" "monotonic_now" + +///| +pub fn monotonic_clock_end(ts : Timestamp) -> Double { + monotonic_nanos_since(ts).to_double() / 1000.0 +} diff --git a/bench/moon.pkg.json b/bench/moon.pkg.json index 7df80944b..f9f663d1a 100644 --- a/bench/moon.pkg.json +++ b/bench/moon.pkg.json @@ -1,7 +1,8 @@ { "targets": { "monotonic_clock_js.mbt": ["js"], - "monotonic_clock_wasm.mbt": ["wasm", "wasm-gc", "moongres"], + "monotonic_clock_wasm.mbt": ["wasm", "wasm-gc"], + "monotonic_clock_moongres.mbt": ["moongres"], "monotonic_clock_native.mbt": ["native", "llvm"] }, "import": [ diff --git a/env/env_moongres.mbt b/env/env_moongres.mbt new file mode 100644 index 000000000..0ba316c46 --- /dev/null +++ b/env/env_moongres.mbt @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2025 燕几(北京)科技有限公司 +// SPDX-License-Identifier: Apache-2.0 OR MulanPSL-2.0 + +///| +fn get_cli_args_internal() -> Array[String] { + [] +} + +///| +fn realtime_micros_since_unix_epoch() -> UInt64 = "env" "realtime_micros_since_unix_epoch" + +///| +fn now_internal() -> UInt64 { + realtime_micros_since_unix_epoch() / 1000 +} + +///| +fn current_dir_internal() -> String? { + None +} diff --git a/env/env_test.mbt b/env/env_test.mbt index 3459aad83..0223ad172 100644 --- a/env/env_test.mbt +++ b/env/env_test.mbt @@ -15,7 +15,7 @@ ///| test { let args = @env.args() - assert_true(args.length() != 0) + ignore(args.length()) } ///| @@ -26,7 +26,6 @@ test "now returns reasonable timestamp" { } ///| -test "current_dir returns reasonable directory" { - let dir = @env.current_dir() - assert_true(dir.is_empty() == false) +test "current_dir works" { + ignore(@env.current_dir()) } diff --git a/env/moon.pkg.json b/env/moon.pkg.json index 24ead7634..abf55a573 100644 --- a/env/moon.pkg.json +++ b/env/moon.pkg.json @@ -7,7 +7,8 @@ "moonbitlang/core/option" ], "targets": { - "env_wasm.mbt": ["wasm", "wasm-gc", "moongres"], + "env_wasm.mbt": ["wasm", "wasm-gc"], + "env_moongres.mbt": ["moongres"], "env_js.mbt": ["js"], "env_native.mbt": ["native", "llvm"] }