Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Aug 13, 2024
1 parent 9fe722d commit 8d47f09
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 28 deletions.
9 changes: 4 additions & 5 deletions assembly/src/assembler/instruction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use core::ops::RangeBounds;

use miette::miette;
use vm_core::{mast::MastNodeId, Decorator, ONE, ZERO};

use super::{
ast::InvokeKind, mast_forest_builder::MastForestBuilder, Assembler, BasicBlockBuilder, Felt,
Operation, ProcedureContext,
};
use crate::{
ast::Instruction, diagnostics::Report, utils::bound_into_included_u64, AssemblyError, Span,
};
use crate::{ast::Instruction, utils::bound_into_included_u64, AssemblyError, Span};

mod adv_ops;
mod crypto_ops;
Expand Down Expand Up @@ -480,10 +479,10 @@ where
let min = bound_into_included_u64(range.start_bound(), true);
let max = bound_into_included_u64(range.end_bound(), false);
AssemblyError::Other(
Report::msg(format!(
miette!(
"parameter value must be greater than or equal to {min} and \
less than or equal to {max}, but was {value}",
))
)
.into(),
)
})
Expand Down
3 changes: 1 addition & 2 deletions assembly/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ impl Assembler {
namespace: crate::LibraryNamespace,
dir: &std::path::Path,
) -> Result<(), Report> {
let source_manager = self.source_manager.clone();
for module in crate::parser::read_modules_from_dir(namespace, dir, source_manager)? {
for module in crate::parser::read_modules_from_dir(namespace, dir, &self.source_manager)? {
self.module_graph.add_ast_module(module)?;
}

Expand Down
6 changes: 4 additions & 2 deletions assembly/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use alloc::{
vec::Vec,
};

use miette::miette;

use crate::{
ast::{Module, ModuleKind},
diagnostics::{
Expand Down Expand Up @@ -152,10 +154,10 @@ impl Compile for Box<Module> {
}
Ok(self)
} else {
Err(Report::msg(format!(
Err(miette!(
"compilation failed: expected a {} module, but got a {actual} module",
options.kind
)))
))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion assembly/src/library/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ mod use_std_library {
let path = path.as_ref();

let modules =
crate::parser::read_modules_from_dir(namespace, path, assembler.source_manager())?;
crate::parser::read_modules_from_dir(namespace, path, &assembler.source_manager())?;
assembler.assemble_library(modules)
}

Expand Down
28 changes: 14 additions & 14 deletions assembly/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod token;

use alloc::{boxed::Box, collections::BTreeSet, string::ToString, sync::Arc, vec::Vec};

use miette::miette;

pub use self::{
error::{BinErrorKind, HexErrorKind, LiteralErrorKind, ParsingError},
lexer::Lexer,
Expand All @@ -33,6 +35,9 @@ use crate::{
sema, LibraryPath, SourceManager,
};

// TYPE ALIASES
// ================================================================================================

type ParseError<'a> = lalrpop_util::ParseError<u32, Token<'a>, ParsingError>;

// MODULE PARSER
Expand Down Expand Up @@ -173,7 +178,7 @@ fn parse_forms_internal(
pub fn read_modules_from_dir(
namespace: crate::LibraryNamespace,
dir: &std::path::Path,
source_manager: Arc<dyn SourceManager>,
source_manager: &dyn SourceManager,
) -> Result<impl Iterator<Item = Box<ast::Module>>, Report> {
use std::collections::{btree_map::Entry, BTreeMap};

Expand All @@ -182,18 +187,12 @@ pub fn read_modules_from_dir(
use crate::diagnostics::{IntoDiagnostic, WrapErr};

if !dir.is_dir() {
return Err(Report::msg(format!(
"the provided path '{}' is not a valid directory",
dir.display()
)));
return Err(miette!("the provided path '{}' is not a valid directory", dir.display()));
}

// mod.masm is not allowed in the root directory
if dir.join(ast::Module::ROOT_FILENAME).exists() {
return Err(Report::msg(format!(
"{} is not allowed in the root directory",
ast::Module::ROOT_FILENAME
)));
return Err(miette!("{} is not allowed in the root directory", ast::Module::ROOT_FILENAME));
}

let mut modules = BTreeMap::default();
Expand All @@ -209,10 +208,10 @@ pub fn read_modules_from_dir(

// Parse module at the given path
let mut parser = ModuleParser::new(ast::ModuleKind::Library);
let ast = parser.parse_file(name.clone(), &source_path, &source_manager)?;
let ast = parser.parse_file(name.clone(), &source_path, source_manager)?;
match modules.entry(name) {
Entry::Occupied(ref entry) => {
return Err(Report::msg(format!("duplicate module '{0}'", entry.key().clone())));
return Err(miette!("duplicate module '{0}'", entry.key().clone()));
},
Entry::Vacant(entry) => {
entry.insert(ast);
Expand All @@ -233,6 +232,7 @@ mod module_walker {
path::{Path, PathBuf},
};

use super::miette;
use crate::{
ast::Module,
diagnostics::{IntoDiagnostic, Report},
Expand Down Expand Up @@ -282,10 +282,10 @@ mod module_walker {
// Remove the file extension and the root prefix, leaving a namespace-relative path
file_path.set_extension("");
if file_path.is_dir() {
return Err(Report::msg(format!(
return Err(miette!(
"file and directory with same name are not allowed: {}",
file_path.display()
)));
));
}
let relative_path = file_path
.strip_prefix(self.root)
Expand All @@ -296,7 +296,7 @@ mod module_walker {
for component in relative_path.iter() {
let component = component.to_str().ok_or_else(|| {
let p = entry.path();
Report::msg(format!("{} is an invalid directory entry", p.display()))
miette!("{} is an invalid directory entry", p.display())
})?;
libpath.push(component).into_diagnostic()?;
}
Expand Down
2 changes: 0 additions & 2 deletions miden/src/cli/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ impl BundleCmd {
let assembler = Assembler::default().with_debug_mode(true);
let library_namespace =
namespace.parse::<LibraryNamespace>().expect("invalid base namespace");
// TODO: Add version to `Library`
// let version = self.version.parse::<Version>().expect("invalid cargo version");
let library = Library::from_dir(&self.dir, library_namespace, assembler)?;

// write the masl output
Expand Down
2 changes: 0 additions & 2 deletions stdlib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ fn main() -> Result<()> {

let assembler = Assembler::default().with_debug_mode(cfg!(feature = "with-debug-info"));
let namespace = "std".parse::<LibraryNamespace>().expect("invalid base namespace");
// TODO: Add version to `Library`
//let version = env!("CARGO_PKG_VERSION").parse::<Version>().expect("invalid cargo version");
let stdlib = Library::from_dir(asm_dir, namespace, assembler)?;

// write the masl output
Expand Down

0 comments on commit 8d47f09

Please sign in to comment.