diff --git a/rapidflux/src/consts.rs b/rapidflux/src/consts.rs new file mode 100644 index 000000000..9dda91466 --- /dev/null +++ b/rapidflux/src/consts.rs @@ -0,0 +1,15 @@ +use librapidflux::consts as lib; +use pyo3::prelude::*; + +use crate::register_submodule_declarations; + +register_submodule_declarations!( + consts, + [ + ("BUILTINS_PACKAGE", lib::BUILTINS_PACKAGE), + ("INTERNAL_PACKAGE", lib::INTERNAL_PACKAGE), + ("MAX_SCALAR_SIZE", lib::MAX_SCALAR_SIZE), + ], + [], + [] +); diff --git a/rapidflux/src/lib.rs b/rapidflux/src/lib.rs index c7a7c5a85..9a693a8aa 100644 --- a/rapidflux/src/lib.rs +++ b/rapidflux/src/lib.rs @@ -9,6 +9,7 @@ use pyo3::prelude::*; +mod consts; mod diagnostics; mod identifier; mod logging; @@ -28,6 +29,9 @@ fn rapidflux(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add("FatalError", py.get_type_bound::())?; + // Constants module + register_submodule!(consts, py, m); + // Logging module register_submodule!(logging, py, m); diff --git a/rapidflux/src/logging.rs b/rapidflux/src/logging.rs index 5bad701d0..f3e26edf3 100644 --- a/rapidflux/src/logging.rs +++ b/rapidflux/src/logging.rs @@ -111,4 +111,9 @@ fn set_quiet(value: bool) { lib::diagnostics::logging::set_quiet(value); } -register_submodule_declarations!(logging, [], [error, help, info, note, set_quiet, warning]); +register_submodule_declarations!( + logging, + [], + [], + [error, help, info, note, set_quiet, warning] +); diff --git a/rapidflux/src/source_code.rs b/rapidflux/src/source_code.rs index f28d684e2..21ce4bfeb 100644 --- a/rapidflux/src/source_code.rs +++ b/rapidflux/src/source_code.rs @@ -26,4 +26,4 @@ fn clear() { lib::clear(); } -register_submodule_declarations!(source_code, [], [clear, register, retrieve]); +register_submodule_declarations!(source_code, [], [], [clear, register, retrieve]); diff --git a/rapidflux/src/ty.rs b/rapidflux/src/ty.rs index d67b5ed4c..dd4b6819b 100644 --- a/rapidflux/src/ty.rs +++ b/rapidflux/src/ty.rs @@ -1142,6 +1142,7 @@ impl_states!( ); register_submodule_declarations!( ty, + [], [ Bounds, Builtins, diff --git a/rapidflux/src/utils.rs b/rapidflux/src/utils.rs index cde63ba83..83f748bc8 100644 --- a/rapidflux/src/utils.rs +++ b/rapidflux/src/utils.rs @@ -31,7 +31,7 @@ macro_rules! impl_states { }; } -/// Register classes and functions in a submodule. +/// Register attributes, classes and functions in a submodule. /// /// This macro generate a `register__module` function that is used by the /// `register_submodule` function later to add a submodule in `rapidflux`. @@ -50,11 +50,11 @@ macro_rules! impl_states { /// fn bar() {} /// fn baz() {} /// -/// register_submodule_declarations!(foo, [A, B], [bar, baz]); +/// register_submodule_declarations!(foo, [("c", 299_792_458)], [A, B], [bar, baz]); /// ``` #[macro_export] macro_rules! register_submodule_declarations { - ($module_name:ident, [$($class_name:ident),* $(,)?], [$($fn_name:ident),* $(,)?] $(,)?) => { + ($module_name:ident, [$(($attr_name:literal, $attr:expr)),* $(,)?], [$($class_name:ident),* $(,)?], [$($fn_name:ident),* $(,)?] $(,)?) => { ::paste::paste! { pub fn []<'py>( py: Python<'py>, @@ -62,6 +62,10 @@ macro_rules! register_submodule_declarations { ) -> PyResult<()> { const PY_MODULE_PATH: &str = concat!("rflx.rapidflux.", stringify!($module_name)); + $( + m.add($attr_name, $attr)?; + )* + $( m.add_class::<$class_name>()?; )* diff --git a/rflx/const.py b/rflx/const.py index d8c704986..731c71bb1 100644 --- a/rflx/const.py +++ b/rflx/const.py @@ -2,13 +2,12 @@ from pathlib import Path from typing import Final -from rflx.identifier import ID +from rflx.rapidflux import ID, consts -BUILTINS_PACKAGE: Final = ID("__BUILTINS__") -INTERNAL_PACKAGE: Final = ID("__INTERNAL__") +BUILTINS_PACKAGE: Final = ID(consts.BUILTINS_PACKAGE) +INTERNAL_PACKAGE: Final = ID(consts.INTERNAL_PACKAGE) -# TODO(eng/recordflux/RecordFlux#1077): Size of integers is limited to 63 bits -MAX_SCALAR_SIZE: Final = 63 +MAX_SCALAR_SIZE: Final = consts.MAX_SCALAR_SIZE CACHE_PATH: Final = Path.cwd() / ".rflx_cache" diff --git a/rflx/rapidflux/consts.pyi b/rflx/rapidflux/consts.pyi new file mode 100644 index 000000000..1d68ec76d --- /dev/null +++ b/rflx/rapidflux/consts.pyi @@ -0,0 +1,5 @@ +from typing import Final + +BUILTINS_PACKAGE: Final[str] +INTERNAL_PACKAGE: Final[str] +MAX_SCALAR_SIZE: Final[int] diff --git a/tests/unit/rapidflux/consts_test.py b/tests/unit/rapidflux/consts_test.py new file mode 100644 index 000000000..ebfa4f3da --- /dev/null +++ b/tests/unit/rapidflux/consts_test.py @@ -0,0 +1,2 @@ +def test_dummy() -> None: + pass