Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasekawa-Takumi committed Apr 19, 2024
1 parent 7186e5b commit 5fc93f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions basic/src/bin/valida.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use p3_baby_bear::BabyBear;

use p3_fri::{FriConfig, TwoAdicFriPcs, TwoAdicFriPcsConfig};
use valida_cpu::MachineWithCpuChip;
use valida_machine::{AdviceProvider, GlobalAdviceProvider, Machine, MachineProof, ProgramROM, StdinAdviceProvider, StoppingFlag};
use valida_machine::{
AdviceProvider, GlobalAdviceProvider, Machine, MachineProof, ProgramROM, StdinAdviceProvider,
StoppingFlag,
};
use valida_memory::MachineWithMemoryChip;

use valida_elf::{load_executable_file, Program};
Expand Down Expand Up @@ -65,7 +68,7 @@ struct Context {
last_fp_: u32,
recorded_current_fp_: u32,
last_fp_size_: u32,
advice : GlobalAdviceProvider,
advice: GlobalAdviceProvider,
}

impl Context {
Expand All @@ -78,7 +81,7 @@ impl Context {
last_fp_: args.stack_height,
recorded_current_fp_: args.stack_height,
last_fp_size_: 0,
advice : GlobalAdviceProvider::new(&args.advice),
advice: GlobalAdviceProvider::new(&args.advice),
};

let Program { code, data } = load_executable_file(
Expand Down
14 changes: 7 additions & 7 deletions machine/src/advice.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::slice;
use std::fs::File;
use std::io;
use std::io::Read;
use std::fs::File;

pub trait AdviceProvider {
/// Get the next byte from the advice tape, if any.
Expand Down Expand Up @@ -35,7 +35,7 @@ impl FixedAdviceProvider {
pub fn new(advice: Vec<u8>) -> Self {
Self { advice, index: 0 }
}
pub fn from_file(file : &mut File) -> Self {
pub fn from_file(file: &mut File) -> Self {
// read the entire file into self::advice:
let mut advice = Vec::new();
file.read_to_end(&mut advice).unwrap();
Expand Down Expand Up @@ -70,26 +70,26 @@ impl AdviceProvider for StdinAdviceProvider {
}

pub struct GlobalAdviceProvider {
provider : AdviceProviderType,
provider: AdviceProviderType,
}
impl GlobalAdviceProvider {
pub fn new(file_name : &Option<String>) -> Self {
pub fn new(file_name: &Option<String>) -> Self {
match file_name {
Some(file_name) => {
let mut file = File::open(file_name).unwrap();
let provider = AdviceProviderType::Fixed(FixedAdviceProvider::from_file(&mut file));
Self { provider }
},
}
None => {
let provider = AdviceProviderType::Stdin(StdinAdviceProvider);
Self { provider }
}
}
}
}
}

impl AdviceProvider for GlobalAdviceProvider {
fn get_advice(&mut self) -> Option<u8> {
self.provider.get_advice()
}
}
}

0 comments on commit 5fc93f8

Please sign in to comment.