Skip to content
Closed
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
10 changes: 5 additions & 5 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# TODO: remove bleeding
- name: Install Moonbit
run: |
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s bleeding
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s nightly
echo "$HOME/.moon/bin" >> $GITHUB_PATH

- name: Moon version
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
license-header-check:
runs-on: ubuntu-latest
env:
HAWKEYE_VERSION: v5.8.1
HAWKEYE_VERSION: v6.3.0
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
done
(exit $_passed)

bleeding-check:
nightly-check:
continue-on-error: true
strategy:
matrix:
Expand All @@ -125,9 +125,9 @@ jobs:
with:
python-version: '3.13'

- name: Install Moonbit (bleeding)
- name: Install Moonbit (nightly)
run: |
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s bleeding
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s nightly
echo "$HOME/.moon/bin" >> $GITHUB_PATH

- name: Moon version
Expand Down
13 changes: 13 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[files]
extend-exclude = ["**/*_gen.mbt"]

[default.extend-identifiers]
IDentifier = "IDentifier"

[default]
extend-ignore-re = [
# ignore string literals
"pen.ba\\(distance\\)",
"\"(.*?)\"",
".*#|.*",
]
40 changes: 30 additions & 10 deletions bool.mbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// ========================================
// PyBool
// ========================================
Expand All @@ -7,10 +21,11 @@ pub struct PyBool {
priv obj : PyObject
}

///| Create a python boolean object from a python object.
/// If the object is not a boolean, it will raise a TypeMisMatchError.
///|
/// Create a python boolean object from a python object.
/// If the object is not a boolean, it will raise a TypeMismatchError.
pub fn PyBool::create(obj : PyObject) -> PyBool raise PyRuntimeError {
guard obj.is_bool() else { raise TypeMisMatchError }
guard obj.is_bool() else { raise TypeMismatchError }
PyBool::{ obj, }
}

Expand All @@ -19,12 +34,13 @@ fn PyBool::create_unchecked(obj : PyObject) -> PyBool {
PyBool::{ obj, }
}

///| Create a python boolean object from a python object reference.
/// If the object is not a boolean, it will raise a TypeMisMatchError.
///|
/// Create a python boolean object from a python object reference.
/// If the object is not a boolean, it will raise a TypeMismatchError.
pub fn PyBool::create_by_ref(
obj_ref : @cpython.PyObjectRef,
) -> PyBool raise PyRuntimeError {
guard @cpython.py_bool_check(obj_ref) else { raise TypeMisMatchError }
guard @cpython.py_bool_check(obj_ref) else { raise TypeMismatchError }
PyBool::{ obj: PyObject::create(obj_ref) }
}

Expand All @@ -38,7 +54,8 @@ pub fn PyBool::dump(self : PyBool) -> Unit {
self.obj.dump()
}

///| Create a python boolean object from moonbit bool.
///|
/// Create a python boolean object from moonbit bool.
///
/// ## Example
///
Expand All @@ -61,7 +78,8 @@ pub fn PyBool::from(value : Bool) -> PyBool {
PyBool::create_by_ref_unchecked(obj_ref)
}

///| Return `true` if it is true, using python interpreter.
///|
/// Return `true` if it is true, using python interpreter.
///
/// ## Example
///
Expand All @@ -82,7 +100,8 @@ pub fn PyBool::to_bool(self : PyBool) -> Bool {
self.is_true()
}

///| Return `true` if it is false, using python interpreter.
///|
/// Return `true` if it is false, using python interpreter.
///
/// ## Example
///
Expand All @@ -97,7 +116,8 @@ pub fn PyBool::is_false(self : PyBool) -> Bool {
self.is_true() |> not
}

///| Return the reverse of the boolean value.
///|
/// Return the reverse of the boolean value.
///
/// ## Example
///
Expand Down
4 changes: 2 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ try {
const pyIncludeDir = path.join(pyPrefix, 'include', `python${pyVersion}`)

// 4. Construct CC_FLAGS
const stubCCFlags = `-I${pyIncludeDir} -DNDEBUG`
const stubCCFlags = `-I${pyIncludeDir} -DNDEBUG -fsanitize=address -g`
const ccFlags = stubCCFlags

// 5. Get Python ldflags
Expand All @@ -37,7 +37,7 @@ try {
// 6. Construct CC_LINK_FLAGS
// Sometimes ldflags already includes the -lpython part, remove it if present before adding ours
const baseLdflags = pyLdflags.replace(/-lpython[\d.]+\w*/, '').trim()
const ccLinkFlags = `${baseLdflags} -lpython${pyVersion}`
const ccLinkFlags = `${baseLdflags} -lpython${pyVersion} -fsanitize=address -g`

// 7. Construct C_INCLUDE_PATH
const existingCIncludePath = process.env.C_INCLUDE_PATH || ''
Expand Down
34 changes: 25 additions & 9 deletions callable.mbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// ========================================
// Function
// ========================================
Expand All @@ -7,10 +21,11 @@ pub struct PyCallable {
priv obj : PyObject
}

///| Create a python callable object from a PyObject.
/// If the object is not callable, a TypeMisMatchError is raised.
///|
/// Create a python callable object from a PyObject.
/// If the object is not callable, a TypeMismatchError is raised.
pub fn PyCallable::create(obj : PyObject) -> PyCallable raise PyRuntimeError {
guard obj.is_callable() else { raise TypeMisMatchError }
guard obj.is_callable() else { raise TypeMismatchError }
PyCallable::{ obj, }
}

Expand All @@ -19,12 +34,13 @@ fn PyCallable::create_unchecked(obj : PyObject) -> PyCallable {
PyCallable::{ obj, }
}

///| Create a python callable object from a PyObjectRef.
/// If the object is not callable, a TypeMisMatchError is raised.
///|
/// Create a python callable object from a PyObjectRef.
/// If the object is not callable, a TypeMismatchError is raised.
pub fn PyCallable::create_by_ref(
obj : @cpython.PyObjectRef,
) -> PyCallable raise PyRuntimeError {
guard @cpython.py_callable_check(obj) else { raise TypeMisMatchError }
guard @cpython.py_callable_check(obj) else { raise TypeMismatchError }
PyCallable::{ obj: PyObject::create(obj) }
}

Expand All @@ -49,9 +65,9 @@ pub fn PyCallable::dump(self : PyCallable) -> Unit {
///|
pub fn PyCallable::invoke(
self : PyCallable,
args~ : PyTuple = PyTuple::new(0),
kwargs~ : PyDict = PyDict::new(),
print_err~ : Bool = false,
args? : PyTuple = PyTuple::new(0),
kwargs? : PyDict = PyDict::new(),
print_err? : Bool = false,
) -> PyObjectEnum? raise PyRuntimeError {
let obj_ref = if kwargs.len() > 0 {
@cpython.py_object_call(self.obj_ref(), args.obj_ref(), kwargs.obj_ref())
Expand Down
Loading
Loading