Skip to content
Draft
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
4 changes: 2 additions & 2 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl Compiler {
let mut next_wire_id = 0;

// First inputs
for (_, node_id) in &input_to_node_id {
for node_id in input_to_node_id.values() {
node_id_to_wire_id.insert(*node_id, next_wire_id);
next_wire_id += 1;
}
Expand Down Expand Up @@ -492,7 +492,7 @@ impl Compiler {
}

// Assign wire ids to output nodes
for (_, node_id) in &output_to_node_id {
for node_id in output_to_node_id.values() {
node_id_to_wire_id.insert(*node_id, next_wire_id);
next_wire_id += 1;
}
Expand Down
22 changes: 22 additions & 0 deletions src/error_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::fs;

pub fn get_line_and_column(file_path: &str, index: usize) -> Option<String> {
let content = fs::read_to_string(file_path).ok()?;
let line_num: usize;
let col_num: usize;
let mut current_index = 0;

for (line_idx, line) in content.lines().enumerate() {
let line_length = line.len() + 1;
if current_index + line_length > index {
line_num = line_idx + 1;
col_num = index - current_index + 1;
return Some(format!(
"file {} , line {}, column {}",
file_path, line_num, col_num
));
}
current_index += line_length;
}
None
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod arithmetic_circuit;
pub mod circom;
pub mod cli;
pub mod compiler;
pub mod error_handler;
pub mod process;
pub mod program;
pub mod runtime;
Expand Down
16 changes: 14 additions & 2 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Handles execution of statements and expressions for arithmetic circuit generation within a `Runtime` environment.

use crate::compiler::{AGateType, Compiler};
use crate::error_handler::get_line_and_column;
use crate::program::ProgramError;
use crate::runtime::{
generate_u32, increment_indices, u32_to_access, Context, DataAccess, DataType, NestedValue,
Expand Down Expand Up @@ -170,15 +171,26 @@ pub fn process_statement(

Ok(())
}
Statement::Assert { arg, .. } => {
Statement::Assert { meta, arg, .. } => {
let access = process_expression(ac, runtime, program_archive, arg)?;
let result = runtime
.current_context()?
.get_variable_value(&access)?
.ok_or(ProgramError::EmptyDataItem)?;

let file_path = program_archive
.file_library
.get_files()
.get(meta.file_id.unwrap())
.unwrap()
.name();

let message = get_line_and_column(&file_path, meta.start).unwrap();

if result == 0 {
return Err(ProgramError::RuntimeError(RuntimeError::AssertionFailed));
return Err(ProgramError::RuntimeError(RuntimeError::AssertionFailed(
message,
)));
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,8 @@ pub enum RuntimeError {
NotAValue,
#[error("Unsupported data type")]
UnsupportedDataType,
#[error("Assertion failed")]
AssertionFailed,
#[error("Assertion Failed in {0}")]
AssertionFailed(String),
}

impl From<RuntimeError> for ProgramError {
Expand Down