Remove a bunch of warnings

This commit is contained in:
Sofia 2026-03-17 21:56:42 +02:00
parent 0fcd00864b
commit e30ecd865a
4 changed files with 27 additions and 35 deletions

View File

@ -134,7 +134,7 @@ pub struct Function {
pub name: Option<Node<String>>, pub name: Option<Node<String>>,
pub params: Vec<Node<String>>, pub params: Vec<Node<String>>,
pub block: Block, pub block: Block,
pub meta: Metadata, pub _meta: Metadata,
} }
impl Parse for Function { impl Parse for Function {
@ -165,7 +165,7 @@ impl Parse for Function {
name, name,
params, params,
block, block,
meta: Metadata::produce(&mut stream, pre), _meta: Metadata::produce(&mut stream, pre),
}) })
} }
} }
@ -183,7 +183,7 @@ impl Parse for String {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Block { pub struct Block {
pub statements: Vec<Node<Statement>>, pub statements: Vec<Node<Statement>>,
pub meta: Metadata, pub _meta: Metadata,
} }
impl Parse for Block { impl Parse for Block {
@ -200,7 +200,7 @@ impl Parse for Block {
Ok(Block { Ok(Block {
statements, statements,
meta: Metadata::produce(&mut stream, pre), _meta: Metadata::produce(&mut stream, pre),
}) })
} }
} }

View File

@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
use crate::{ use crate::{
ast::{AccessModifier, BinaryOperator, Block, Expression, Literal, Statement, UnaryOperator}, ast::{AccessModifier, BinaryOperator, Block, Expression, Literal, Statement, UnaryOperator},
vm::{Constant, Instruction, LuaBool, VMFloat}, vm::{Constant, Instruction, LuaBool},
}; };
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -16,7 +16,7 @@ impl State {
self.constants self.constants
.iter() .iter()
.enumerate() .enumerate()
.find(|(i, c)| *c == value) .find(|(_, c)| *c == value)
.unwrap() .unwrap()
.0 as u32 .0 as u32
} }
@ -218,8 +218,7 @@ impl Statement {
None => { None => {
for (i, (name, indexes)) in names.iter().enumerate() { for (i, (name, indexes)) in names.iter().enumerate() {
if indexes.len() > 0 { if indexes.len() > 0 {
let mut table_reg = if let Some(reg) = scope.locals.get(&name.kind) let table_reg = if let Some(reg) = scope.locals.get(&name.kind) {
{
*reg *reg
} else if let Some(upval_reg) = scope.upvalues.get(&name.kind) { } else if let Some(upval_reg) = scope.upvalues.get(&name.kind) {
let local = scope.register_counter.next(); let local = scope.register_counter.next();

View File

@ -1,4 +1,4 @@
use std::{fmt::Debug, marker::PhantomData, path::PathBuf}; use std::{fmt::Debug, path::PathBuf};
use thiserror::Error; use thiserror::Error;
@ -11,9 +11,9 @@ use crate::{
vm::{ClosureRunner, VirtualMachine}, vm::{ClosureRunner, VirtualMachine},
}; };
pub mod ast; mod ast;
pub mod compile; mod compile;
pub mod token_stream; mod token_stream;
pub mod vm; pub mod vm;
#[derive(Error, Debug)] #[derive(Error, Debug)]
@ -26,9 +26,9 @@ pub enum CompilationError {
#[derive(Clone)] #[derive(Clone)]
pub struct CompilationUnit { pub struct CompilationUnit {
instructions: Vec<vm::Instruction>, pub instructions: Vec<vm::Instruction>,
state: compile::State, pub state: compile::State,
constants: Vec<vm::Constant>, pub constants: Vec<vm::Constant>,
} }
impl Debug for CompilationUnit { impl Debug for CompilationUnit {

View File

@ -1,17 +1,10 @@
use thiserror::Error; use thiserror::Error;
use std::{ use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, rc::Rc};
cell::{RefCell, RefMut},
collections::HashMap,
fmt::Debug,
hash::Hash,
rc::Rc,
};
use crate::{ use crate::{
CompilationUnit, CompilationUnit,
ast::{BinaryOperator, UnaryOperator}, ast::{BinaryOperator, UnaryOperator},
compile,
}; };
#[derive(Clone, Hash, PartialEq, Eq, Copy)] #[derive(Clone, Hash, PartialEq, Eq, Copy)]
@ -221,7 +214,7 @@ pub enum RuntimeError {
} }
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct Environment { pub(crate) struct Environment {
pub globals: HashMap<Constant, Rc<RefCell<Value>>>, pub globals: HashMap<Constant, Rc<RefCell<Value>>>,
} }
@ -515,10 +508,10 @@ impl VirtualMachine {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Closure { pub struct Closure {
pub vm: VirtualMachine, vm: VirtualMachine,
pub prototype: u32, prototype: u32,
pub environment: Rc<RefCell<Environment>>, environment: Rc<RefCell<Environment>>,
pub upvalues: HashMap<u16, Rc<RefCell<Value>>>, upvalues: HashMap<u16, Rc<RefCell<Value>>>,
} }
impl Closure { impl Closure {
@ -551,13 +544,13 @@ impl Closure {
} }
pub struct ClosureRunner { pub struct ClosureRunner {
pub closure: Closure, closure: Closure,
pub program_counter: usize, program_counter: usize,
pub stack: HashMap<u16, Rc<RefCell<Value>>>, stack: HashMap<u16, Rc<RefCell<Value>>>,
pub inner: Option<Box<ClosureRunner>>, inner: Option<Box<ClosureRunner>>,
pub function_register: u16, function_register: u16,
pub return_registers: Vec<u16>, return_registers: Vec<u16>,
pub top: u16, top: u16,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]