Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [0.4.36]

### Changed

- Prepare for next MoonBit toolchain support (#197)

## [0.4.35]

### Added
Expand Down
4 changes: 2 additions & 2 deletions benchmark/benchmark.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn Task::new(name : String, f : () -> Unit, count? : Int = 10) -> Task {
///|
#deprecated("Use moon bench instead")
#coverage.skip
pub fn run(self : Task) -> TaskResult {
pub fn Task::run(self : Task) -> TaskResult {
let now = @ffi.instant_now()
for i = 1; i <= self.count; i = i + 1 {
(self.f)()
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn Criterion::new() -> Criterion {
///|
#deprecated("Use moon bench instead")
#coverage.skip
pub fn add(self : Criterion, task : Task) -> Unit {
pub fn Criterion::add(self : Criterion, task : Task) -> Unit {
self.tasks.push(task)
}

Expand Down
4 changes: 2 additions & 2 deletions crypto/sha256.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub impl CryptoHasher for SHA256 with update(self : SHA256, data : BytesView) ->

///|
/// update the state of given context from new `data`
pub fn[Data : ByteSource] update(self : SHA256, data : Data) -> Unit {
pub fn[Data : ByteSource] SHA256::update(self : SHA256, data : Data) -> Unit {
let mut offset = 0
while offset < data.length() {
let min_len = if 64 - self.buf_index >= data.length() - offset {
Expand All @@ -143,7 +143,7 @@ pub fn[Data : ByteSource] update(self : SHA256, data : Data) -> Unit {
}

///|
pub fn finalize(self : SHA256) -> FixedArray[Byte] {
pub fn SHA256::finalize(self : SHA256) -> FixedArray[Byte] {
let ret = FixedArray::make(32, Byte::default())
self._finalize_into(ret)
ret
Expand Down
26 changes: 13 additions & 13 deletions decimal/decimal.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub fn Decimal::from_double(d : Double, precision : Int) -> Decimal? {
/// inspect(d.to_string(), content="Some(123.45)")
/// ```
///
pub fn to_string(self : Decimal) -> String {
pub fn Decimal::to_string(self : Decimal) -> String {
if self.is_zero() {
"0"
} else {
Expand Down Expand Up @@ -376,7 +376,7 @@ pub fn Decimal::to_double(self : Decimal) -> Double {
/// inspect(d.to_int(), content="Some(123)")
/// ```
///
pub fn to_int(self : Decimal) -> Int? {
pub fn Decimal::to_int(self : Decimal) -> Int? {
if self.scale == 0 {
Some(self.coefficient.to_int())
} else {
Expand All @@ -400,7 +400,7 @@ pub fn to_int(self : Decimal) -> Int? {
/// inspect(d.to_bigint(), content="123")
/// ```
///
pub fn to_bigint(self : Decimal) -> @bigint.BigInt {
pub fn Decimal::to_bigint(self : Decimal) -> @bigint.BigInt {
if self.scale == 0 {
self.coefficient
} else {
Expand Down Expand Up @@ -431,25 +431,25 @@ pub fn neg_one() -> Decimal {

///|
/// Checks if the decimal is zero.
pub fn is_zero(self : Decimal) -> Bool {
pub fn Decimal::is_zero(self : Decimal) -> Bool {
self.coefficient.is_zero()
}

///|
/// Checks if the decimal is positive.
pub fn is_positive(self : Decimal) -> Bool {
pub fn Decimal::is_positive(self : Decimal) -> Bool {
self.coefficient > 0N
}

///|
/// Checks if the decimal is negative.
pub fn is_negative(self : Decimal) -> Bool {
pub fn Decimal::is_negative(self : Decimal) -> Bool {
self.coefficient < 0N
}

///|
/// Returns the sign of the decimal: -1, 0, or 1.
pub fn signum(self : Decimal) -> Int {
pub fn Decimal::signum(self : Decimal) -> Int {
if self.coefficient.is_zero() {
0
} else if self.coefficient > 0N {
Expand All @@ -461,7 +461,7 @@ pub fn signum(self : Decimal) -> Int {

///|
/// Returns the absolute value of the decimal.
pub fn abs(self : Decimal) -> Decimal {
pub fn Decimal::abs(self : Decimal) -> Decimal {
if self.coefficient < 0N {
{ coefficient: -self.coefficient, scale: self.scale }
} else {
Expand All @@ -471,13 +471,13 @@ pub fn abs(self : Decimal) -> Decimal {

///|
/// Returns the coefficient (significant digits) of the decimal.
pub fn coefficient(self : Decimal) -> @bigint.BigInt {
pub fn Decimal::coefficient(self : Decimal) -> @bigint.BigInt {
self.coefficient
}

///|
/// Returns the scale (number of decimal places) of the decimal.
pub fn scale(self : Decimal) -> Int {
pub fn Decimal::scale(self : Decimal) -> Int {
self.scale
}

Expand All @@ -503,7 +503,7 @@ pub fn scale(self : Decimal) -> Int {
/// inspect(rounded.to_string(), content="3.14")
/// ```
///
pub fn round(self : Decimal, places : Int) -> Decimal? {
pub fn Decimal::round(self : Decimal, places : Int) -> Decimal? {
if places < 0 || places > max_scale {
return None
}
Expand Down Expand Up @@ -547,7 +547,7 @@ pub fn round(self : Decimal, places : Int) -> Decimal? {
/// inspect(truncated.to_string(), content="3.14")
/// ```
///
pub fn truncate(self : Decimal, places : Int) -> Decimal? {
pub fn Decimal::truncate(self : Decimal, places : Int) -> Decimal? {
if places < 0 || places > max_scale {
return None
}
Expand Down Expand Up @@ -585,7 +585,7 @@ pub fn truncate(self : Decimal, places : Int) -> Decimal? {
/// inspect(scaled.to_string(), content="123.4500")
/// ```
///
pub fn scale_to(self : Decimal, new_scale : Int) -> Decimal? {
pub fn Decimal::scale_to(self : Decimal, new_scale : Int) -> Decimal? {
if new_scale < 0 || new_scale > max_scale {
return None
}
Expand Down
45 changes: 24 additions & 21 deletions encoding/decoding.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn decoder(encoding : Encoding) -> Decoder {
/// inspect(decoder.decode(inputs[1], stream=true), content="")
/// inspect(decoder.decode(inputs[2], stream=false), content="🐰")
/// ```
pub fn decode(
pub fn Decoder::decode(
self : Decoder,
input : BytesView,
stream? : Bool = false,
Expand Down Expand Up @@ -214,7 +214,10 @@ pub fn decode_to(
///
/// `MalformedError`: when the byte sequence is not properly formatted according to the specified encoding.
/// `TruncatedError`: when the byte sequence ends prematurely, implying that more data is expected for complete decoding.
pub fn consume(self : Decoder, input : BytesView) -> String raise Error {
pub fn Decoder::consume(
self : Decoder,
input : BytesView,
) -> String raise Error {
self.decode(input, stream=true)
}

Expand All @@ -236,7 +239,7 @@ pub fn consume(self : Decoder, input : BytesView) -> String raise Error {
///
/// `MalformedError`: This error is raised if the remaining byte sequence is not properly formatted according to the specified encoding.
/// `TruncatedError`: This error is raised if the remaining byte sequence ends prematurely, implying that more data was expected for complete decoding.
pub fn finish(self : Decoder) -> String raise Error {
pub fn Decoder::finish(self : Decoder) -> String raise Error {
self.decode(b"", stream=false)
}

Expand All @@ -255,7 +258,7 @@ pub fn finish(self : Decoder) -> String raise Error {
/// # Returns
///
/// A `String` representing the decoded content from the input byte sequence, with any invalid sequences replaced by the Unicode Replacement Character (`U+FFFD`).
pub fn decode_lossy(
pub fn Decoder::decode_lossy(
self : Decoder,
input : BytesView,
stream? : Bool = false,
Expand Down Expand Up @@ -336,7 +339,7 @@ pub fn Decoder::decode_lossy_to(
/// # Returns
///
/// A `String` representing the partially decoded content from the input byte sequence, with any invalid sequences replaced by the Unicode Replacement Character (`U+FFFD`), as more bytes are expected.
pub fn lossy_consume(self : Decoder, input : BytesView) -> String {
pub fn Decoder::lossy_consume(self : Decoder, input : BytesView) -> String {
self.decode_lossy(input, stream=true)
}

Expand All @@ -353,12 +356,12 @@ pub fn lossy_consume(self : Decoder, input : BytesView) -> String {
/// # Returns
///
/// A `String` representing the final part of the decoded content, with any invalid sequences replaced by the Unicode Replacement Character (`U+FFFD`), after all byte sequences have been processed.
pub fn lossy_finish(self : Decoder) -> String {
pub fn Decoder::lossy_finish(self : Decoder) -> String {
self.decode_lossy(b"", stream=false)
}

///|
fn i_cont(self : Decoder, input : BytesView) -> Unit {
fn Decoder::i_cont(self : Decoder, input : BytesView) -> Unit {
// concat `input` to `i`, drop decoded `i`
let i_rem = @cmp.maximum(self.i_rem(), 0)
let new_len = i_rem + input.length()
Expand All @@ -378,34 +381,34 @@ fn i_cont(self : Decoder, input : BytesView) -> Unit {
// Implementations

///|
fn decode_(self : Decoder) -> Decode {
fn Decoder::decode_(self : Decoder) -> Decode {
(self.k)(self)
}

///|
fn ret(self : Decoder, k : Cont, v : Decode) -> Decode {
fn Decoder::ret(self : Decoder, k : Cont, v : Decode) -> Decode {
self.k = k
v
}

///|
fn i_rem(self : Decoder) -> Int {
fn Decoder::i_rem(self : Decoder) -> Int {
self.i.length() - self.i_pos
}

///|
fn t_need(self : Decoder, need : Int) -> Unit {
fn Decoder::t_need(self : Decoder, need : Int) -> Unit {
self.t_len = 0
self.t_need = need
}

///|
fn eoi(self : Decoder) -> Unit {
fn Decoder::eoi(self : Decoder) -> Unit {
self.i = FixedArray::default()
}

///|
fn refill(self : Decoder, k : Cont) -> Decode {
fn Decoder::refill(self : Decoder, k : Cont) -> Decode {
self.eoi()
self.ret(k, Decode::Refill(Bytes::from_fixedarray(self.t)))
}
Expand Down Expand Up @@ -441,7 +444,7 @@ fn t_fill(k : Cont, decoder : Decoder) -> Decode {
// UTF8

///|
fn decode_utf_8(self : Decoder) -> Decode {
fn Decoder::decode_utf_8(self : Decoder) -> Decode {
let rem = self.i_rem()
if rem <= 0 {
Decode::End
Expand All @@ -465,7 +468,7 @@ fn decode_utf_8(self : Decoder) -> Decode {
}

///|
fn t_decode_utf_8(self : Decoder) -> Decode {
fn Decoder::t_decode_utf_8(self : Decoder) -> Decode {
if self.t_len < self.t_need {
self.ret(Decoder::decode_utf_8, malformed(self.t, 0, self.t_len))
} else {
Expand Down Expand Up @@ -568,7 +571,7 @@ priv enum UTF16Decode {
}

///|
fn decode_utf_16le(self : Decoder) -> Decode {
fn Decoder::decode_utf_16le(self : Decoder) -> Decode {
let rem = self.i_rem()
if rem <= 0 {
Decode::End
Expand All @@ -583,7 +586,7 @@ fn decode_utf_16le(self : Decoder) -> Decode {
}

///|
fn t_decode_utf_16le(self : Decoder) -> Decode {
fn Decoder::t_decode_utf_16le(self : Decoder) -> Decode {
if self.t_len < self.t_need {
self.ret(Decoder::decode_utf_16le, malformed(self.t, 0, self.t_len))
} else {
Expand All @@ -592,7 +595,7 @@ fn t_decode_utf_16le(self : Decoder) -> Decode {
}

///|
fn decode_utf_16le_lo(self : Decoder, v : UTF16Decode) -> Decode {
fn Decoder::decode_utf_16le_lo(self : Decoder, v : UTF16Decode) -> Decode {
match v {
UTF16Uchar(u) => self.ret(Decoder::decode_utf_16le, Uchar(u))
UTF16Malformed(s) => self.ret(Decoder::decode_utf_16le, Malformed(s))
Expand Down Expand Up @@ -675,7 +678,7 @@ fn r_utf_16(
// UTF16BE

///|
fn decode_utf_16be(self : Decoder) -> Decode {
fn Decoder::decode_utf_16be(self : Decoder) -> Decode {
let rem = self.i_rem()
if rem <= 0 {
Decode::End
Expand All @@ -690,7 +693,7 @@ fn decode_utf_16be(self : Decoder) -> Decode {
}

///|
fn t_decode_utf_16be(self : Decoder) -> Decode {
fn Decoder::t_decode_utf_16be(self : Decoder) -> Decode {
if self.t_len < self.t_need {
self.ret(Decoder::decode_utf_16be, malformed(self.t, 0, self.t_len))
} else {
Expand All @@ -699,7 +702,7 @@ fn t_decode_utf_16be(self : Decoder) -> Decode {
}

///|
fn decode_utf_16be_lo(self : Decoder, decode : UTF16Decode) -> Decode {
fn Decoder::decode_utf_16be_lo(self : Decoder, decode : UTF16Decode) -> Decode {
match decode {
UTF16Uchar(x) => self.ret(Decoder::decode_utf_16be, Uchar(x))
UTF16Malformed(x) => self.ret(Decoder::decode_utf_16be, Malformed(x))
Expand Down
6 changes: 3 additions & 3 deletions fs/fs_wasm.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
// limitations under the License.

///|
typealias @ffi.XExternString
using @ffi {type XExternString}

///|
typealias @ffi.XExternByteArray
using @ffi {type XExternByteArray}

///|
typealias @ffi.XExternStringArray
using @ffi {type XExternStringArray}

///|
fn get_error_message_ffi() -> XExternString = "__moonbit_fs_unstable" "get_error_message"
Expand Down
2 changes: 1 addition & 1 deletion moon.mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moonbitlang/x",
"version": "0.4.35",
"version": "0.4.36",
"readme": "README.md",
"repository": "https://github.com/moonbitlang/x",
"license": "Apache-2.0",
Expand Down
4 changes: 1 addition & 3 deletions rational/rational.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub impl[T : Integral] Compare for Rational[T] with compare(
/// inspect(negative.to_double(), content="-0.75")
/// ```
///
pub fn to_double(self : Rational64) -> Double {
pub fn Rational64::to_double(self : Rational64) -> Double {
// TODO: complete algorithm
self.numerator.to_double() / self.denominator.to_double()
}
Expand Down Expand Up @@ -720,8 +720,6 @@ pub fn[T : Integral] Rational::is_integer(self : Rational[T]) -> Bool {
self.denominator == T::from_int(1)
}

///|

///|
test "op_add" {
// 1/2 + 1/3 = 5/6
Expand Down
Loading
Loading