Skip to content

Commit

Permalink
Fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Apr 23, 2024
1 parent b044db3 commit 1f00100
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
13 changes: 10 additions & 3 deletions src/compiler/comptypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,10 @@ pub trait HasCompilerOptsDelegation {
fn compiler_opts(&self) -> Rc<dyn CompilerOpts>;
/// Call a function that updates this object's CompilerOpts and use the
/// update our own object with the result. Return the new wrapper.
fn update_compiler_opts<F: FnOnce(Rc<dyn CompilerOpts>) -> Rc<dyn CompilerOpts>>(&self, f: F) -> Rc<dyn CompilerOpts>;
fn update_compiler_opts<F: FnOnce(Rc<dyn CompilerOpts>) -> Rc<dyn CompilerOpts>>(
&self,
f: F,
) -> Rc<dyn CompilerOpts>;

// Defaults.
fn override_filename(&self) -> String {
Expand Down Expand Up @@ -544,7 +547,10 @@ pub trait HasCompilerOptsDelegation {
fn override_set_start_env(&self, start_env: Option<Rc<SExp>>) -> Rc<dyn CompilerOpts> {
self.update_compiler_opts(|o| o.set_start_env(start_env))
}
fn override_set_prim_map(&self, new_map: Rc<HashMap<Vec<u8>, Rc<SExp>>>) -> Rc<dyn CompilerOpts> {
fn override_set_prim_map(
&self,
new_map: Rc<HashMap<Vec<u8>, Rc<SExp>>>,
) -> Rc<dyn CompilerOpts> {
self.update_compiler_opts(|o| o.set_prim_map(new_map))
}
fn override_read_new_file(
Expand All @@ -561,7 +567,8 @@ pub trait HasCompilerOptsDelegation {
sexp: Rc<SExp>,
symbol_table: &mut HashMap<String, String>,
) -> Result<SExp, CompileErr> {
self.compiler_opts().compile_program(allocator, runner, sexp, symbol_table)
self.compiler_opts()
.compile_program(allocator, runner, sexp, symbol_table)
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/tests/classic/stage_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::classic::clvm_tools::stages::stage_2::helpers::{brun, evaluate, quote
use crate::classic::clvm_tools::stages::stage_2::operators::run_program_for_search_paths;
use crate::classic::clvm_tools::stages::stage_2::reader::{process_embed_file, read_file};

use crate::compiler::comptypes::{CompileErr, CompilerOpts, HasCompilerOptsDelegation};
use crate::compiler::compiler::DefaultCompilerOpts;
use crate::compiler::comptypes::{CompileErr, CompilerOpts, HasCompilerOptsDelegation};
use crate::compiler::sexp::decode_string;
use crate::compiler::srcloc::Srcloc;

Expand Down Expand Up @@ -307,7 +307,10 @@ struct TestCompilerOptsPresentsOwnFiles {

impl TestCompilerOptsPresentsOwnFiles {
fn new(filename: String, files: HashMap<String, String>) -> Self {
TestCompilerOptsPresentsOwnFiles { files: Rc::new(files), opts: Rc::new(DefaultCompilerOpts::new(&filename)) }
TestCompilerOptsPresentsOwnFiles {
files: Rc::new(files),
opts: Rc::new(DefaultCompilerOpts::new(&filename)),
}
}
}

Expand All @@ -316,11 +319,14 @@ impl HasCompilerOptsDelegation for TestCompilerOptsPresentsOwnFiles {
self.opts.clone()
}

fn update_compiler_opts<F: FnOnce(Rc<dyn CompilerOpts>) -> Rc<dyn CompilerOpts>>(&self, f: F) -> Rc<dyn CompilerOpts> {
fn update_compiler_opts<F: FnOnce(Rc<dyn CompilerOpts>) -> Rc<dyn CompilerOpts>>(
&self,
f: F,
) -> Rc<dyn CompilerOpts> {
let new_opts = f(self.opts.clone());
Rc::new(TestCompilerOptsPresentsOwnFiles {
opts: new_opts,
.. self.clone()
..self.clone()
})
}

Expand Down
11 changes: 8 additions & 3 deletions src/tests/compiler/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ impl TestModuleCompilerOpts {
}

impl HasCompilerOptsDelegation for TestModuleCompilerOpts {
fn compiler_opts(&self) -> Rc<dyn CompilerOpts> { self.opts.clone() }
fn update_compiler_opts<F: FnOnce(Rc<dyn CompilerOpts>) -> Rc<dyn CompilerOpts>>(&self, f: F) -> Rc<dyn CompilerOpts> {
fn compiler_opts(&self) -> Rc<dyn CompilerOpts> {
self.opts.clone()
}
fn update_compiler_opts<F: FnOnce(Rc<dyn CompilerOpts>) -> Rc<dyn CompilerOpts>>(
&self,
f: F,
) -> Rc<dyn CompilerOpts> {
let new_opts = f(self.opts.clone());
Rc::new(TestModuleCompilerOpts {
opts: new_opts,
.. self.clone()
..self.clone()
})
}
}
Expand Down

0 comments on commit 1f00100

Please sign in to comment.