From c3bdce74a97e6f442ca64ea4e1ff5df9ce6585c9 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sun, 26 Apr 2020 12:10:38 -0400 Subject: [PATCH] MAINT: cargo fmt. --- src/build/mod.rs | 18 +++----------- src/build/opcode/environment.rs | 2 +- src/build/opcode/runtime.rs | 9 +++---- src/build/opcode/vm.rs | 44 +++++++++++++++++++-------------- src/build/test.rs | 2 +- src/convert/exec.rs | 4 +-- src/convert/yamlmulti.rs | 16 ++++++------ src/main.rs | 29 ++++++++++++++-------- src/parse/mod.rs | 13 ++++++---- 9 files changed, 70 insertions(+), 67 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index d2384fd..c3d56e8 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -194,11 +194,7 @@ where pub fn eval_stmts(&mut self, ast: Vec, path: Option) -> BuildResult { // We should probably stash this in an op_cache somewhere? let ops = translate::AST::translate(ast, &self.working_dir); - let mut vm = VM::new( - self.strict, - Rc::new(ops), - &self.working_dir, - ); + let mut vm = VM::new(self.strict, Rc::new(ops), &self.working_dir); if path.is_some() { vm.set_path(path.unwrap()); } @@ -219,11 +215,7 @@ where println!(""); } // Initialize VM with an empty OpPointer - let mut vm = VM::new( - self.strict, - Rc::new(PositionMap::new()), - &self.working_dir, - ); + let mut vm = VM::new(self.strict, Rc::new(PositionMap::new()), &self.working_dir); loop { // print prompt let line = match editor.readline(&format!("{}> ", lines.next_line())) { @@ -337,11 +329,7 @@ where &mut ops_map, &self.working_dir, ); - let mut vm = VM::new( - self.strict, - Rc::new(ops_map), - &self.working_dir, - ); + let mut vm = VM::new(self.strict, Rc::new(ops_map), &self.working_dir); if self.validate_mode { vm.enable_validate_mode(); } diff --git a/src/build/opcode/environment.rs b/src/build/opcode/environment.rs index 18bb64e..5d12d5e 100644 --- a/src/build/opcode/environment.rs +++ b/src/build/opcode/environment.rs @@ -63,7 +63,7 @@ impl Environment { out_lock: BTreeSet::new(), }; me.populate_stdlib(); - return me + return me; } pub fn get_cached_path_val(&self, path: &String) -> Option> { diff --git a/src/build/opcode/runtime.rs b/src/build/opcode/runtime.rs index c8b8341..7f90628 100644 --- a/src/build/opcode/runtime.rs +++ b/src/build/opcode/runtime.rs @@ -217,12 +217,9 @@ impl Builtins { None => { let op_pointer = decorate_error!(path_pos => env.borrow_mut().get_ops_for_path(&normalized))?; // TODO(jwall): What if we don't have a base path? - let mut vm = VM::with_pointer( - self.strict, - op_pointer, - normalized.parent().unwrap(), - ) - .with_import_stack(import_stack.clone()); + let mut vm = + VM::with_pointer(self.strict, op_pointer, normalized.parent().unwrap()) + .with_import_stack(import_stack.clone()); vm.run(env)?; let result = Rc::new(vm.symbols_to_tuple(true)); env.borrow_mut().update_path_val(&path, result.clone()); diff --git a/src/build/opcode/vm.rs b/src/build/opcode/vm.rs index 9050c34..e372074 100644 --- a/src/build/opcode/vm.rs +++ b/src/build/opcode/vm.rs @@ -55,19 +55,11 @@ pub struct VM { } impl VM { - pub fn new>( - strict: bool, - ops: Rc, - working_dir: P, - ) -> Self { + pub fn new>(strict: bool, ops: Rc, working_dir: P) -> Self { Self::with_pointer(strict, OpPointer::new(ops), working_dir) } - pub fn with_pointer>( - strict: bool, - ops: OpPointer, - working_dir: P, - ) -> Self { + pub fn with_pointer>(strict: bool, ops: OpPointer, working_dir: P) -> Self { Self { working_dir: working_dir.into(), stack: Vec::new(), @@ -489,7 +481,12 @@ impl VM { return vm.pop(); } - fn op_new_scope(&mut self, jp: i32, ptr: OpPointer, env: &RefCell>) -> Result<(), Error> + fn op_new_scope( + &mut self, + jp: i32, + ptr: OpPointer, + env: &RefCell>, + ) -> Result<(), Error> where O: std::io::Write + Clone, E: std::io::Write + Clone, @@ -507,7 +504,11 @@ impl VM { Ok(()) } - fn op_fcall(&mut self, pos: Position, env: &RefCell>) -> Result<(), Error> + fn op_fcall( + &mut self, + pos: Position, + env: &RefCell>, + ) -> Result<(), Error> where O: std::io::Write + Clone, E: std::io::Write + Clone, @@ -890,7 +891,11 @@ impl VM { Ok(()) } - fn op_copy(&mut self, pos: Position, env: &RefCell>) -> Result<(), Error> + fn op_copy( + &mut self, + pos: Position, + env: &RefCell>, + ) -> Result<(), Error> where O: std::io::Write + Clone, E: std::io::Write + Clone, @@ -1074,11 +1079,7 @@ impl VM { Ok(()) } - pub fn get_binding( - &self, - name: &str, - pos: &Position, - ) -> Result<(Rc, Position), Error> { + pub fn get_binding(&self, name: &str, pos: &Position) -> Result<(Rc, Position), Error> { let tpl = if name == "self" { self.self_stack.last().cloned() } else { @@ -1194,7 +1195,12 @@ impl VM { }) } - fn op_runtime(&mut self, h: Hook, pos: Position, env: &RefCell>) -> Result<(), Error> + fn op_runtime( + &mut self, + h: Hook, + pos: Position, + env: &RefCell>, + ) -> Result<(), Error> where O: std::io::Write + Clone, E: std::io::Write + Clone, diff --git a/src/build/test.rs b/src/build/test.rs index 126c37d..16c844b 100644 --- a/src/build/test.rs +++ b/src/build/test.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. use std; -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; use super::{FileBuilder, Val}; use crate::ast::*; diff --git a/src/convert/exec.rs b/src/convert/exec.rs index dd74b09..6d0566b 100644 --- a/src/convert/exec.rs +++ b/src/convert/exec.rs @@ -194,11 +194,11 @@ impl Converter for ExecConverter { #[cfg(test)] mod exec_test { use std::cell::RefCell; - + use super::*; + use crate::build::opcode::Environment; use crate::build::FileBuilder; use crate::convert::traits::Converter; - use crate::build::opcode::Environment; use std; use std::io::Cursor; diff --git a/src/convert/yamlmulti.rs b/src/convert/yamlmulti.rs index fd54068..0d690d1 100644 --- a/src/convert/yamlmulti.rs +++ b/src/convert/yamlmulti.rs @@ -1,11 +1,11 @@ // Copyright 2020 Jeremy Wall -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,15 +16,15 @@ use std; use std::io::Write; use std::rc::Rc; -use crate::convert::yaml::YamlConverter; -use crate::convert::traits::{ConvertResult, Converter}; use crate::build::Val; +use crate::convert::traits::{ConvertResult, Converter}; +use crate::convert::yaml::YamlConverter; -pub struct MultiYamlConverter (YamlConverter); +pub struct MultiYamlConverter(YamlConverter); impl MultiYamlConverter { pub fn new() -> Self { - MultiYamlConverter (YamlConverter::new()) + MultiYamlConverter(YamlConverter::new()) } pub fn convert_list(&self, vals: &Vec>, mut w: &mut dyn Write) -> ConvertResult { @@ -57,4 +57,4 @@ impl Converter for MultiYamlConverter { fn help(&self) -> String { include_str!("yaml_help.txt").to_owned() } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 36e3ff2..ba3376c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,7 +132,7 @@ fn build_file<'a>( if file_path_buf.is_relative() { file_path_buf = std::env::current_dir()?.join(file_path_buf); } -let mut builder = build::FileBuilder::new(std::env::current_dir()?, import_paths, env); + let mut builder = build::FileBuilder::new(std::env::current_dir()?, import_paths, env); builder.set_strict(strict); if validate { builder.enable_validate_mode(); @@ -212,7 +212,8 @@ fn visit_ucg_files( let next_path = next_item.path(); let path_as_string = String::from(next_path.to_string_lossy()); if next_path.is_dir() && recurse { - if let Err(e) = visit_ucg_files(&next_path, recurse, validate, strict, import_paths, env) + if let Err(e) = + visit_ucg_files(&next_path, recurse, validate, strict, import_paths, env) { eprintln!("{}", e); result = false; @@ -262,7 +263,14 @@ fn build_command( let mut ok = true; if files.is_none() { let curr_dir = std::env::current_dir().unwrap(); - let ok = visit_ucg_files(curr_dir.as_path(), recurse, false, strict, import_paths, env); + let ok = visit_ucg_files( + curr_dir.as_path(), + recurse, + false, + strict, + import_paths, + env, + ); if let Ok(false) = ok { process::exit(1) } @@ -361,7 +369,9 @@ fn test_command( for file in files.unwrap() { let pb = PathBuf::from(file); //if pb.is_dir() { - if let Ok(false) = visit_ucg_files(pb.as_path(), recurse, true, strict, import_paths, env) { + if let Ok(false) = + visit_ucg_files(pb.as_path(), recurse, true, strict, import_paths, env) + { ok = false; } } @@ -448,12 +458,11 @@ fn do_repl(import_paths: &Vec, strict: bool) -> std::result::Result<(), } } } - let env = std::cell::RefCell::new(build::opcode::Environment::new(StdoutWrapper::new(), StderrWrapper::new())); - let mut builder = build::FileBuilder::new( - std::env::current_dir()?, - import_paths, - &env, - ); + let env = std::cell::RefCell::new(build::opcode::Environment::new( + StdoutWrapper::new(), + StderrWrapper::new(), + )); + let mut builder = build::FileBuilder::new(std::env::current_dir()?, import_paths, &env); builder.set_strict(strict); builder.repl(editor, config_home)?; diff --git a/src/parse/mod.rs b/src/parse/mod.rs index a0f58c0..5e2282c 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -380,11 +380,14 @@ fn tuple_to_func<'a>( make_fn!( arglist, Vec>, - separated!(punct!(","), do_each!( - sym => symbol, - _ => optional!(shape_suffix), - (sym) - )) + separated!( + punct!(","), + do_each!( + sym => symbol, + _ => optional!(shape_suffix), + (sym) + ) + ) ); fn module_expression(input: SliceIter) -> Result, Expression> {