mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-24 18:39:50 -04:00
MAINT: cargo fmt
This commit is contained in:
parent
db9b7aef43
commit
34636a1743
@ -578,7 +578,12 @@ impl ModuleDef {
|
|||||||
let rewrite_import = |e: &mut Expression| {
|
let rewrite_import = |e: &mut Expression| {
|
||||||
let main_separator = format!("{}", std::path::MAIN_SEPARATOR);
|
let main_separator = format!("{}", std::path::MAIN_SEPARATOR);
|
||||||
if let Expression::Include(ref mut def) = e {
|
if let Expression::Include(ref mut def) = e {
|
||||||
let path = PathBuf::from(&def.path.fragment.replace("/", &main_separator).replace("\\", &main_separator));
|
let path = PathBuf::from(
|
||||||
|
&def.path
|
||||||
|
.fragment
|
||||||
|
.replace("/", &main_separator)
|
||||||
|
.replace("\\", &main_separator),
|
||||||
|
);
|
||||||
if path.is_relative() {
|
if path.is_relative() {
|
||||||
def.path.fragment = base
|
def.path.fragment = base
|
||||||
.join(path)
|
.join(path)
|
||||||
@ -589,7 +594,12 @@ impl ModuleDef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Expression::Import(ref mut def) = e {
|
if let Expression::Import(ref mut def) = e {
|
||||||
let path = PathBuf::from(&def.path.fragment.replace("/", &main_separator).replace("\\", &main_separator));
|
let path = PathBuf::from(
|
||||||
|
&def.path
|
||||||
|
.fragment
|
||||||
|
.replace("/", &main_separator)
|
||||||
|
.replace("\\", &main_separator),
|
||||||
|
);
|
||||||
// std/ paths are special and do not get made into absolute paths.
|
// std/ paths are special and do not get made into absolute paths.
|
||||||
if path.starts_with(format!("std{}", main_separator)) {
|
if path.starts_with(format!("std{}", main_separator)) {
|
||||||
return;
|
return;
|
||||||
|
@ -23,19 +23,19 @@ use std::io::Read;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use simple_error;
|
|
||||||
use rustyline;
|
use rustyline;
|
||||||
|
use simple_error;
|
||||||
|
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::error;
|
use crate::error;
|
||||||
use crate::iter::OffsetStrIter;
|
use crate::iter::OffsetStrIter;
|
||||||
use crate::parse::parse;
|
use crate::parse::parse;
|
||||||
|
|
||||||
|
use crate::build::opcode::pointer::OpPointer;
|
||||||
use crate::build::opcode::translate;
|
use crate::build::opcode::translate;
|
||||||
|
use crate::build::opcode::translate::PositionMap;
|
||||||
use crate::build::opcode::Environment;
|
use crate::build::opcode::Environment;
|
||||||
use crate::build::opcode::VM;
|
use crate::build::opcode::VM;
|
||||||
use crate::build::opcode::pointer::OpPointer;
|
|
||||||
use crate::build::opcode::translate::PositionMap;
|
|
||||||
|
|
||||||
pub mod assets;
|
pub mod assets;
|
||||||
pub mod format;
|
pub mod format;
|
||||||
@ -207,7 +207,11 @@ where
|
|||||||
println!("Type '#help' for help.");
|
println!("Type '#help' for help.");
|
||||||
println!("");
|
println!("");
|
||||||
// Initialize VM with an empty OpPointer
|
// Initialize VM with an empty OpPointer
|
||||||
let mut vm = VM::new(Rc::new(PositionMap::new()), self.environment.clone(), &self.working_dir);
|
let mut vm = VM::new(
|
||||||
|
Rc::new(PositionMap::new()),
|
||||||
|
self.environment.clone(),
|
||||||
|
&self.working_dir,
|
||||||
|
);
|
||||||
loop {
|
loop {
|
||||||
// print prompt
|
// print prompt
|
||||||
let line = editor.readline(&format!("{}> ", lines.next_line()))?;
|
let line = editor.readline(&format!("{}> ", lines.next_line()))?;
|
||||||
@ -255,8 +259,7 @@ where
|
|||||||
println!("{}", val);
|
println!("{}", val);
|
||||||
vm.last = None;
|
vm.last = None;
|
||||||
}
|
}
|
||||||
None => {
|
None => {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
editor.history_mut().add(stmt);
|
editor.history_mut().add(stmt);
|
||||||
editor.save_history(&config_home)?;
|
editor.save_history(&config_home)?;
|
||||||
|
@ -46,9 +46,7 @@ impl<'a> Entry<'a> {
|
|||||||
path: P,
|
path: P,
|
||||||
) -> Result<OpPointer, Error> {
|
) -> Result<OpPointer, Error> {
|
||||||
let cached = match self.0 {
|
let cached = match self.0 {
|
||||||
btree_map::Entry::Occupied(e) => {
|
btree_map::Entry::Occupied(e) => e.get().clone(),
|
||||||
e.get().clone()
|
|
||||||
}
|
|
||||||
btree_map::Entry::Vacant(e) => {
|
btree_map::Entry::Vacant(e) => {
|
||||||
let v = Rc::new(f()?);
|
let v = Rc::new(f()?);
|
||||||
e.insert(v.clone());
|
e.insert(v.clone());
|
||||||
|
@ -78,7 +78,9 @@ impl From<regex::Error> for Error {
|
|||||||
impl From<std::io::Error> for Error {
|
impl From<std::io::Error> for Error {
|
||||||
fn from(e: std::io::Error) -> Self {
|
fn from(e: std::io::Error) -> Self {
|
||||||
let msg = match dbg!(e.kind()) {
|
let msg = match dbg!(e.kind()) {
|
||||||
io::ErrorKind::NotFound | io::ErrorKind::Other => format!("OSError: Path not found: {}", e),
|
io::ErrorKind::NotFound | io::ErrorKind::Other => {
|
||||||
|
format!("OSError: Path not found: {}", e)
|
||||||
|
}
|
||||||
_ => format!("{}", e),
|
_ => format!("{}", e),
|
||||||
};
|
};
|
||||||
Error {
|
Error {
|
||||||
|
@ -12,11 +12,11 @@
|
|||||||
// 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::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
@ -156,7 +156,12 @@ impl Builtins {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_file_as_string<P: Into<PathBuf>>(&self, base_path: P, path: &str, pos: Position) -> Result<String, Error> {
|
fn get_file_as_string<P: Into<PathBuf>>(
|
||||||
|
&self,
|
||||||
|
base_path: P,
|
||||||
|
path: &str,
|
||||||
|
pos: Position,
|
||||||
|
) -> Result<String, Error> {
|
||||||
let sep = format!("{}", std::path::MAIN_SEPARATOR);
|
let sep = format!("{}", std::path::MAIN_SEPARATOR);
|
||||||
let raw_path = path.replace("/", &sep);
|
let raw_path = path.replace("/", &sep);
|
||||||
// FIXME(jwall): import paths?
|
// FIXME(jwall): import paths?
|
||||||
@ -186,33 +191,30 @@ impl Builtins {
|
|||||||
if let Some((val, path_pos)) = path {
|
if let Some((val, path_pos)) = path {
|
||||||
if let &Value::P(Str(ref path)) = val.as_ref() {
|
if let &Value::P(Str(ref path)) = val.as_ref() {
|
||||||
// TODO(jwall): A bit hacky we should probably change import stacks to be pathbufs.
|
// TODO(jwall): A bit hacky we should probably change import stacks to be pathbufs.
|
||||||
let normalized = decorate_error!(path_pos => self.normalize_path(base_path, false, dbg!(path)))?;
|
let normalized =
|
||||||
|
decorate_error!(path_pos => self.normalize_path(base_path, false, dbg!(path)))?;
|
||||||
// first we chack the cache
|
// first we chack the cache
|
||||||
let path = dbg!(normalized.to_string_lossy().to_string());
|
let path = dbg!(normalized.to_string_lossy().to_string());
|
||||||
if let Some(val) = env.borrow().get_cached_path_val(&path) {
|
if let Some(val) = env.borrow().get_cached_path_val(&path) {
|
||||||
stack.push((val, path_pos));
|
stack.push((val, path_pos));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if import_stack
|
if import_stack.iter().find(|p| *p == &path).is_some() {
|
||||||
.iter()
|
|
||||||
.find(|p| *p == &path)
|
|
||||||
.is_some() {
|
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
format!("Import cycle detected: {} in {:?}", path, import_stack),
|
format!("Import cycle detected: {} in {:?}", path, import_stack),
|
||||||
pos));
|
pos,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let val = {
|
let val = { env.borrow_mut().get_cached_path_val(&path) };
|
||||||
env.borrow_mut().get_cached_path_val(&path)
|
|
||||||
};
|
|
||||||
match val {
|
match val {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
stack.push((v, path_pos));
|
stack.push((v, path_pos));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let op_pointer =
|
let op_pointer = decorate_error!(path_pos => env.borrow_mut().get_ops_for_path(&normalized))?;
|
||||||
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(op_pointer, env.clone(), normalized.parent().unwrap())
|
let mut vm =
|
||||||
|
VM::with_pointer(op_pointer, env.clone(), normalized.parent().unwrap())
|
||||||
.with_import_stack(import_stack.clone());
|
.with_import_stack(import_stack.clone());
|
||||||
vm.run()?;
|
vm.run()?;
|
||||||
let result = Rc::new(vm.symbols_to_tuple(true));
|
let result = Rc::new(vm.symbols_to_tuple(true));
|
||||||
@ -265,7 +267,11 @@ impl Builtins {
|
|||||||
};
|
};
|
||||||
if typ == "str" {
|
if typ == "str" {
|
||||||
stack.push((
|
stack.push((
|
||||||
Rc::new(P(Str(self.get_file_as_string(base_path, &path, pos.clone())?))),
|
Rc::new(P(Str(self.get_file_as_string(
|
||||||
|
base_path,
|
||||||
|
&path,
|
||||||
|
pos.clone(),
|
||||||
|
)?))),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
@ -368,7 +374,8 @@ impl Builtins {
|
|||||||
if env.borrow().get_out_lock_for_path(&path) {
|
if env.borrow().get_out_lock_for_path(&path) {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
format!("You can only have one output per file"),
|
format!("You can only have one output per file"),
|
||||||
pos));
|
pos,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
env.borrow_mut().set_out_lock_for_path(path.as_ref());
|
env.borrow_mut().set_out_lock_for_path(path.as_ref());
|
||||||
Some(write_path)
|
Some(write_path)
|
||||||
@ -376,7 +383,8 @@ impl Builtins {
|
|||||||
if env.borrow().get_out_lock_for_path("/dev/stdout") {
|
if env.borrow().get_out_lock_for_path("/dev/stdout") {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
format!("You can only have one output per file"),
|
format!("You can only have one output per file"),
|
||||||
pos));
|
pos,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
env.borrow_mut().set_out_lock_for_path("/dev/stdout");
|
env.borrow_mut().set_out_lock_for_path("/dev/stdout");
|
||||||
None
|
None
|
||||||
@ -393,7 +401,7 @@ impl Builtins {
|
|||||||
Some(p) => {
|
Some(p) => {
|
||||||
let p = p.with_extension(c.file_ext());
|
let p = p.with_extension(c.file_ext());
|
||||||
Box::new(File::create(&p)?)
|
Box::new(File::create(&p)?)
|
||||||
},
|
}
|
||||||
None => Box::new(stdout),
|
None => Box::new(stdout),
|
||||||
};
|
};
|
||||||
if let Err(e) = c.convert(Rc::new(val), &mut writer) {
|
if let Err(e) = c.convert(Rc::new(val), &mut writer) {
|
||||||
@ -625,7 +633,7 @@ impl Builtins {
|
|||||||
_ => {
|
_ => {
|
||||||
result_elems.push(e.clone());
|
result_elems.push(e.clone());
|
||||||
pos_elems.push(e_pos);
|
pos_elems.push(e_pos);
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stack.push((Rc::new(C(List(result_elems, pos_elems))), pos));
|
stack.push((Rc::new(C(List(result_elems, pos_elems))), pos));
|
||||||
@ -651,7 +659,7 @@ impl Builtins {
|
|||||||
_ => {
|
_ => {
|
||||||
new_fields.push((name.clone(), val.clone()));
|
new_fields.push((name.clone(), val.clone()));
|
||||||
new_flds_pos_list.push((name_pos, val_pos));
|
new_flds_pos_list.push((name_pos, val_pos));
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stack.push((Rc::new(C(Tuple(new_fields, new_flds_pos_list))), pos));
|
stack.push((Rc::new(C(Tuple(new_fields, new_flds_pos_list))), pos));
|
||||||
|
@ -165,11 +165,7 @@ impl Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Val::Boolean(_)
|
Val::Boolean(_) | Val::Empty | Val::Float(_) | Val::Int(_) | Val::Str(_) => {
|
||||||
| Val::Empty
|
|
||||||
| Val::Float(_)
|
|
||||||
| Val::Int(_)
|
|
||||||
| Val::Str(_) => {
|
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -28,7 +28,7 @@ use std::process;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use ucglib::build;
|
use ucglib::build;
|
||||||
use ucglib::build::assets::{MemoryCache};
|
use ucglib::build::assets::MemoryCache;
|
||||||
use ucglib::convert::{ConverterRegistry, ImporterRegistry};
|
use ucglib::convert::{ConverterRegistry, ImporterRegistry};
|
||||||
use ucglib::iter::OffsetStrIter;
|
use ucglib::iter::OffsetStrIter;
|
||||||
use ucglib::parse::parse;
|
use ucglib::parse::parse;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user