mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
MAINT: cargo fmt.
This commit is contained in:
parent
8b3552e491
commit
c3bdce74a9
@ -194,11 +194,7 @@ where
|
||||
pub fn eval_stmts(&mut self, ast: Vec<Statement>, path: Option<PathBuf>) -> 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();
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ impl<Stdout: Write + Clone, Stderr: Write + Clone> Environment<Stdout, Stderr> {
|
||||
out_lock: BTreeSet::new(),
|
||||
};
|
||||
me.populate_stdlib();
|
||||
return me
|
||||
return me;
|
||||
}
|
||||
|
||||
pub fn get_cached_path_val(&self, path: &String) -> Option<Rc<Value>> {
|
||||
|
@ -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());
|
||||
|
@ -55,19 +55,11 @@ pub struct VM {
|
||||
}
|
||||
|
||||
impl VM {
|
||||
pub fn new<P: Into<PathBuf>>(
|
||||
strict: bool,
|
||||
ops: Rc<PositionMap>,
|
||||
working_dir: P,
|
||||
) -> Self {
|
||||
pub fn new<P: Into<PathBuf>>(strict: bool, ops: Rc<PositionMap>, working_dir: P) -> Self {
|
||||
Self::with_pointer(strict, OpPointer::new(ops), working_dir)
|
||||
}
|
||||
|
||||
pub fn with_pointer<P: Into<PathBuf>>(
|
||||
strict: bool,
|
||||
ops: OpPointer,
|
||||
working_dir: P,
|
||||
) -> Self {
|
||||
pub fn with_pointer<P: Into<PathBuf>>(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<O, E>(&mut self, jp: i32, ptr: OpPointer, env: &RefCell<Environment<O, E>>) -> Result<(), Error>
|
||||
fn op_new_scope<O, E>(
|
||||
&mut self,
|
||||
jp: i32,
|
||||
ptr: OpPointer,
|
||||
env: &RefCell<Environment<O, E>>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
O: std::io::Write + Clone,
|
||||
E: std::io::Write + Clone,
|
||||
@ -507,7 +504,11 @@ impl VM {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn op_fcall<O, E>(&mut self, pos: Position, env: &RefCell<Environment<O, E>>) -> Result<(), Error>
|
||||
fn op_fcall<O, E>(
|
||||
&mut self,
|
||||
pos: Position,
|
||||
env: &RefCell<Environment<O, E>>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
O: std::io::Write + Clone,
|
||||
E: std::io::Write + Clone,
|
||||
@ -890,7 +891,11 @@ impl VM {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn op_copy<O, E>(&mut self, pos: Position, env: &RefCell<Environment<O, E>>) -> Result<(), Error>
|
||||
fn op_copy<O, E>(
|
||||
&mut self,
|
||||
pos: Position,
|
||||
env: &RefCell<Environment<O, E>>,
|
||||
) -> 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<Value>, Position), Error> {
|
||||
pub fn get_binding(&self, name: &str, pos: &Position) -> Result<(Rc<Value>, Position), Error> {
|
||||
let tpl = if name == "self" {
|
||||
self.self_stack.last().cloned()
|
||||
} else {
|
||||
@ -1194,7 +1195,12 @@ impl VM {
|
||||
})
|
||||
}
|
||||
|
||||
fn op_runtime<O, E>(&mut self, h: Hook, pos: Position, env: &RefCell<Environment<O, E>>) -> Result<(), Error>
|
||||
fn op_runtime<O, E>(
|
||||
&mut self,
|
||||
h: Hook,
|
||||
pos: Position,
|
||||
env: &RefCell<Environment<O, E>>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
O: std::io::Write + Clone,
|
||||
E: std::io::Write + Clone,
|
||||
|
@ -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::*;
|
||||
|
@ -196,9 +196,9 @@ 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;
|
||||
|
@ -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<Rc<Val>>, mut w: &mut dyn Write) -> ConvertResult {
|
||||
|
29
src/main.rs
29
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<PathBuf>, 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)?;
|
||||
|
@ -380,11 +380,14 @@ fn tuple_to_func<'a>(
|
||||
|
||||
make_fn!(
|
||||
arglist<SliceIter<Token>, Vec<Value>>,
|
||||
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<Token>) -> Result<SliceIter<Token>, Expression> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user