Skip to content

Commit

Permalink
Tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
vlopes11 committed Nov 10, 2022
1 parent e6b8b50 commit 099e566
Show file tree
Hide file tree
Showing 9 changed files with 13,662 additions and 13,405 deletions.
50 changes: 50 additions & 0 deletions assembly/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::ProcedureId;

use super::{String, ToString, Token};
use core::fmt;

#[cfg(feature = "std")]
use std::error::Error as StdError;

// ASSEMBLY ERROR
// ================================================================================================

Expand Down Expand Up @@ -326,6 +331,33 @@ pub enum SerializationError {
InvalidFieldElement,
}

#[derive(Clone, Eq, PartialEq)]
pub struct PrecompileError {
pub message: String,
}

impl PrecompileError {
pub fn invalid_module(idx: u16) -> Self {
Self {
message: format!("undefined procedure: {idx}"),
}
}

pub fn invalid_proc(proc: &ProcedureId) -> Self {
Self {
message: format!("undefined module procedure: {proc:x?}"),
}
}
}

impl From<AssemblyError> for PrecompileError {
fn from(err: AssemblyError) -> Self {
Self {
message: err.message,
}
}
}

// COMMON TRAIT IMPLEMENTATIONS
// ================================================================================================

Expand All @@ -340,3 +372,21 @@ impl fmt::Display for AssemblyError {
write!(f, "assembly error at {}: {}", self.step, self.message)
}
}

impl fmt::Debug for PrecompileError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "precompilation error: {}", self.message)
}
}

impl fmt::Display for PrecompileError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "precompilation error: {}", self.message)
}
}

#[cfg(feature = "std")]
impl StdError for AssemblyError {}

#[cfg(feature = "std")]
impl StdError for PrecompileError {}
8 changes: 4 additions & 4 deletions assembly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ use procedures::Procedure;

mod parsers;
use parsers::{combine_blocks, parse_code_blocks};
pub use parsers::{parse_module, ModuleAst};
pub use parsers::{ModuleAst, NamedModuleAst, ProcedureAst, ProgramAst};

mod tokens;
use tokens::{Token, TokenStream};

mod errors;
pub use errors::AssemblyError;
pub use errors::{AssemblyError, PrecompileError};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -93,7 +93,7 @@ pub trait ModuleProvider {
fn get_source(&self, path: &str) -> Option<&str>;

/// Fetch a module AST from its ID
fn get_module(&self, id: &ProcedureId) -> Option<&ModuleAst>;
fn get_module(&self, id: &ProcedureId) -> Option<NamedModuleAst<'_>>;
}

// A default provider that won't resolve modules
Expand All @@ -102,7 +102,7 @@ impl ModuleProvider for () {
None
}

fn get_module(&self, _id: &ProcedureId) -> Option<&ModuleAst> {
fn get_module(&self, _id: &ProcedureId) -> Option<NamedModuleAst<'_>> {
None
}
}
Expand Down
Loading

0 comments on commit 099e566

Please sign in to comment.