Skip to content
Open
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
7 changes: 7 additions & 0 deletions mm0-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions mm0-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ wasm-bindgen = "0.2"
name = "mm0-rs"
path = "src/main.rs"
doc = false

[dev-dependencies]
glob = "0.3.0"
18 changes: 9 additions & 9 deletions mm0-rs/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum FileCache {
}

#[derive(DeepSizeOf, Clone)]
pub(crate) enum FileContents {
pub enum FileContents {
Ascii(Arc<LinedString>),
#[cfg(not(target_arch = "wasm32"))]
MMap(Arc<memmap::Mmap>),
Expand All @@ -64,23 +64,23 @@ pub(crate) enum FileContents {

impl FileContents {
/// Constructs a new [`FileContents`] from source text.
pub(crate) fn new(text: String) -> Self {
pub fn new(text: String) -> Self {
Self::Ascii(Arc::new(text.into()))
}

/// Constructs a new [`FileContents`] from a memory map.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn new_mmap(data: memmap::Mmap) -> Self {
pub fn new_mmap(data: memmap::Mmap) -> Self {
Self::MMap(Arc::new(data))
}

/// Constructs a new [`FileContents`] from a memory map.
#[allow(unused)]
pub(crate) fn new_bin(data: Box<[u8]>) -> Self {
pub fn new_bin(data: Box<[u8]>) -> Self {
Self::Bin(data.into())
}

pub(crate) fn new_bin_from_file(path: &std::path::Path) -> io::Result<Self> {
pub fn new_bin_from_file(path: &std::path::Path) -> io::Result<Self> {
#[cfg(not(target_arch = "wasm32"))] {
let file = fs::File::open(path)?;
// Safety: Well, memory mapping files is never totally safe, but we're assuming
Expand All @@ -94,17 +94,17 @@ impl FileContents {
}
}

pub(crate) fn try_ascii(&self) -> Option<&Arc<LinedString>> {
pub fn try_ascii(&self) -> Option<&Arc<LinedString>> {
if let Self::Ascii(e) = self {Some(e)} else {None}
}

#[track_caller]
pub(crate) fn ascii(&self) -> &Arc<LinedString> {
pub fn ascii(&self) -> &Arc<LinedString> {
self.try_ascii().expect("expected ASCII file")
}

#[allow(unused)]
pub(crate) fn ptr_eq(&self, other: &Self) -> bool {
pub fn ptr_eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Ascii(e1), Self::Ascii(e2)) => Arc::ptr_eq(e1, e2),
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -469,7 +469,7 @@ fn elaborate_and_send(path: FileRef, send: FSender<ElabResult<()>>, rd: ArcList<

/// Elaborate a file, and return the completed [`FrozenEnv`] result, along with the
/// file contents.
pub(crate) fn elab_for_result(path: FileRef) -> io::Result<(FileContents, Option<FrozenEnv>)> {
pub fn elab_for_result(path: FileRef) -> io::Result<(FileContents, Option<FrozenEnv>)> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to make this pub in order to make it accessible from the test. Unfortunately this results in a bunch of warnings about missing documentation.

let (path, file) = VFS.get_or_insert(path)?;
let env = match block_on(elaborate(path, Default::default()))? {
ElabResult::Ok(_, _, env) => Some(env),
Expand Down
1 change: 1 addition & 0 deletions mm0-rs/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Common test code goes here
13 changes: 13 additions & 0 deletions mm0-rs/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mod common;

use mm0_rs::{compiler::elab_for_result, FileRef};

#[test]
fn elaborate_examples() {
for file in glob::glob("../examples/*.mm[01]").unwrap() {
let file = file.unwrap();
println!("\n--- Elaborating {} ---", file.display());
let file_ref = FileRef::from(file);
let (_, _) = elab_for_result(file_ref.clone()).expect(&format!("failed to elaborate {}", file_ref.clone()));
}
}