Commit e86aa5f3 authored by Jeff Smits's avatar Jeff Smits

Removed formatter off directives and reformatted

parent 2234ceee
......@@ -333,13 +333,19 @@ fn eval_match<'d, 'f: 'd>(
}
Op("Cons", ref children) if children.len() == 2 => {
match current.term {
::factory::Term::List(ref r) => match **r {
::factory::TermList::Cons(ref head, ref tail) => {
eval_match(context, &children[0], head)?;
eval_match(context, &children[1], &context.factory.list_term(tail.clone()))
},
::factory::TermList::Nil => Err(Error::StrategyFailed),
},
::factory::Term::List(ref r) => {
match **r {
::factory::TermList::Cons(ref head, ref tail) => {
eval_match(context, &children[0], head)?;
eval_match(
context,
&children[1],
&context.factory.list_term(tail.clone()),
)
}
::factory::TermList::Nil => Err(Error::StrategyFailed),
}
}
_ => Err(Error::StrategyFailed),
}
}
......@@ -373,7 +379,9 @@ fn eval_match<'d, 'f: 'd>(
use factory::Term::*;
match current.term {
Application(current_cons, ref current_children) => {
let current_cons = &context.factory.string(::std::string::String::from(current_cons));
let current_cons = &context.factory.string(
::std::string::String::from(current_cons),
);
eval_match(context, cons, current_cons)?;
let current_children =
&context.factory.list(current_children.into_iter().cloned());
......@@ -404,17 +412,17 @@ fn eval_match<'d, 'f: 'd>(
Cached(C(ref cache), ref term) => {
if let Option::Some(ref cached_term) = *cache.borrow() {
if cached_term == current {
return Ok(())
return Ok(());
} else {
return Err(Error::StrategyFailed)
return Err(Error::StrategyFailed);
}
}
let result = build_term::build(term, context)?;
*cache.borrow_mut() = Some(result.clone());
if result == *current {
return Ok(())
return Ok(());
} else {
return Err(Error::StrategyFailed)
return Err(Error::StrategyFailed);
}
}
}
......@@ -429,7 +437,10 @@ mod build_term {
use aterm::BrokenF32;
use aterm::{ATerm as A, ATermFactory as ATF};
pub fn build<'d, 'f: 'd>(term: &BuildTerm<'f>, context: &MutContext<'d, 'f>) -> Result<ATermRef<'f>> {
pub fn build<'d, 'f: 'd>(
term: &BuildTerm<'f>,
context: &MutContext<'d, 'f>,
) -> Result<ATermRef<'f>> {
build_with_annos(term, context, None)
}
......@@ -480,10 +491,7 @@ mod build_term {
Ok(context.factory.nil())
} else {
Ok(context.factory.with_annos(
context.factory.application(
s,
t.into_iter(),
),
context.factory.application(s, t.into_iter()),
annos.unwrap_or_default(),
))
}
......@@ -541,7 +549,7 @@ mod build_term {
}
Cached(C(ref cache), ref term) => {
if let Option::Some(ref cached_term) = *cache.borrow() {
return Ok(cached_term.clone())
return Ok(cached_term.clone());
}
let result = build_with_annos(term, context, annos)?;
*cache.borrow_mut() = Some(result.clone());
......@@ -551,7 +559,10 @@ mod build_term {
}
/// Lifts `build` over a vector
fn build_vec<'d, 'f: 'd>(context: &MutContext<'d, 'f>, vec: &[BuildTerm<'f>]) -> Result<Vec<ATermRef<'f>>> {
fn build_vec<'d, 'f: 'd>(
context: &MutContext<'d, 'f>,
vec: &[BuildTerm<'f>],
) -> Result<Vec<ATermRef<'f>>> {
vec.into_iter().map(|t| build(t, context)).collect()
}
}
......@@ -577,19 +588,14 @@ where
match current.term {
Application(name, ref r) => {
return children_fun(&*r, strat, context)
.map(|r| {
context.factory.application(name, r.iter().cloned())
})
.map(|r| context.factory.application(name, r.iter().cloned()))
.map(|t| {
context.factory.with_annos(t, annos.into_iter().cloned())
})
}
List(ref r) => {
return children_fun(
&r.iter().collect::<Vec<_>>(),
strat,
context,
).map(|r| context.factory.list(r.iter().cloned()))
return children_fun(&r.iter().collect::<Vec<_>>(), strat, context)
.map(|r| context.factory.list(r.iter().cloned()))
.map(|t| {
context.factory.with_annos(t, annos.into_iter().cloned())
})
......
......@@ -40,26 +40,28 @@ pub fn read_lib<'f>(
}
#[cfg_attr(rustfmt, rustfmt_skip)]
pub fn find_str_path(str_path: Option<String>) -> PathBuf {
use std::env;
use std::process::Command;
str_path
.or_else(||
env::var_os("STRDIR")
.map(|s|
s.into_string().expect("STRDIR found in environment, but was not valid \
unicode. Bailing out. ")))
.or_else(|| {
env::var_os("STRDIR").map(|s| {
s.into_string().expect(
"STRDIR found in environment, but was not valid \
unicode. Bailing out. ",
)
})
})
.and_then(|s| if s.is_empty() { None } else { Some(s) })
.or_else(||
Command::new("strategoxt-path")
.output()
.ok()
.map(|o|
String::from_utf8(o.stdout)
.expect("strategoxt-path successfully executed but the output was not \
valid unicode. Bailing out. ")))
.or_else(|| {
Command::new("strategoxt-path").output().ok().map(|o| {
String::from_utf8(o.stdout).expect(
"strategoxt-path successfully executed but the output was not \
valid unicode. Bailing out. ",
)
})
})
.and_then(|s| {
let mut p = PathBuf::from(s);
// pop once to drop the file name, pop again to go to the parent dir
......
......@@ -59,20 +59,22 @@ struct Opt {
args: Vec<String>,
}
#[cfg_attr(rustfmt, rustfmt_skip)]
fn main() {
let opt = Opt::from_args();
let str_path = io::find_str_path(opt.str_path);
// TODO: support command line arguments in opt.args
match exec(opt.program, str_path, opt.libraries, opt.stack_space) {
Err(TracedError(Error::InterpreterExit(i),_)) => { process::exit(i) },
Err(TracedError(Error::StrategyFailed,_)) => { process::exit(1) },
Err(TracedError(e,st)) => {
Err(TracedError(Error::InterpreterExit(i), _)) => process::exit(i),
Err(TracedError(Error::StrategyFailed, _)) => process::exit(1),
Err(TracedError(e, st)) => {
println!("Stacktrace:\n{}", st);
println!("{:?}", e);
process::exit(1)
},
Ok(result) => { println!("{}", result); process::exit(0) },
}
Ok(result) => {
println!("{}", result);
process::exit(0)
}
}
}
......
......@@ -399,7 +399,7 @@ impl<'a> TryFrom<ctree::Term<'a>> for (BuildTerm<'a>, SizeEstimate) {
P::Op("Nil", ref r) if r.is_empty() => {
let (pt, est) = (*term).try_into()?;
Ok((pt, est.map(|u| u + 1)))
},
}
_ => {
let (bt1, est1) = (*term).try_into()?;
let (bt2, est2) = (*annos).try_into()?;
......@@ -436,7 +436,8 @@ impl<'a> TryFrom<ctree::PreTerm<'a>> for (BuildTerm<'a>, SizeEstimate) {
I::Str(s) => Ok((O::Str(s), Some(1))),
I::Op(cons, children) |
I::OpQ(cons, children) => {
let (children, est): (Vec<_>, Vec<SizeEstimate>) = try_into_vec(children)?.into_iter().unzip();
let (children, est): (Vec<_>, Vec<SizeEstimate>) =
try_into_vec(children)?.into_iter().unzip();
let est = est.into_iter().fold(Some(1), add_estimates);
Ok((O::Op(cons, children), est))
}
......@@ -477,7 +478,7 @@ impl<'a> TryFrom<ctree::Term<'a>> for MatchTerm<'a> {
let (mt, est) = mtf(value.clone())?;
if est.is_some() && est.unwrap() > MATCH_CACHED_THRESHOLD {
if let Ok((bt, _)) = btf(value) {
return Ok(MatchTerm::Cached(C::new(), Box::new(bt)))
return Ok(MatchTerm::Cached(C::new(), Box::new(bt)));
}
}
Ok(mt)
......@@ -535,7 +536,8 @@ impl<'a> TryFrom<ctree::PreTerm<'a>> for (MatchTerm<'a>, SizeEstimate) {
I::Str(s) => Ok((O::Str(s), Some(1))),
I::Op(cons, children) |
I::OpQ(cons, children) => {
let (children, est): (Vec<_>, Vec<SizeEstimate>) = try_into_vec(children)?.into_iter().unzip();
let (children, est): (Vec<_>, Vec<SizeEstimate>) =
try_into_vec(children)?.into_iter().unzip();
let est = est.into_iter().fold(Some(1), add_estimates);
Ok((O::Op(cons, children), est))
}
......
......@@ -304,14 +304,16 @@ pub fn S_ISDIR<'d, 'f: 'd>(
}
}
#[cfg_attr(rustfmt, rustfmt_skip)]
pub fn fputs<'d, 'f : 'd>(context: &MutContext<'d, 'f>,
sargs: &[StrategyDef<'d, 'f>],
targs: &[ATermRef<'f>],
current: ATermRef<'f>)
-> Result<ATermRef<'f>> {
pub fn fputs<'d, 'f: 'd>(
context: &MutContext<'d, 'f>,
sargs: &[StrategyDef<'d, 'f>],
targs: &[ATermRef<'f>],
current: ATermRef<'f>,
) -> Result<ATermRef<'f>> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive fputs called with wrong argument count"));
return Err(Error::UnknownBehaviour(
"Primitive fputs called with wrong argument count",
));
}
let string = targs[0].get_string().ok_or(Error::StrategyFailed)?;
let fd = targs[1].get_int().ok_or(Error::StrategyFailed)?;
......@@ -329,14 +331,16 @@ pub fn fputs<'d, 'f : 'd>(context: &MutContext<'d, 'f>,
}
}
#[cfg_attr(rustfmt, rustfmt_skip)]
pub fn fputc<'d, 'f : 'd>(context: &MutContext<'d, 'f>,
sargs: &[StrategyDef<'d, 'f>],
targs: &[ATermRef<'f>],
current: ATermRef<'f>)
-> Result<ATermRef<'f>> {
pub fn fputc<'d, 'f: 'd>(
context: &MutContext<'d, 'f>,
sargs: &[StrategyDef<'d, 'f>],
targs: &[ATermRef<'f>],
current: ATermRef<'f>,
) -> Result<ATermRef<'f>> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive fputc called with wrong argument count"));
return Err(Error::UnknownBehaviour(
"Primitive fputc called with wrong argument count",
));
}
let char = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let fd = targs[1].get_int().ok_or(Error::StrategyFailed)?;
......@@ -789,10 +793,7 @@ pub fn copy<'d, 'f: 'd>(
let output_file = targs[1].get_string();
if let (Some(input_file), Some(output_file)) = (input_file, output_file) {
let input_path = ssl_state.sys.cwd_with_file_name(input_file).canonicalize();
let output_path = ssl_state
.sys
.cwd_with_file_name(output_file)
.canonicalize();
let output_path = ssl_state.sys.cwd_with_file_name(output_file).canonicalize();
if let (Ok(ref ip), Ok(ref op)) = (input_path, output_path) {
if ip == op {
let _ = fs::copy(ip, op).map_err(|_| Error::StrategyFailed)?;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment