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 {
|
pub fn eval_stmts(&mut self, ast: Vec<Statement>, path: Option<PathBuf>) -> BuildResult {
|
||||||
// We should probably stash this in an op_cache somewhere?
|
// We should probably stash this in an op_cache somewhere?
|
||||||
let ops = translate::AST::translate(ast, &self.working_dir);
|
let ops = translate::AST::translate(ast, &self.working_dir);
|
||||||
let mut vm = VM::new(
|
let mut vm = VM::new(self.strict, Rc::new(ops), &self.working_dir);
|
||||||
self.strict,
|
|
||||||
Rc::new(ops),
|
|
||||||
&self.working_dir,
|
|
||||||
);
|
|
||||||
if path.is_some() {
|
if path.is_some() {
|
||||||
vm.set_path(path.unwrap());
|
vm.set_path(path.unwrap());
|
||||||
}
|
}
|
||||||
@ -219,11 +215,7 @@ where
|
|||||||
println!("");
|
println!("");
|
||||||
}
|
}
|
||||||
// Initialize VM with an empty OpPointer
|
// Initialize VM with an empty OpPointer
|
||||||
let mut vm = VM::new(
|
let mut vm = VM::new(self.strict, Rc::new(PositionMap::new()), &self.working_dir);
|
||||||
self.strict,
|
|
||||||
Rc::new(PositionMap::new()),
|
|
||||||
&self.working_dir,
|
|
||||||
);
|
|
||||||
loop {
|
loop {
|
||||||
// print prompt
|
// print prompt
|
||||||
let line = match editor.readline(&format!("{}> ", lines.next_line())) {
|
let line = match editor.readline(&format!("{}> ", lines.next_line())) {
|
||||||
@ -337,11 +329,7 @@ where
|
|||||||
&mut ops_map,
|
&mut ops_map,
|
||||||
&self.working_dir,
|
&self.working_dir,
|
||||||
);
|
);
|
||||||
let mut vm = VM::new(
|
let mut vm = VM::new(self.strict, Rc::new(ops_map), &self.working_dir);
|
||||||
self.strict,
|
|
||||||
Rc::new(ops_map),
|
|
||||||
&self.working_dir,
|
|
||||||
);
|
|
||||||
if self.validate_mode {
|
if self.validate_mode {
|
||||||
vm.enable_validate_mode();
|
vm.enable_validate_mode();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ impl<Stdout: Write + Clone, Stderr: Write + Clone> Environment<Stdout, Stderr> {
|
|||||||
out_lock: BTreeSet::new(),
|
out_lock: BTreeSet::new(),
|
||||||
};
|
};
|
||||||
me.populate_stdlib();
|
me.populate_stdlib();
|
||||||
return me
|
return me;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cached_path_val(&self, path: &String) -> Option<Rc<Value>> {
|
pub fn get_cached_path_val(&self, path: &String) -> Option<Rc<Value>> {
|
||||||
|
@ -217,12 +217,9 @@ impl Builtins {
|
|||||||
None => {
|
None => {
|
||||||
let op_pointer = decorate_error!(path_pos => env.borrow_mut().get_ops_for_path(&normalized))?;
|
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?
|
// TODO(jwall): What if we don't have a base path?
|
||||||
let mut vm = VM::with_pointer(
|
let mut vm =
|
||||||
self.strict,
|
VM::with_pointer(self.strict, op_pointer, normalized.parent().unwrap())
|
||||||
op_pointer,
|
.with_import_stack(import_stack.clone());
|
||||||
normalized.parent().unwrap(),
|
|
||||||
)
|
|
||||||
.with_import_stack(import_stack.clone());
|
|
||||||
vm.run(env)?;
|
vm.run(env)?;
|
||||||
let result = Rc::new(vm.symbols_to_tuple(true));
|
let result = Rc::new(vm.symbols_to_tuple(true));
|
||||||
env.borrow_mut().update_path_val(&path, result.clone());
|
env.borrow_mut().update_path_val(&path, result.clone());
|
||||||
|
@ -55,19 +55,11 @@ pub struct VM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl VM {
|
impl VM {
|
||||||
pub fn new<P: Into<PathBuf>>(
|
pub fn new<P: Into<PathBuf>>(strict: bool, ops: Rc<PositionMap>, working_dir: P) -> Self {
|
||||||
strict: bool,
|
|
||||||
ops: Rc<PositionMap>,
|
|
||||||
working_dir: P,
|
|
||||||
) -> Self {
|
|
||||||
Self::with_pointer(strict, OpPointer::new(ops), working_dir)
|
Self::with_pointer(strict, OpPointer::new(ops), working_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_pointer<P: Into<PathBuf>>(
|
pub fn with_pointer<P: Into<PathBuf>>(strict: bool, ops: OpPointer, working_dir: P) -> Self {
|
||||||
strict: bool,
|
|
||||||
ops: OpPointer,
|
|
||||||
working_dir: P,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
working_dir: working_dir.into(),
|
working_dir: working_dir.into(),
|
||||||
stack: Vec::new(),
|
stack: Vec::new(),
|
||||||
@ -489,7 +481,12 @@ impl VM {
|
|||||||
return vm.pop();
|
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
|
where
|
||||||
O: std::io::Write + Clone,
|
O: std::io::Write + Clone,
|
||||||
E: std::io::Write + Clone,
|
E: std::io::Write + Clone,
|
||||||
@ -507,7 +504,11 @@ impl VM {
|
|||||||
Ok(())
|
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
|
where
|
||||||
O: std::io::Write + Clone,
|
O: std::io::Write + Clone,
|
||||||
E: std::io::Write + Clone,
|
E: std::io::Write + Clone,
|
||||||
@ -890,7 +891,11 @@ impl VM {
|
|||||||
Ok(())
|
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
|
where
|
||||||
O: std::io::Write + Clone,
|
O: std::io::Write + Clone,
|
||||||
E: std::io::Write + Clone,
|
E: std::io::Write + Clone,
|
||||||
@ -1074,11 +1079,7 @@ impl VM {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_binding(
|
pub fn get_binding(&self, name: &str, pos: &Position) -> Result<(Rc<Value>, Position), Error> {
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
pos: &Position,
|
|
||||||
) -> Result<(Rc<Value>, Position), Error> {
|
|
||||||
let tpl = if name == "self" {
|
let tpl = if name == "self" {
|
||||||
self.self_stack.last().cloned()
|
self.self_stack.last().cloned()
|
||||||
} else {
|
} 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
|
where
|
||||||
O: std::io::Write + Clone,
|
O: std::io::Write + Clone,
|
||||||
E: std::io::Write + Clone,
|
E: std::io::Write + Clone,
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use std;
|
use std;
|
||||||
use std::rc::Rc;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::{FileBuilder, Val};
|
use super::{FileBuilder, Val};
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
|
@ -194,11 +194,11 @@ impl Converter for ExecConverter {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod exec_test {
|
mod exec_test {
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::build::opcode::Environment;
|
||||||
use crate::build::FileBuilder;
|
use crate::build::FileBuilder;
|
||||||
use crate::convert::traits::Converter;
|
use crate::convert::traits::Converter;
|
||||||
use crate::build::opcode::Environment;
|
|
||||||
|
|
||||||
use std;
|
use std;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// Copyright 2020 Jeremy Wall
|
// Copyright 2020 Jeremy Wall
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@ -16,15 +16,15 @@ use std;
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::convert::yaml::YamlConverter;
|
|
||||||
use crate::convert::traits::{ConvertResult, Converter};
|
|
||||||
use crate::build::Val;
|
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 {
|
impl MultiYamlConverter {
|
||||||
pub fn new() -> Self {
|
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 {
|
pub fn convert_list(&self, vals: &Vec<Rc<Val>>, mut w: &mut dyn Write) -> ConvertResult {
|
||||||
@ -57,4 +57,4 @@ impl Converter for MultiYamlConverter {
|
|||||||
fn help(&self) -> String {
|
fn help(&self) -> String {
|
||||||
include_str!("yaml_help.txt").to_owned()
|
include_str!("yaml_help.txt").to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
src/main.rs
29
src/main.rs
@ -132,7 +132,7 @@ fn build_file<'a>(
|
|||||||
if file_path_buf.is_relative() {
|
if file_path_buf.is_relative() {
|
||||||
file_path_buf = std::env::current_dir()?.join(file_path_buf);
|
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);
|
builder.set_strict(strict);
|
||||||
if validate {
|
if validate {
|
||||||
builder.enable_validate_mode();
|
builder.enable_validate_mode();
|
||||||
@ -212,7 +212,8 @@ fn visit_ucg_files(
|
|||||||
let next_path = next_item.path();
|
let next_path = next_item.path();
|
||||||
let path_as_string = String::from(next_path.to_string_lossy());
|
let path_as_string = String::from(next_path.to_string_lossy());
|
||||||
if next_path.is_dir() && recurse {
|
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);
|
eprintln!("{}", e);
|
||||||
result = false;
|
result = false;
|
||||||
@ -262,7 +263,14 @@ fn build_command(
|
|||||||
let mut ok = true;
|
let mut ok = true;
|
||||||
if files.is_none() {
|
if files.is_none() {
|
||||||
let curr_dir = std::env::current_dir().unwrap();
|
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 {
|
if let Ok(false) = ok {
|
||||||
process::exit(1)
|
process::exit(1)
|
||||||
}
|
}
|
||||||
@ -361,7 +369,9 @@ fn test_command(
|
|||||||
for file in files.unwrap() {
|
for file in files.unwrap() {
|
||||||
let pb = PathBuf::from(file);
|
let pb = PathBuf::from(file);
|
||||||
//if pb.is_dir() {
|
//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;
|
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 env = std::cell::RefCell::new(build::opcode::Environment::new(
|
||||||
let mut builder = build::FileBuilder::new(
|
StdoutWrapper::new(),
|
||||||
std::env::current_dir()?,
|
StderrWrapper::new(),
|
||||||
import_paths,
|
));
|
||||||
&env,
|
let mut builder = build::FileBuilder::new(std::env::current_dir()?, import_paths, &env);
|
||||||
);
|
|
||||||
builder.set_strict(strict);
|
builder.set_strict(strict);
|
||||||
|
|
||||||
builder.repl(editor, config_home)?;
|
builder.repl(editor, config_home)?;
|
||||||
|
@ -380,11 +380,14 @@ fn tuple_to_func<'a>(
|
|||||||
|
|
||||||
make_fn!(
|
make_fn!(
|
||||||
arglist<SliceIter<Token>, Vec<Value>>,
|
arglist<SliceIter<Token>, Vec<Value>>,
|
||||||
separated!(punct!(","), do_each!(
|
separated!(
|
||||||
sym => symbol,
|
punct!(","),
|
||||||
_ => optional!(shape_suffix),
|
do_each!(
|
||||||
(sym)
|
sym => symbol,
|
||||||
))
|
_ => optional!(shape_suffix),
|
||||||
|
(sym)
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
fn module_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expression> {
|
fn module_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, Expression> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user