Skip to content

Commit

Permalink
Fixed warnings from cargo
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Oct 15, 2023
1 parent 7ae274b commit 88455e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
9 changes: 4 additions & 5 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fs::read;
use std::io::stderr;
use std::path::PathBuf;
use std::rc::Rc;

use ast::Program;
use clap::{Parser, Subcommand};
Expand All @@ -28,7 +27,7 @@ fn main() {

match args.subcommand {
Action::Run { filename } => {
let Some(ast) = load_ast(&filename) else{
let Some(ast) = load_ast(&filename) else {
print_err("Could not load AST");
return;
};
Expand All @@ -46,7 +45,7 @@ fn main() {
}
}
Action::Ast { filename } => {
let Some(ast) = load_ast(&filename) else{
let Some(ast) = load_ast(&filename) else {
print_err("Could not load AST");
return;
};
Expand All @@ -56,12 +55,12 @@ fn main() {
}

fn load_ast(filename: &PathBuf) -> Option<Program> {
let Ok(file) = read(filename) else{
let Ok(file) = read(filename) else {
print_err("Could not load file from disk.");
return None;
};

let Ok(source) = String::from_utf8(file)else{
let Ok(source) = String::from_utf8(file) else {
print_err("Could not parse UTF-8 source.");
return None;
};
Expand Down
38 changes: 16 additions & 22 deletions crates/interpreter/src/stdlib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use std::{
rc::Rc,
time::{SystemTime, UNIX_EPOCH},
};

use gc::{GcCell, Trace};

use crate::{Context, Error, GcValue, NativeFn, ShallowValue, Value};
use std::time::{SystemTime, UNIX_EPOCH};

pub fn add_stdlib(context: &mut Context) {
context.add_native_fn("timestamp".to_string(), NativeFn(timestamp));
Expand Down Expand Up @@ -39,9 +33,9 @@ fn push(_ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {

let mut first = (*args_iter.next().unwrap()).borrow_mut();

let Value::Array(arr) = &mut *first else{
return Err(Error::TypeError(ShallowValue::Array, (*first).as_shallow()));
};
let Value::Array(arr) = &mut *first else {
return Err(Error::TypeError(ShallowValue::Array, (*first).as_shallow()));
};

for arg in args_iter {
arr.push_back(arg.clone())
Expand All @@ -59,13 +53,13 @@ fn pop(_ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {

let mut first = (*args_iter.next().unwrap()).borrow_mut();

let Value::Array(arr) = &mut *first else{
return Err(Error::TypeError(ShallowValue::Array, (*first).as_shallow()));
};
let Value::Array(arr) = &mut *first else {
return Err(Error::TypeError(ShallowValue::Array, (*first).as_shallow()));
};

Ok(arr.pop_back().unwrap_or_else(|| Value::Null.into_gc()))
}
fn unshift(ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {
fn unshift(_ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {
if args.len() < 2 {
return Err(Error::IncorrectArgumentCount(2, args.len()));
}
Expand All @@ -74,17 +68,17 @@ fn unshift(ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {

let mut first = (*args_iter.next().unwrap()).borrow_mut();

let Value::Array(arr) = &mut *first else{
return Err(Error::TypeError(ShallowValue::Array, (*first).as_shallow()));
};
let Value::Array(arr) = &mut *first else {
return Err(Error::TypeError(ShallowValue::Array, (*first).as_shallow()));
};

for arg in args_iter {
arr.push_front(arg.clone())
}

Ok((Value::Null).into_gc())
}
fn shift(ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {
fn shift(_ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {
if args.is_empty() {
return Err(Error::IncorrectArgumentCount(1, args.len()));
}
Expand All @@ -93,14 +87,14 @@ fn shift(ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {

let mut first = (*args_iter.next().unwrap()).borrow_mut();

let Value::Array(arr) = &mut *first else{
return Err(Error::TypeError(ShallowValue::Array, (*first).as_shallow()));
};
let Value::Array(arr) = &mut *first else {
return Err(Error::TypeError(ShallowValue::Array, (*first).as_shallow()));
};

Ok(arr.pop_front().unwrap_or_else(|| Value::Null.into_gc()))
}

fn len(ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {
fn len(_ctx: &mut Context, args: &[GcValue]) -> Result<GcValue, Error> {
if args.is_empty() {
return Err(Error::IncorrectArgumentCount(1, args.len()));
}
Expand Down
7 changes: 3 additions & 4 deletions crates/interpreter/src/value.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::cell::RefCell;
use std::collections::{HashMap, VecDeque};
use std::fmt::Display;
use std::ops::Deref;
use std::rc::Rc;

use ast::{BinaryOpKind, FnCall, Stmt};
use gc::{unsafe_empty_trace, Finalize, Gc, GcCell, GcCellRef, GcCellRefMut, Trace};
use ast::BinaryOpKind;
use gc::{Finalize, Gc, GcCell, GcCellRef, GcCellRefMut, Trace};

use crate::error::Error;
use crate::{Callable, Context, NativeFn};
use crate::Callable;

#[derive(Clone, Trace, Finalize)]
pub enum Value {
Expand Down

0 comments on commit 88455e8

Please sign in to comment.