fix a lot of warnings

This commit is contained in:
Daniella / Tove 2023-02-19 02:14:01 +01:00
parent d2d533642a
commit 07264a5f67
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
4 changed files with 67 additions and 51 deletions

View file

@ -141,14 +141,14 @@ pub fn dyn_call(stack: &mut Stack) -> OError {
};
let mut words = Vec::new();
let mut ra = 0;
while s.starts_with("&") {
while s.starts_with('&') {
ra += 1;
s = s[1..].to_owned();
}
if s.ends_with(";") {
if s.ends_with(';') {
words.push(Word::Call(s[..s.len() - 1].to_owned(), true, ra));
} else {
words.push(Word::Call(s.to_owned(), false, ra));
words.push(Word::Call(s, false, ra));
}
Words { words }.exec(stack)?;
Ok(())
@ -160,14 +160,14 @@ pub fn dyn_objcall(stack: &mut Stack) -> OError {
};
let mut words = Vec::new();
let mut ra = 0;
while s.starts_with("&") {
while s.starts_with('&') {
ra += 1;
s = s[1..].to_owned();
}
if s.ends_with(";") {
if s.ends_with(';') {
words.push(Word::ObjCall(s[..s.len() - 1].to_owned(), true, ra));
} else {
words.push(Word::ObjCall(s.to_owned(), false, ra));
words.push(Word::ObjCall(s, false, ra));
}
Words { words }.exec(stack)?;
Ok(())
@ -240,7 +240,8 @@ pub fn dyn_readf(stack: &mut Stack) -> OError {
}
pub fn register(r: &mut Stack, o: Arc<Frame>) {
let fns: [(&str, fn(&mut Stack) -> OError, u32); 14] = [
type Fn = fn(&mut Stack) -> OError;
let fns: [(&str, Fn, u32); 14] = [
("dyn-__dump", dyn_dump, 0),
("dyn-def", dyn_def, 0),
("dyn-func", dyn_func, 0),

View file

@ -69,7 +69,7 @@ fn read_block(
}))))
}
"construct" => {
let name = (&str_words[i + 1]).to_owned();
let name = str_words[i + 1].to_owned();
assert_eq!(
str_words[i + 2],
"{",
@ -78,7 +78,7 @@ fn read_block(
let mut fields = Vec::new();
i += 3;
while str_words[i] != ";" && str_words[i] != "}" {
fields.push((&str_words[i]).to_owned());
fields.push(str_words[i].to_owned());
i += 1;
}
let mut methods = Vec::new();
@ -86,7 +86,7 @@ fn read_block(
if str_words[i] == ";" {
i += 1;
while str_words[i] != "}" {
let name = (&str_words[i]).to_owned();
let name = str_words[i].to_owned();
if name == "construct" {
has_construct = true;
}
@ -137,7 +137,7 @@ fn read_block(
let mut vars = Vec::new();
i += 1;
while &str_words[i] != ";" {
vars.push((&str_words[i]).to_owned());
vars.push(str_words[i].to_owned());
i += 1;
}
words.push(Word::Key(Keyword::With(vars)));
@ -145,37 +145,37 @@ fn read_block(
"}" => {
break;
}
x if x.starts_with("\"") => {
x if x.starts_with('\"') => {
words.push(Word::Const(Value::Str(x[1..].to_owned())));
}
x if x.chars().all(|c| c.is_numeric() || c == '_') && !x.starts_with("_") => {
x if x.chars().all(|c| c.is_numeric() || c == '_') && !x.starts_with('_') => {
words.push(Word::Const(Value::Mega(x.parse().unwrap())));
}
x if x.chars().all(|c| c.is_numeric() || c == '.' || c == '_')
&& !x.starts_with("_") =>
&& !x.starts_with('_') =>
{
words.push(Word::Const(Value::Double(x.parse().unwrap())));
}
x => {
let mut word = x.split(":").next().unwrap();
let mut word = x.split(':').next().unwrap();
let mut ra = 0;
while word.starts_with("&") {
while word.starts_with('&') {
ra += 1;
word = &word[1..];
}
if word.ends_with(";") {
words.push(Word::Call(word[..word.len() - 1].to_owned(), true, ra));
if let Some(word) = word.strip_suffix(';') {
words.push(Word::Call(word.to_owned(), true, ra));
} else {
words.push(Word::Call(word.to_owned(), false, ra));
}
for mut word in x.split(":").skip(1) {
for mut word in x.split(':').skip(1) {
let mut ra = 0;
while word.starts_with("&") {
while word.starts_with('&') {
ra += 1;
word = &word[1..];
}
if word.ends_with(";") {
words.push(Word::ObjCall(word[..word.len() - 1].to_owned(), true, ra));
if let Some(word) = word.strip_suffix(';') {
words.push(Word::ObjCall(word.to_owned(), true, ra));
} else {
words.push(Word::ObjCall(word.to_owned(), false, ra));
}
@ -234,7 +234,7 @@ fn parse_line(line: &str) -> Vec<String> {
continue;
}
if c == ' ' {
if s == "" {
if s.is_empty() {
continue;
}
words.push(s);
@ -246,7 +246,7 @@ fn parse_line(line: &str) -> Vec<String> {
was_in_string = false;
s += String::from(c).as_str();
}
if s != "" {
if !s.is_empty() {
words.push(s);
}
words

View file

@ -31,6 +31,12 @@ pub struct Runtime {
types_by_id: HashMap<u32, AMType>,
}
impl Default for Runtime {
fn default() -> Self {
Self::new()
}
}
impl Runtime {
pub fn new() -> Self {
let mut rt = Runtime {
@ -38,15 +44,15 @@ impl Runtime {
types_by_name: HashMap::new(),
types_by_id: HashMap::new(),
};
let _ = rt.make_type("null".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("int".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("long".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("mega".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("float".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("double".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("func".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("array".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("str".to_owned(), |t| Ok(t)); // infallible
let _ = rt.make_type("null".to_owned(), Ok); // infallible
let _ = rt.make_type("int".to_owned(), Ok); // infallible
let _ = rt.make_type("long".to_owned(), Ok); // infallible
let _ = rt.make_type("mega".to_owned(), Ok); // infallible
let _ = rt.make_type("float".to_owned(), Ok); // infallible
let _ = rt.make_type("double".to_owned(), Ok); // infallible
let _ = rt.make_type("func".to_owned(), Ok); // infallible
let _ = rt.make_type("array".to_owned(), Ok); // infallible
let _ = rt.make_type("str".to_owned(), Ok); // infallible
rt
}
@ -102,7 +108,7 @@ impl Display for Frame {
f.write_str("\nVars: \n")?;
for (name, object) in self.variables.lock_ro().iter() {
f.write_str(" ")?;
f.write_str(&name)?;
f.write_str(name)?;
f.write_str(": ")?;
std::fmt::Display::fmt(&object.lock_ro(), f)?;
f.write_str("\n")?;
@ -201,6 +207,12 @@ impl Display for Stack {
}
}
impl Default for Stack {
fn default() -> Self {
Self::new()
}
}
impl Stack {
pub fn new() -> Self {
let o = Arc::new(Frame::root());
@ -210,7 +222,7 @@ impl Stack {
};
dyn_fns::register(&mut r, o.clone());
std_fns::register(&mut r, o.clone());
std_fns::register(&mut r, o);
r
}
@ -263,7 +275,7 @@ impl Stack {
ret_count: 1,
origin: frame.clone(),
to_call: FuncImpl::NativeDyn(Arc::new(Box::new(move |stack| {
stack.push(tmpframe.get_var(tmpname.clone(), &stack)?);
stack.push(tmpframe.get_var(tmpname.clone(), stack)?);
Ok(())
}))),
cname: Some("RUNTIME".to_owned()),
@ -271,14 +283,14 @@ impl Stack {
);
let tmpname = name.clone();
let tmpframe = frame.clone();
frame.clone().functions.lock().insert(
frame.functions.lock().insert(
"=".to_owned() + &name,
Arc::new(Func {
ret_count: 0,
origin: frame.clone(),
to_call: FuncImpl::NativeDyn(Arc::new(Box::new(move |stack| {
let v = stack.pop();
tmpframe.set_var(tmpname.clone(), v, &stack)
tmpframe.set_var(tmpname.clone(), v, stack)
}))),
cname: Some("RUNTIME".to_owned()),
}),
@ -422,6 +434,7 @@ pub struct Words {
}
#[derive(Clone)]
#[allow(clippy::type_complexity)]
pub enum FuncImpl {
Native(fn(&mut Stack) -> OError),
NativeDyn(Arc<Box<dyn Fn(&mut Stack) -> OError>>),
@ -574,7 +587,7 @@ impl Display for Object {
self.native.fmt(f)?;
f.write_str(") { ")?;
for (k, v) in &self.property_map {
f.write_str(&k)?;
f.write_str(k)?;
f.write_str(": ")?;
std::fmt::Display::fmt(&v.lock_ro(), f)?;
}
@ -608,7 +621,7 @@ impl Object {
Value::Double(_) => true,
Value::Func(_) => true,
Value::Array(_) => true,
Value::Str(x) => x == "",
Value::Str(x) => x.is_empty(),
}
}
}
@ -655,7 +668,7 @@ impl Words {
for word in self.words.clone() {
match word {
Word::Key(x) => match x {
Keyword::Dump => println!("{}", stack),
Keyword::Dump => println!("{stack}"),
Keyword::Def(x) => stack.define_var(x),
Keyword::Func(name, rem, words) => stack.define_func(
name,
@ -708,12 +721,13 @@ impl Words {
RUNTIME.with(move |rt| {
let mut rt = rt.borrow_mut();
let rt = rt.as_mut().expect("no runtime (use .set())");
Ok(
rt.get_type_by_name(tb.clone())
.ok_or_else(|| rstack.error(ErrorKind::TypeNotFound(tb.clone())))?
.lock()
.parents
.push(rt.get_type_by_name(ta).ok_or_else(|| rstack.error(ErrorKind::TypeNotFound(tb)))?))
.ok_or_else(|| rstack.error(ErrorKind::TypeNotFound(tb.clone())))?
.lock()
.parents
.push(rt.get_type_by_name(ta).ok_or_else(|| rstack.error(ErrorKind::TypeNotFound(tb)))?);
Ok(
())
})?;
}
Keyword::While(cond, blk) => loop {

View file

@ -218,7 +218,7 @@ pub fn to_long(stack: &mut Stack) -> OError {
Value::Long(match o {
Value::Null => type_err!(stack, "null", "long"),
Value::Int(x) => x as i64,
Value::Long(x) => x as i64,
Value::Long(x) => x,
Value::Mega(x) => x as i64,
Value::Float(x) => x as i64,
Value::Double(x) => x as i64,
@ -240,7 +240,7 @@ pub fn to_mega(stack: &mut Stack) -> OError {
Value::Null => type_err!(stack, "null", "mega"),
Value::Int(x) => x as i128,
Value::Long(x) => x as i128,
Value::Mega(x) => x as i128,
Value::Mega(x) => x,
Value::Float(x) => x as i128,
Value::Double(x) => x as i128,
Value::Func(_) => type_err!(stack, "func", "mega"),
@ -262,7 +262,7 @@ pub fn to_float(stack: &mut Stack) -> OError {
Value::Int(x) => x as f32,
Value::Long(x) => x as f32,
Value::Mega(x) => x as f32,
Value::Float(x) => x as f32,
Value::Float(x) => x,
Value::Double(x) => x as f32,
Value::Func(_) => type_err!(stack, "func", "float"),
Value::Array(_) => type_err!(stack, "array", "float"),
@ -284,7 +284,7 @@ pub fn to_double(stack: &mut Stack) -> OError {
Value::Long(x) => x as f64,
Value::Mega(x) => x as f64,
Value::Float(x) => x as f64,
Value::Double(x) => x as f64,
Value::Double(x) => x,
Value::Func(_) => type_err!(stack, "func", "double"),
Value::Array(_) => type_err!(stack, "array", "double"),
Value::Str(x) => x
@ -373,7 +373,8 @@ pub fn exit(stack: &mut Stack) -> OError {
}
pub fn register(r: &mut Stack, o: Arc<Frame>) {
let fns: [(&str, fn(&mut Stack) -> OError, u32); 28] = [
type Fn = fn(&mut Stack) -> OError;
let fns: [(&str, Fn, u32); 28] = [
("pop", pop, 0),
("dup", dup, 2),
("clone", clone, 1),