Commit be22f84a authored by Jeff Smits's avatar Jeff Smits

cargo clippy && cargo fmt

parent 6151fbfa
......@@ -10,7 +10,7 @@ use std::borrow::Borrow;
use std::cell::RefCell;
// TODO: do AOS to SOA transform for scopes, (to the level of individual variables? Maybe ).
/// This context is internally mutable in RefCell fields. This is just for convenience as we don't
/// This context is internally mutable in `RefCell` fields. This is just for convenience as we don't
/// want to pass around the mutable fields separately. But the internal mutability is not a hidden
/// thing without effect, so the name of the context includes `Mut`.
pub struct MutContext<'a> {
......@@ -47,7 +47,9 @@ impl<'a> MutContext<'a> {
.cloned() // ATermRef should be very cheap to clone
.next()
.ok_or_else(|| Error::UndefinedPrimitive(prim_name.to_owned()))?;
self.stack_tracer.borrow_mut().push(prim_name.to_owned());
self.stack_tracer
.borrow_mut()
.push(prim_name.to_owned());
let result = eval_prim_ref(prim_ref, self, sargs, targs, current);
if result.is_ok() {
self.stack_tracer.borrow_mut().pop_on_success();
......@@ -66,7 +68,7 @@ impl<'a> MutContext<'a> {
.flat_map(|scope| scope.strategy.get(strat_name))
.cloned() // >:(
.next()
.ok_or(Error::UndefinedStrategy(strat_name.to_owned()))
.ok_or_else(|| Error::UndefinedStrategy(strat_name.to_owned()))
}
fn get_term_option(&self, term_name: &str) -> Result<Option<ATermRef>> {
......@@ -77,11 +79,12 @@ impl<'a> MutContext<'a> {
.flat_map(|scope| scope.term.get(term_name))
.cloned()
.next()
.ok_or(Error::UndefinedVariable(term_name.to_owned()))
.ok_or_else(|| Error::UndefinedVariable(term_name.to_owned()))
}
pub fn get_term(&self, term_name: &str) -> Result<ATermRef> {
self.get_term_option(term_name).and_then(|o| o.ok_or(Error::UninitializedVariable))
self.get_term_option(term_name)
.and_then(|o| o.ok_or(Error::UninitializedVariable))
}
pub fn match_term(&self, term_name: &str, current: &ATermRef) -> Result<()> {
......@@ -89,27 +92,32 @@ impl<'a> MutContext<'a> {
match term {
Some(term) => {
if Borrow::<ATerm>::borrow(&term) == current.borrow() {
return Ok(())
return Ok(());
} else {
return Err(Error::StrategyFailed)
return Err(Error::StrategyFailed);
}
}
None => {
for mut scope in self.scopes.borrow_mut().iter_mut().rev() {
if scope.overlay || scope.term.contains_key(term_name) {
if let Some(Some(t)) = scope.term.insert(term_name.to_owned(), Some(current.clone())) {
unreachable!(
format!("match_term: No scope had {}, but we just replaced {} when \
we added it?!", term_name, t))
if let Some(Some(t)) =
scope
.term
.insert(term_name.to_owned(), Some(current.clone())) {
unreachable!(format!("match_term: No scope had {}, but we just \
replaced {} when we added it?!",
term_name,
t))
} else {
return Ok(())
return Ok(());
}
}
}
}
}
unreachable!(format!("match_term: First we could find {} unbound, then we couldn't \
anymore?!", term_name))
anymore?!",
term_name))
}
pub fn push_scope(&self, scope: Scope<ATermRef>) {
......@@ -118,10 +126,12 @@ impl<'a> MutContext<'a> {
pub fn apply_overlay(&self) {
let mut scopes = self.scopes.borrow_mut();
let overlay = scopes.pop().expect("apply_overlay: scopes stack unexpectedly empty");
let overlay = scopes
.pop()
.expect("apply_overlay: scopes stack unexpectedly empty");
if !overlay.overlay {
unreachable!("apply_overlay: Interpreter bug, scopes stack did not contain an overlay \
at the top")
at the top")
}
}
......@@ -152,7 +162,7 @@ impl StackTracer {
self.current_depth = self.stack.len();
}
pub fn stack<'a>(&'a self) -> ::std::slice::Iter<'a, String> {
pub fn stack(&self) -> ::std::slice::Iter<String> {
self.stack.iter()
}
}
......@@ -160,7 +170,7 @@ impl StackTracer {
impl fmt::Display for StackTracer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (n, name) in self.stack.iter().enumerate() {
if n+1 == self.current_depth {
if n + 1 == self.current_depth {
writeln!(f, "{} <==", name)?;
} else {
writeln!(f, "{}", name)?;
......@@ -178,24 +188,23 @@ pub struct Scope<ATerm> {
}
impl<ATerm> Scope<ATerm> {
pub fn new<IA, IS>(terms:IA, defs: IS) -> Scope<ATerm>
where IA: IntoIterator<Item=(String,ATerm)>,
IS: IntoIterator<Item=(String,StrategyDef)>
pub fn new<IA, IS>(terms: IA, defs: IS) -> Scope<ATerm>
where IA: IntoIterator<Item = (String, ATerm)>,
IS: IntoIterator<Item = (String, StrategyDef)>
{
Scope {
term: terms.into_iter().map(|(n,a)| (n,Some(a))).collect(),
term: terms.into_iter().map(|(n, a)| (n, Some(a))).collect(),
strategy: defs.into_iter().collect(),
overlay: false,
}
}
pub fn from_defs<I>(defs: I) -> Scope<ATerm>
where I: IntoIterator<Item =StrategyDef>
where I: IntoIterator<Item = StrategyDef>
{
Scope {
term: HashMap::default(),
strategy: defs
.into_iter()
strategy: defs.into_iter()
.map(|sdeft| (sdeft.name(), sdeft))
.collect(),
overlay: false,
......
......@@ -259,13 +259,10 @@ impl<'a, A> TryFrom<&'a A> for ConstType
fn try_from(value: &'a A) -> Result<Self, Self::Err> {
if let a::Term::Application(ref c, ref r) = value.as_inner().term {
match c.borrow() {
"ConstType" => {
if r.len() == 1 {
return match_(&r[0]).map(ConstType);
}
if let "ConstType" = c.borrow() {
if r.len() == 1 {
return match_(&r[0]).map(ConstType);
}
_ => {}
}
}
Err(Error::CTreeParse("ConstType"))
......@@ -378,14 +375,11 @@ impl<'a, A> TryFrom<&'a A> for SVar
fn try_from(value: &'a A) -> Result<Self, Self::Err> {
if let a::Term::Application(ref c, ref r) = value.as_inner().term {
match c.borrow() {
"SVar" => {
let r = r;
if r.len() == 1 {
return match_string(&r[0]).map(SVar);
}
if let "SVar" = c.borrow() {
let r = r;
if r.len() == 1 {
return match_string(&r[0]).map(SVar);
}
_ => {}
}
}
Err(Error::CTreeParse("SVar"))
......@@ -512,14 +506,11 @@ impl<'a, A> TryFrom<&'a A> for VarDec
fn try_from(value: &'a A) -> Result<Self, Self::Err> {
if let a::Term::Application(ref c, ref r) = value.as_inner().term {
match c.borrow() {
"VarDec" => {
if r.len() == 2 {
let str = match_string(&r[0])?;
return match_(&r[1]).map(|ty| VarDec(str, ty));
}
if let "VarDec" = c.borrow() {
if r.len() == 2 {
let str = match_string(&r[0])?;
return match_(&r[1]).map(|ty| VarDec(str, ty));
}
_ => {}
}
}
Err(Error::CTreeParse("TypedId"))
......@@ -684,14 +675,11 @@ impl<'a, A> TryFrom<&'a A> for Var
fn try_from(value: &'a A) -> Result<Self, Self::Err> {
if let a::Term::Application(ref c, ref r) = value.as_inner().term {
match c.borrow() {
"Var" => {
let r = r;
if r.len() == 1 {
return match_string(&r[0]).map(Var);
}
if let "Var" = c.borrow() {
let r = r;
if r.len() == 1 {
return match_string(&r[0]).map(Var);
}
_ => {}
}
}
Err(Error::CTreeParse("Var"))
......@@ -870,7 +858,7 @@ fn match_<'a, A, R, T>(r: &'a R) -> Result<T, Error>
A: 'a + ATerm<Rec = R>,
R: Borrow<A>
{
return r.borrow().try_into();
r.borrow().try_into()
}
// This function seems more complicated than necessary... Not sure how to simplify though
......@@ -883,7 +871,7 @@ pub fn string_unescape(string: &str) -> String {
if copy {
result.push_str(chunk);
copy = false;
} else if chunk.len() == 0 {
} else if chunk.is_empty() {
// if not copy, then an empty chunk represents two consecutive backslashes
result.push('\\');
// The chunk after doesn't need special handling
......
......@@ -44,13 +44,13 @@ impl<'t> error::Error for Error {
Error::Io(ref err) => err.cause(),
Error::Fmt(ref err) => err.cause(),
Error::ATermParse(ref err) => err.cause(),
Error::CTreeParse(_) => None,
Error::UndefinedStrategy(_) => None,
Error::UndefinedVariable(_) => None,
Error::UndefinedPrimitive(_) => None,
Error::UninitializedVariable => None,
Error::StrategyFailed => None,
Error::UnknownBehaviour(_) => None,
Error::CTreeParse(_) |
Error::UndefinedStrategy(_) |
Error::UndefinedVariable(_) |
Error::UndefinedPrimitive(_) |
Error::UninitializedVariable |
Error::StrategyFailed |
Error::UnknownBehaviour(_) |
Error::InterpreterExit(_) => None,
}
}
......@@ -62,13 +62,13 @@ impl<'t> fmt::Display for Error {
Error::Io(ref err) => err.fmt(f),
Error::Fmt(ref err) => err.fmt(f),
Error::ATermParse(ref err) => err.fmt(f),
Error::CTreeParse(ref s) => write!(f, "CTreeParseError in {}", s),
Error::CTreeParse(s) => write!(f, "CTreeParseError in {}", s),
Error::UndefinedStrategy(ref s) => write!(f, "UndefinedStrategyError: {}", s),
Error::UndefinedVariable(ref s) => write!(f, "UndefinedVariableError: {}", s),
Error::UndefinedPrimitive(ref s) => write!(f, "UndefinedPrimitiveError: {}", s),
Error::UninitializedVariable => write!(f, "Uninitialized variable"),
Error::StrategyFailed => write!(f, "Strategy failed"),
Error::UnknownBehaviour(ref s) => write!(f, "Unknown behaviour for {}", s),
Error::UnknownBehaviour(s) => write!(f, "Unknown behaviour for {}", s),
Error::InterpreterExit(i) => write!(f, "Interpreter exited with code {}", i),
}
}
......
......@@ -15,7 +15,7 @@ use std::rc::Rc;
use std::borrow::Borrow;
pub type HashTable = LinkedHashMap<ATermRef, ATermRef>;
#[derive(Debug, PartialEq, Eq, Clone, Default)]
#[derive(Debug, Eq, Clone, Default)]
pub struct IndexedSet(HashMap<ATermRef, u16>, u16);
impl IndexedSet {
......@@ -38,7 +38,7 @@ impl IndexedSet {
pub fn insert(&mut self, key: ATermRef) -> u16 {
self.1 += 1;
let _ = self.0.insert(key, self.1);
return self.1;
self.1
}
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<u16>
......@@ -53,9 +53,15 @@ impl IndexedSet {
}
}
impl PartialEq for IndexedSet {
fn eq(&self, other: &IndexedSet) -> bool {
self.0.eq(&other.0)
}
}
impl Hash for IndexedSet {
fn hash<H: Hasher>(&self, state: &mut H) {
for t in self.0.iter() {
for t in &self.0 {
t.hash(state);
}
}
......@@ -67,20 +73,22 @@ pub enum Blob {
IndexedSet(Rc<RefCell<IndexedSet>>),
}
/// This is an evil Hash implementation that will just go through the RefCell. Since the RefCell is
/// mutable inside, this will really mess things up if you use a Blob in a place where hashing is
/// used. This situation is similar to the one with `aterm::Term::Real`.
/// This is an evil `Hash` implementation that will just go through the `RefCell`. Since the
/// `RefCell` is mutable inside, this will really mess things up if you use a `Blob` in a place
/// where hashing is used. This situation is similar to the one with `aterm::Term::Real`.
#[allow(unknown_lints)]
#[allow(derive_hash_xor_eq)]
impl Hash for Blob {
fn hash<H: Hasher>(&self, state: &mut H) {
match *self {
Blob::HashTable(ref htrc) => {
let htrc: &RefCell<HashTable> = htrc.borrow();
htrc.borrow().hash(state)
},
}
Blob::IndexedSet(ref isrc) => {
let isrc: &RefCell<IndexedSet> = isrc.borrow();
isrc.borrow().hash(state)
},
}
}
}
}
......
This diff is collapsed.
......@@ -21,13 +21,13 @@ pub fn read_input<P: AsRef<Path>>(path: &P) -> io::Result<String> {
Ok(ctree)
}
pub fn read_aterm<'a, P: AsRef<Path>>(f: &ATermFactory, path: &P) -> Result<ATermRef> {
pub fn read_aterm<P: AsRef<Path>>(f: &ATermFactory, path: &P) -> Result<ATermRef> {
let file_contents = read_input(path)?;
let (aterm, _) = f.read_ascii(&file_contents)?;
Ok(aterm)
}
pub fn read_lib<'a>(f: &ATermFactory,
pub fn read_lib(f: &ATermFactory,
str_path: &Path,
path: &str)
-> Result<(ATermRef, Option<&'static Primitives>)> {
......@@ -49,7 +49,7 @@ pub fn find_str_path(str_path: Option<String>) -> PathBuf {
env::var_os("STRDIR")
.map(|s|
s.into_string().expect("STRDIR found in environment, but was not valid \
unicode. Bailing out. ")))
unicode. Bailing out. ")))
.and_then(|s| if s.is_empty() { None } else { Some(s) })
.or_else(||
Command::new("strategoxt-path")
......@@ -57,9 +57,8 @@ pub fn find_str_path(str_path: Option<String>) -> PathBuf {
.ok()
.map(|o|
String::from_utf8(o.stdout)
.ok()
.expect("strategoxt-path successfully executed but the output was not valid \
unicode. Bailing out. ")))
.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
......@@ -70,5 +69,5 @@ pub fn find_str_path(str_path: Option<String>) -> PathBuf {
}
})
.map(PathBuf::from)
.unwrap_or(PathBuf::from("."))
}
\ No newline at end of file
.unwrap_or_else(|| PathBuf::from("."))
}
extern crate structopt;
#[macro_use]
extern crate structopt_derive;
extern crate aterm;
extern crate try_from;
extern crate phf;
......@@ -15,4 +12,4 @@ pub mod interpreter;
mod ctree;
mod context;
mod preprocess;
mod primitives;
\ No newline at end of file
mod primitives;
......@@ -17,9 +17,8 @@ use std::result;
use aterm::print::ATermWrite;
use error::{Result, Error};
use factory::{ATermFactory, ATermRef};
use factory::ATermFactory;
use interpreter::{interpret_main, TracedError};
use primitives::Primitives;
mod io;
mod error;
......@@ -83,7 +82,11 @@ fn main() {
}
}
fn exec(program_path: String, str_path: PathBuf, library_paths: Vec<String>, stack_space: usize) -> result::Result<String, TracedError> {
fn exec(program_path: String,
str_path: PathBuf,
library_paths: Vec<String>,
stack_space: usize)
-> result::Result<String, TracedError> {
use std::thread;
thread::Builder::new()
.name("Main execution thread".into())
......
......@@ -22,7 +22,7 @@ macro_rules! eprintln {
pub fn preprocess(program: ctree::Module) -> Result<Scope<ATermRef>> {
let decls = match program {
ctree::Module::Module(_, decls) => decls,
ctree::Module::Module(_, decls) |
ctree::Module::Specification(decls) => decls,
};
let defs = decls
......@@ -62,7 +62,12 @@ impl StrategyDef {
current: ATermRef)
-> Result<ATermRef> {
match *self {
StrategyDef::Predefined{ref name, ref sargs, ref targs, ref body} => {
StrategyDef::Predefined {
ref name,
ref sargs,
ref targs,
ref body,
} => {
if actual_sargs.len() != sargs.len() || actual_targs.len() != targs.len() {
Err(Error::UndefinedStrategy(name.clone()))
} else {
......@@ -79,7 +84,11 @@ impl StrategyDef {
result
}
}
StrategyDef::Anonymous {ref body, no_of_scopes, ..} => {
StrategyDef::Anonymous {
ref body,
no_of_scopes,
..
} => {
let name = self.name();
if !(actual_sargs.is_empty() && actual_targs.is_empty()) {
Err(Error::UndefinedStrategy(name))
......@@ -87,7 +96,10 @@ impl StrategyDef {
context.stack_tracer.borrow_mut().push(name);
let popped_scopes = context.scopes.borrow_mut().split_off(no_of_scopes);
let result = body.eval(context, current);
context.scopes.borrow_mut().extend_from_slice(&popped_scopes);
context
.scopes
.borrow_mut()
.extend_from_slice(&popped_scopes);
if result.is_ok() {
context.stack_tracer.borrow_mut().pop_on_success();
} else {
......@@ -99,27 +111,38 @@ impl StrategyDef {
}
}
pub fn from_strategy(context: &MutContext, name: String, number: usize, body: Strategy, no_of_scopes: usize) -> Result<Self> {
pub fn from_strategy(context: &MutContext,
name: String,
number: usize,
body: Strategy,
no_of_scopes: usize)
-> Result<Self> {
// NOTE: this is not an optimisation but a necessary semantic distinction to allow
// strategies that take arguments to be passed as strategy arguments!
match body {
Strategy::CallT(ref name, ref sargs, ref targs)
if sargs.is_empty() && targs.is_empty() =>
context.get_strategy(name),
_ => Ok(StrategyDef::Anonymous {
argument_of: name,
argument_no: number,
body: body,
no_of_scopes: no_of_scopes,
}),
Strategy::CallT(ref name, ref sargs, ref targs) if sargs.is_empty() &&
targs.is_empty() => {
context.get_strategy(name)
}
_ => {
Ok(StrategyDef::Anonymous {
argument_of: name,
argument_no: number,
body: body,
no_of_scopes: no_of_scopes,
})
}
}
}
pub fn name(&self) -> String {
match *self {
StrategyDef::Predefined { ref name, .. } => name.clone(),
StrategyDef::Anonymous { ref argument_of, ref argument_no, .. } =>
format!("{}.{}", argument_of, argument_no),
StrategyDef::Anonymous {
ref argument_of,
ref argument_no,
..
} => format!("{}.{}", argument_of, argument_no),
}
}
}
......@@ -149,7 +172,7 @@ impl TryFrom<ctree::Def> for StrategyDef {
// libstratego-lib already has some of these, so this warning will be shown by
// default. That makes it a warning people will learn to ignore, so why show it
// at all..
// eprintln!("WARNING: ignoring annotations on strategy definitions");
// eprintln!("WARNING: ignoring annotations on strategy definitions");
// TODO: support single annotations like in java-backend/trans/s2j.str
Self::try_from(sdeft.into())
}
......@@ -198,7 +221,7 @@ impl TryFrom<ctree::Strategy> for Strategy {
let sterm: BuildTerm = sterm.try_into()?;
let var_name = match sterm {
BuildTerm::Var(n) => Ok(n),
_ => Err(Error::CTreeParse("Non-variable in CallDynamic name position"))
_ => Err(Error::CTreeParse("Non-variable in CallDynamic name position")),
}?;
let targs = try_into_vec(targs)?;
try_into_vec(sargs).map(|sargs| O::CallDynamic(var_name, sargs, targs))
......@@ -307,25 +330,25 @@ impl BuildTerm {
Var(ref s) => context.get_term(s),
Int(i) => {
Ok(context
.factory
.with_annos(context.factory.t_int(i), annos))
.factory
.with_annos(context.factory.t_int(i), annos))
}
Real(BrokenF32(f)) => {
Ok(context
.factory
.with_annos(context.factory.t_real(f), annos))
.factory
.with_annos(context.factory.t_real(f), annos))
}
Str(ref s) => {
Ok(context
.factory
.with_annos(context.factory.t_string(s.clone()), annos))
.factory
.with_annos(context.factory.t_string(s.clone()), annos))
}
Op(ref s, ref t) => {
let t = Self::build_vec(context, t)?;
Ok(context
.factory
.with_annos(context.factory.t_application(s.clone(), t.into_iter()),
annos))
.factory
.with_annos(context.factory.t_application(s.clone(), t.into_iter()),
annos))
}
Explode(ref cons, ref children) => {
use aterm::Term::*;
......@@ -347,10 +370,12 @@ impl BuildTerm {
return Ok(context.factory.with_annos(application, annos));
}
// According to STR-626 non-string constructor term implosion should fail
// Which the STR/J does when interpreting, but the compiled version just does the
// same as the List case: give back the children
// Which the STR/J does when interpreting, but the compiled version just does
// the same as the List case: give back the children
Application(_, _) |
List(_) => return Ok(to_cons_nil_list(context.factory, children.iter().cloned())),
List(_) => {
return Ok(to_cons_nil_list(context.factory, children.iter().cloned()))
}
Blob(_) | Placeholder(_) => {
return Err(Error::UnknownBehaviour("Blob or ATerm placeholder in build of \
explode pattern (#) first argument"))
......@@ -375,12 +400,8 @@ impl BuildTerm {
}
/// Lifts `build` over a vector
fn build_vec<'a>(context: &MutContext<'a>,
vec: &Vec<BuildTerm>)
-> Result<Vec<ATermRef>> {
vec.into_iter()
.map(|t| t.build(context))
.collect()
fn build_vec<'a>(context: &MutContext<'a>, vec: &[BuildTerm]) -> Result<Vec<ATermRef>> {
vec.into_iter().map(|t| t.build(context)).collect()
}
/// Takes a `BuildTerm` and tries to find `Op("Cons", ...)` and `Op("Nil",[])` to build
......@@ -402,6 +423,7 @@ impl BuildTerm {
Ok(None)
}
#[allow(dead_code)]
pub fn build_static(&self, f: &ATermFactory) -> Result<ATermRef> {
use context::StackTracer;
use primitives::ssl::State;
......@@ -497,6 +519,8 @@ fn try_into_vec<T1, T2: TryFrom<T1>>(v: Vec<T1>)
.collect::<result::Result<Vec<_>, _>>()
}
#[allow(unknown_lints)]
#[allow(boxed_local)]
fn try_into_box<T1, T2: TryFrom<T1>>(v: Box<T1>)
-> result::Result<Box<T2>, <T2 as TryFrom<T1>>::Err> {
(*v).try_into().map(Box::new)
......
......@@ -116,9 +116,7 @@ pub fn hashtable_put<'a>(context: &MutContext<'a>,
let table: &RefCell<HashTable> = table.borrow();
let _ = table
.borrow_mut()
.insert(key, value);
let _ = table.borrow_mut().insert(key, value);
Ok(targs[0].clone())
}
......@@ -141,9 +139,7 @@ pub fn hashtable_remove<'a>(context: &MutContext<'a>,
let table: &RefCell<HashTable> = table.borrow();
let _ = table
.borrow_mut()
.remove(&targs[1]);
let _ = table.borrow_mut().remove(&targs[1]);
Ok(targs[0].clone())
}
......@@ -194,7 +190,7 @@ pub fn hashtable_keys<'a>(context: &MutContext<'a>,
let table: &RefCell<HashTable> = table.borrow();
let result = to_cons_nil_list(&context.factory, table.borrow().keys().cloned());
let result = to_cons_nil_list(context.factory, table.borrow().keys().cloned());
Ok(result)
}
......
......@@ -50,7 +50,7 @@ pub fn indexedSet_reset<'a>(context: &MutContext<'a>,
.and_then(TryInto::try_into)
.map_err(|_| Error::StrategyFailed)?;
let mut set: &RefCell<IndexedSet> = set.borrow();
let set: &RefCell<IndexedSet> = set.borrow();
set.borrow_mut().clear();
Ok(current)
......@@ -162,6 +162,6 @@ pub fn indexedSet_elements<'a>(context: &MutContext<'a>,
let set: &RefCell<IndexedSet> = set.borrow();
let keys: Vec<_> = set.borrow().keys().cloned().collect();
let result = to_cons_nil_list(&context.factory, keys.into_iter());
let result = to_cons_nil_list(context.factory, keys.into_iter());
Ok(result)
}
......@@ -15,6 +15,8 @@ pub struct State {
}
impl State {
#[allow(unknown_lints)]
#[allow(new_without_default)]
pub fn new() -> Self {
State {
string: StringState::new(),
......
......@@ -11,7 +11,7 @@ pub fn stacktrace_get_all_frame_names<'a>(context: &MutContext<'a>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
Ok(to_cons_nil_list(&context.factory,
Ok(to_cons_nil_list(context.factory,
context
.stack_tracer
.borrow()
......
......@@ -26,7 +26,7 @@ pub struct StringState {
impl StringState {
pub fn new() -> Self {
StringState {
new_alphacounter: 'a' as u8,
new_alphacounter: b'a',
new_counter: 0,
newname_counters: HashMap::new(),
}
......@@ -170,8 +170,8 @@ pub fn new<'a>(context: &MutContext<'a>,
-> Result<ATermRef> {
let mut ssl_state = context.ssl_state.borrow_mut();
ssl_state.string.new_alphacounter += 1;
if ssl_state.string.new_alphacounter > ('z' as u8) {
ssl_state.string.new_alphacounter = 'a' as u8;
if ssl_state.string.new_alphacounter > (b'z') {
ssl_state.string.new_alphacounter = b'a';
if ssl_state.string.new_counter == u16::max_value() {
panic!("new (SSL): Generated 26 * {} unique names, no idea what to generate any more!",
u16::max_value());
......
......@@ -56,37 +56,27 @@ impl SysState {
pub fn get_writer<'a>(&'a mut self, fd: i32) -> Result<Box<Write + 'a>> {
if fd <= STDIN as i32 {
Err(Error::StrategyFailed)
} else if fd == STDOUT as i32 {
Ok(Box::new(io::BufWriter::new(io::stdout())))
} else if fd == STDERR as i32 {
} else if fd == STDOUT as i32 || fd == STDERR as i32 {
Ok(Box::new(io::BufWriter::new(io::stderr())))
} else {
} else if let Some(ref file) = self.open_files[fd as usize - 3] {
// -3 because of the reserved STDIN/OUT/ERR
if let Some(ref file) = self.open_files[fd as usize - 3] {
Ok(Box::new(io::BufWriter::new(file)) as Box<Write>)
} else {
Err(Error::StrategyFailed)
}
Ok(Box::new(io::BufWriter::new(file)) as Box<Write>)
} else {