handle warnings
This commit is contained in:
parent
3613c7cc8f
commit
7258fe035a
11 changed files with 64 additions and 55 deletions
|
|
@ -20,7 +20,7 @@ fn window_conf() -> Conf {
|
|||
async fn main() {
|
||||
info!("Hello, 👁️🗨️!");
|
||||
if screen_width() < SCREEN_WIDTH {
|
||||
request_new_screen_size(SCREEN_WIDTH as f32, SCREEN_HEIGHT as f32);
|
||||
request_new_screen_size(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
}
|
||||
rand::srand(macroquad::miniquad::date::now() as _);
|
||||
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ fn eval_expr(expr_env: &Env, state: &mut State, expr: &ast::Expr) -> Result<ast:
|
|||
Ok(result)
|
||||
}
|
||||
ast::Expr::Access { expr, field } => match eval_expr(expr_env, state, expr)? {
|
||||
ast::Value::Record(record) => Ok(state.variables.get(record.get(&field)?).clone()),
|
||||
ast::Value::Record(record) => Ok(state.variables.get(record.get(field)?).clone()),
|
||||
ast::Value::Vector(vec) => match field {
|
||||
_ if field.0.chars().all(char::is_numeric) => {
|
||||
let index = field.0.parse::<usize>().unwrap();
|
||||
|
|
@ -172,7 +172,7 @@ fn eval_expr(expr_env: &Env, state: &mut State, expr: &ast::Expr) -> Result<ast:
|
|||
let value = match expr_env.get(var) {
|
||||
Ok(value) => Ok(value.clone()),
|
||||
Err(err) => {
|
||||
if state.primitive_funcs.get(&var).is_some() {
|
||||
if state.primitive_funcs.get(var).is_some() {
|
||||
Ok(ast::Value::PrimitiveFunc(var.clone()))
|
||||
} else {
|
||||
Err(err)
|
||||
|
|
@ -192,7 +192,7 @@ fn eval_expr(expr_env: &Env, state: &mut State, expr: &ast::Expr) -> Result<ast:
|
|||
}
|
||||
|
||||
for (arg, e) in func.args.into_iter().zip(args.iter()) {
|
||||
let evalled = eval_expr(&expr_env, state, e)?;
|
||||
let evalled = eval_expr(expr_env, state, e)?;
|
||||
closure_env.insert(arg.name, evalled);
|
||||
}
|
||||
match eval_expr(&closure_env, state, &func.body)? {
|
||||
|
|
@ -205,7 +205,7 @@ fn eval_expr(expr_env: &Env, state: &mut State, expr: &ast::Expr) -> Result<ast:
|
|||
ast::Value::PrimitiveFunc(func) => {
|
||||
let mut argsvec = vec![];
|
||||
for arg in args.iter() {
|
||||
let evalled = eval_expr(&expr_env, state, arg)?;
|
||||
let evalled = eval_expr(expr_env, state, arg)?;
|
||||
let e = value_to_stadnalone_expr(state, evalled)?;
|
||||
argsvec.push(e);
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ fn eval_expr(expr_env: &Env, state: &mut State, expr: &ast::Expr) -> Result<ast:
|
|||
Backtrace::capture(),
|
||||
)),
|
||||
},
|
||||
ast::Expr::Not(e) => match eval_expr(&expr_env, state, e)? {
|
||||
ast::Expr::Not(e) => match eval_expr(expr_env, state, e)? {
|
||||
ast::Value::Boolean(b) => Ok(ast::Value::Boolean(!b)),
|
||||
v => Err(Error::NotABoolean(v, Backtrace::capture())),
|
||||
},
|
||||
|
|
@ -353,9 +353,13 @@ fn eval_expr(expr_env: &Env, state: &mut State, expr: &ast::Expr) -> Result<ast:
|
|||
let cop = match cop {
|
||||
ast::Cmp::Eq => |a, b| a == b,
|
||||
ast::Cmp::NotEq => |a, b| a != b,
|
||||
#[allow(clippy::bool_comparison)]
|
||||
ast::Cmp::Gt => |a, b| a > b,
|
||||
#[allow(clippy::bool_comparison)]
|
||||
ast::Cmp::Gte => |a, b| a >= b,
|
||||
#[allow(clippy::bool_comparison)]
|
||||
ast::Cmp::Lt => |a, b| a < b,
|
||||
#[allow(clippy::bool_comparison)]
|
||||
ast::Cmp::Lte => |a, b| a <= b,
|
||||
};
|
||||
Ok(ast::Value::Boolean(cop(a, b)))
|
||||
|
|
@ -417,7 +421,7 @@ fn eval_expr_shallow(
|
|||
) -> Result<ast::Value, Error> {
|
||||
match expr {
|
||||
ast::Expr::Var(var) => {
|
||||
let result = expr_env.get(&var)?;
|
||||
let result = expr_env.get(var)?;
|
||||
match result {
|
||||
ast::Value::Ref(_) => Ok(result.clone()),
|
||||
v => Err(Error::NotAReference(
|
||||
|
|
@ -428,7 +432,7 @@ fn eval_expr_shallow(
|
|||
}
|
||||
}
|
||||
ast::Expr::Access { expr, field } => match eval_expr(expr_env, state, expr)? {
|
||||
ast::Value::Record(record) => Ok(ast::Value::Ref(record.get(&field)?.clone())),
|
||||
ast::Value::Record(record) => Ok(ast::Value::Ref(record.get(field)?.clone())),
|
||||
ast::Value::Vector(vec) => match field {
|
||||
_ if field.0.chars().all(char::is_numeric) => {
|
||||
let index = field.0.parse::<usize>().unwrap();
|
||||
|
|
@ -455,6 +459,7 @@ fn defs_to_env(
|
|||
let mut env = Env::new(env_name.clone());
|
||||
|
||||
for def in defs {
|
||||
#[allow(clippy::match_single_binding)]
|
||||
let (mutable, name, closure) = match def {
|
||||
ast::Definition {
|
||||
mutable,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
//! Interpreter for Ayin.
|
||||
|
||||
pub mod interpret;
|
||||
pub mod types;
|
||||
#[allow(clippy::module_inception)]
|
||||
mod interpret;
|
||||
mod types;
|
||||
|
||||
pub use interpret::*;
|
||||
pub use types::*;
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ pub struct Variables {
|
|||
}
|
||||
|
||||
impl Variables {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
Variables {
|
||||
vars: HashMap::new(),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#[allow(clippy::module_inception)]
|
||||
pub mod parser;
|
||||
pub mod scanner;
|
||||
pub mod types;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn parse_includes(tokens: &mut Tokens) -> ParseResult<Vec<ast::File>> {
|
|||
}
|
||||
|
||||
fn parse_include(tokens: &mut Tokens) -> ParseResult<ast::File> {
|
||||
if let Some(_) = tokens.next_if(&Token::Include) {
|
||||
if tokens.next_if(&Token::Include).is_some() {
|
||||
if let Some(LocatedToken {
|
||||
token: Token::String(string),
|
||||
..
|
||||
|
|
@ -93,11 +93,8 @@ fn parse_dot(tokens: &mut Tokens, expr: ast::Expr) -> Result<ast::Expr, Error> {
|
|||
}
|
||||
|
||||
fn parse_definition(tokens: &mut Tokens) -> ParseResult<ast::Definition> {
|
||||
if let Some(_) = tokens.next_if(&Token::Let) {
|
||||
let mutable = match tokens.next_if(&Token::Mut) {
|
||||
Some(_) => true,
|
||||
_ => false,
|
||||
};
|
||||
if tokens.next_if(&Token::Let).is_some() {
|
||||
let mutable = tokens.next_if(&Token::Mut).is_some();
|
||||
if let Some(name) = parse_identifier_name(tokens)? {
|
||||
if let Some(expr) = parse_set(tokens)? {
|
||||
Ok(Some(ast::Definition {
|
||||
|
|
@ -182,7 +179,7 @@ fn parse_expr2(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
fn parse_simple_expr(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
||||
tokens.one_of(vec![
|
||||
|t| {
|
||||
if let Some(_) = t.next_if(&Token::Not) {
|
||||
if t.next_if(&Token::Not).is_some() {
|
||||
Ok(parse_expr(t)?.map(|expr| ast::Expr::Not(Box::new(expr))))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
|
@ -197,13 +194,13 @@ fn parse_simple_expr(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
parse_vector,
|
||||
|t| t.between(&Token::OpenParen, &Token::CloseParen, parse_expr),
|
||||
|t| {
|
||||
if let Some(_) = t.next_if(&Token::If) {
|
||||
if t.next_if(&Token::If).is_some() {
|
||||
if let Some(condition) = parse_expr(t)? {
|
||||
if let Some(then) = t
|
||||
.between(&Token::OpenCurly, &Token::CloseCurly, parse_block)?
|
||||
.map(ast::Expr::Block)
|
||||
{
|
||||
if let Some(r#else) = if let Some(_) = t.next_if(&Token::Else) {
|
||||
if let Some(r#else) = if t.next_if(&Token::Else).is_some() {
|
||||
Ok(
|
||||
t.between(&Token::OpenCurly, &Token::CloseCurly, parse_block)?
|
||||
.map(ast::Expr::Block),
|
||||
|
|
@ -239,7 +236,7 @@ fn parse_simple_expr(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
}
|
||||
|
||||
fn parse_fn(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
||||
if let Some(_) = tokens.next_if(&Token::Fn) {
|
||||
if tokens.next_if(&Token::Fn).is_some() {
|
||||
if let Some(args) = parse_args(tokens)? {
|
||||
if let Some(body) =
|
||||
tokens.between(&Token::OpenCurly, &Token::CloseCurly, parse_block)?
|
||||
|
|
@ -268,7 +265,7 @@ fn parse_fn(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
fn parse_block(tokens: &mut Tokens) -> ParseResult<Vec<ast::Statement>> {
|
||||
if let Some(mut stmts) = tokens.many_sep_by_maybe(&Token::Semicolon, parse_statement)? {
|
||||
//println!("{stmts:#?} {} {:#?}", stmts.len(), tokens.peek());
|
||||
if stmts.len() > 0 && tokens.next_if(&Token::Semicolon).is_some() {
|
||||
if !stmts.is_empty() && tokens.next_if(&Token::Semicolon).is_some() {
|
||||
stmts.push(ast::Statement::Expr(ast::UNIT));
|
||||
//println!("stmts: {stmts:#?}");
|
||||
Ok(Some(stmts))
|
||||
|
|
@ -286,7 +283,7 @@ fn parse_statement(tokens: &mut Tokens) -> ParseResult<ast::Statement> {
|
|||
|tokens| Ok(parse_expr(tokens)?.map(ast::Statement::Expr)),
|
||||
|tokens| Ok(parse_definition(tokens)?.map(ast::Statement::Let)),
|
||||
|tokens| {
|
||||
if let Some(_) = tokens.next_if(&Token::Return) {
|
||||
if tokens.next_if(&Token::Return).is_some() {
|
||||
let expr = parse_expr(tokens)?;
|
||||
Ok(Some(ast::Statement::Return(expr)))
|
||||
} else {
|
||||
|
|
@ -294,14 +291,14 @@ fn parse_statement(tokens: &mut Tokens) -> ParseResult<ast::Statement> {
|
|||
}
|
||||
},
|
||||
|tokens| {
|
||||
if let Some(_) = tokens.next_if(&Token::Break) {
|
||||
if tokens.next_if(&Token::Break).is_some() {
|
||||
Ok(Some(ast::Statement::Break))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
},
|
||||
|t| {
|
||||
if let Some(_) = t.next_if(&Token::Loop) {
|
||||
if t.next_if(&Token::Loop).is_some() {
|
||||
if let Some(block) = t
|
||||
.between(&Token::OpenCurly, &Token::CloseCurly, parse_block)?
|
||||
.map(ast::Expr::Block)
|
||||
|
|
@ -348,7 +345,7 @@ fn parse_vector(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
|
||||
fn parse_record_field_expr(tokens: &mut Tokens) -> ParseResult<(ast::Label, ast::Expr)> {
|
||||
if let Some(label) = parse_label(tokens)? {
|
||||
if let Some(_) = tokens.next_if(&Token::Colon) {
|
||||
if tokens.next_if(&Token::Colon).is_some() {
|
||||
if let Some(expr) = parse_expr(tokens)? {
|
||||
Ok(Some((label, expr)))
|
||||
} else {
|
||||
|
|
@ -388,7 +385,7 @@ fn parse_number(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
..
|
||||
}) = t.next_if(&Token::Int(0))
|
||||
{
|
||||
Ok(Some(ast::Expr::Value(ast::Value::Int(number.into()))))
|
||||
Ok(Some(ast::Expr::Value(ast::Value::Int(number))))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
|
@ -399,7 +396,7 @@ fn parse_number(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
..
|
||||
}) = t.next_if(&Token::Float(0.0))
|
||||
{
|
||||
Ok(Some(ast::Expr::Value(ast::Value::Float(number.into()))))
|
||||
Ok(Some(ast::Expr::Value(ast::Value::Float(number))))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
|
@ -408,7 +405,7 @@ fn parse_number(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
}
|
||||
|
||||
fn parse_identifier(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
||||
Ok(parse_identifier_name(tokens)?.map(|name| ast::Expr::Var(name)))
|
||||
Ok(parse_identifier_name(tokens)?.map(ast::Expr::Var))
|
||||
}
|
||||
|
||||
fn parse_identifier_arg(tokens: &mut Tokens) -> ParseResult<ast::Arg> {
|
||||
|
|
@ -416,7 +413,7 @@ fn parse_identifier_arg(tokens: &mut Tokens) -> ParseResult<ast::Arg> {
|
|||
}
|
||||
|
||||
fn parse_identifier_name(tokens: &mut Tokens) -> ParseResult<ast::Name> {
|
||||
Ok(parse_identifier_string(tokens)?.map(|string| ast::Name(string)))
|
||||
Ok(parse_identifier_string(tokens)?.map(ast::Name))
|
||||
}
|
||||
|
||||
fn parse_label(tokens: &mut Tokens) -> ParseResult<ast::Label> {
|
||||
|
|
@ -447,7 +444,7 @@ fn parse_bool(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
tokens.one_of(vec![
|
||||
|t| {
|
||||
Ok({
|
||||
if let Some(_) = t.next_if(&Token::True) {
|
||||
if t.next_if(&Token::True).is_some() {
|
||||
Some(ast::Expr::Value(ast::Value::Boolean(true)))
|
||||
} else {
|
||||
None
|
||||
|
|
@ -456,7 +453,7 @@ fn parse_bool(tokens: &mut Tokens) -> ParseResult<ast::Expr> {
|
|||
},
|
||||
|t| {
|
||||
Ok({
|
||||
if let Some(_) = t.next_if(&Token::False) {
|
||||
if t.next_if(&Token::False).is_some() {
|
||||
Some(ast::Expr::Value(ast::Value::Boolean(false)))
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ pub fn scan(source: String) -> Tokens {
|
|||
token: Token::Op(Op::Mod),
|
||||
}),
|
||||
'-' => {
|
||||
let c = c.clone();
|
||||
let c = *c;
|
||||
let is_number = scanner.peek().map(|ch| ch.is_numeric()) == Some(true);
|
||||
if is_number {
|
||||
tokens.push(lex_number(&mut scanner, start, &c));
|
||||
|
|
@ -240,9 +240,7 @@ pub fn scan(source: String) -> Tokens {
|
|||
tokens.push(LocatedToken {
|
||||
start,
|
||||
end: scanner.cursor(),
|
||||
token: match str.as_str() {
|
||||
_ => Token::Label(str),
|
||||
},
|
||||
token: Token::Label(str),
|
||||
});
|
||||
}
|
||||
// comments
|
||||
|
|
@ -274,7 +272,7 @@ pub fn scan(source: String) -> Tokens {
|
|||
_ if c.is_whitespace() => {}
|
||||
// numbers
|
||||
_ if c.is_numeric() => {
|
||||
let c = c.clone();
|
||||
let c = *c;
|
||||
tokens.push(lex_number(&mut scanner, start, &c));
|
||||
}
|
||||
// identifiers and keywords
|
||||
|
|
|
|||
|
|
@ -82,14 +82,12 @@ impl Tokens {
|
|||
pub fn peek(&mut self) -> Option<&LocatedToken> {
|
||||
self.0.last()
|
||||
}
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn next(&mut self) -> Option<LocatedToken> {
|
||||
let t = self.0.pop();
|
||||
|
||||
// println!("'{:?}'", t);
|
||||
t
|
||||
self.0.pop()
|
||||
}
|
||||
pub fn next_if(&mut self, token: &Token) -> Option<LocatedToken> {
|
||||
let t = self.0.pop_if(|t| match (t.token.clone(), token) {
|
||||
self.0.pop_if(|t| match (t.token.clone(), token) {
|
||||
(a, b) if a == *b => true,
|
||||
(Token::Identifier(_), Token::Identifier(_)) => true,
|
||||
(Token::Int(_), Token::Int(_)) => true,
|
||||
|
|
@ -98,9 +96,7 @@ impl Tokens {
|
|||
(Token::Label(_), Token::Label(_)) => true,
|
||||
(Token::Op(_), Token::Op(_)) => true,
|
||||
_ => false,
|
||||
});
|
||||
// println!("'{:?}'", t);
|
||||
t
|
||||
})
|
||||
}
|
||||
pub fn between<T>(&mut self, start: &Token, end: &Token, parser: Parser<T>) -> ParseResult<T> {
|
||||
if let Some(_start) = self.next_if(start) {
|
||||
|
|
@ -162,7 +158,7 @@ impl Tokens {
|
|||
if let Some(first) = parser(self)? {
|
||||
let mut results = vec![first];
|
||||
loop {
|
||||
self.next_if(&separator);
|
||||
self.next_if(separator);
|
||||
if let Some(result) = parser(self)? {
|
||||
results.push(result);
|
||||
} else {
|
||||
|
|
@ -177,7 +173,7 @@ impl Tokens {
|
|||
pub fn many_sep_by<T>(&mut self, separator: &Token, parser: Parser<T>) -> ParseResult<Vec<T>> {
|
||||
if let Some(first) = parser(self)? {
|
||||
let mut results = vec![first];
|
||||
while let Some(_) = self.next_if(&separator) {
|
||||
while self.next_if(separator).is_some() {
|
||||
if let Some(result) = parser(self)? {
|
||||
results.push(result);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
pub mod primitive_functions;
|
||||
|
||||
pub mod runtime;
|
||||
#[allow(clippy::module_inception)]
|
||||
mod runtime;
|
||||
pub use runtime::*;
|
||||
|
||||
pub mod types;
|
||||
mod types;
|
||||
pub use types::*;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ pub fn primitive_funcs() -> PrimitiveFuncs {
|
|||
}
|
||||
|
||||
fn clear(args: Vec<ast::Expr>) -> ast::Value {
|
||||
#[allow(clippy::get_first)]
|
||||
let r = to_u8(args.get(0));
|
||||
let g = to_u8(args.get(1));
|
||||
let b = to_u8(args.get(2));
|
||||
|
|
@ -29,7 +30,7 @@ fn random_u8(_args: Vec<ast::Expr>) -> ast::Value {
|
|||
}
|
||||
|
||||
fn frame_time(_args: Vec<ast::Expr>) -> ast::Value {
|
||||
ast::Value::Float(get_frame_time() as f32)
|
||||
ast::Value::Float(get_frame_time())
|
||||
}
|
||||
|
||||
struct Rectangle {
|
||||
|
|
@ -40,6 +41,7 @@ struct Rectangle {
|
|||
}
|
||||
|
||||
fn draw_rectangle(args: Vec<ast::Expr>) -> ast::Value {
|
||||
#[allow(clippy::get_first)]
|
||||
let rectangle = match args.get(0) {
|
||||
Some(ast::Expr::Record(record)) => {
|
||||
let x = to_f32(record.get(&"x".into()));
|
||||
|
|
@ -60,16 +62,17 @@ fn draw_rectangle(args: Vec<ast::Expr>) -> ast::Value {
|
|||
_ => todo!(),
|
||||
};
|
||||
mq::draw_rectangle(
|
||||
rectangle.x * SCALE as f32,
|
||||
rectangle.y * SCALE as f32,
|
||||
rectangle.w * SCALE as f32,
|
||||
rectangle.h * SCALE as f32,
|
||||
rectangle.x * SCALE,
|
||||
rectangle.y * SCALE,
|
||||
rectangle.w * SCALE,
|
||||
rectangle.h * SCALE,
|
||||
color,
|
||||
);
|
||||
ast::UNIT_VALUE
|
||||
}
|
||||
|
||||
fn draw_text(args: Vec<ast::Expr>) -> ast::Value {
|
||||
#[allow(clippy::get_first)]
|
||||
let text = to_string(args.get(0));
|
||||
let x = to_f32(args.get(1));
|
||||
let y = to_f32(args.get(2));
|
||||
|
|
@ -100,7 +103,7 @@ fn to_u8(value: Option<&ast::Expr>) -> u8 {
|
|||
fn to_f32(value: Option<&ast::Expr>) -> f32 {
|
||||
match value {
|
||||
Some(ast::Expr::Value(ast::Value::Int(i))) => *i as f32,
|
||||
Some(ast::Expr::Value(ast::Value::Float(f))) => *f as f32,
|
||||
Some(ast::Expr::Value(ast::Value::Float(f))) => *f,
|
||||
_ => 0.0,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use macroquad::prelude::*;
|
|||
|
||||
pub struct State {
|
||||
pub assets: Assets,
|
||||
pub state: interpret::types::State,
|
||||
pub state: interpret::State,
|
||||
pub game_state: ast::Value,
|
||||
pub gamepads: gamepads::Gamepads,
|
||||
}
|
||||
|
|
@ -50,6 +50,12 @@ impl Input {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Input {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Gamepad {
|
||||
pub buttons: Buttons,
|
||||
pub dpad: DPad,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue