Fix clippy errors
This commit is contained in:
@@ -40,7 +40,7 @@ pub enum InterruptIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InterruptIndex {
|
impl InterruptIndex {
|
||||||
fn as_u8(self) -> u8 {
|
const fn as_u8(self) -> u8 {
|
||||||
self as u8
|
self as u8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,9 +48,8 @@ pub static _KERNEL_PHYSICAL_MEMORY_OFFSET: Lazy<(u64, u64)> = Lazy::new(|| {
|
|||||||
///
|
///
|
||||||
/// Panics if the memory map was not found in MEMORY_MAP_REQUEST.
|
/// Panics if the memory map was not found in MEMORY_MAP_REQUEST.
|
||||||
pub fn get_memory_map() -> &'static MemoryMapResponse {
|
pub fn get_memory_map() -> &'static MemoryMapResponse {
|
||||||
if let Some(memory_map) = MEMORY_MAP_REQUEST.get_response() {
|
MEMORY_MAP_REQUEST.get_response().map_or_else(
|
||||||
memory_map
|
|| unreachable!("Could not fetch memory map from Limine."),
|
||||||
} else {
|
|memory_map| memory_map,
|
||||||
unreachable!("Could not fetch memory map from Limine.")
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct FoundryOSFrameAllocator {
|
pub struct FoundryOSFrameAllocator {
|
||||||
memory_map: &'static MemoryMapResponse,
|
memory_map: &'static MemoryMapResponse,
|
||||||
next: usize,
|
next: usize,
|
||||||
}
|
}
|
||||||
@@ -66,8 +66,8 @@ impl FoundryOSFrameAllocator {
|
|||||||
/// This function takes a reference to a `MemoryMapResponse` and initializes a
|
/// This function takes a reference to a `MemoryMapResponse` and initializes a
|
||||||
/// `FoundryOSFrameAllocator` with it. The `next` field is set to 0, indicating that
|
/// `FoundryOSFrameAllocator` with it. The `next` field is set to 0, indicating that
|
||||||
/// the first frame to be allocated is the first frame in the memory map.
|
/// the first frame to be allocated is the first frame in the memory map.
|
||||||
pub unsafe fn init(memory_map: &'static MemoryMapResponse) -> FoundryOSFrameAllocator {
|
pub const unsafe fn init(memory_map: &'static MemoryMapResponse) -> Self {
|
||||||
FoundryOSFrameAllocator {
|
Self {
|
||||||
memory_map,
|
memory_map,
|
||||||
next: 0,
|
next: 0,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ pub mod interrupts;
|
|||||||
|
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
|
|
||||||
pub(crate) mod memmap;
|
pub mod memmap;
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![feature(abi_x86_interrupt)]
|
#![feature(abi_x86_interrupt)]
|
||||||
|
#![warn(
|
||||||
|
clippy::correctness,
|
||||||
|
clippy::nursery,
|
||||||
|
clippy::unnecessary_cast,
|
||||||
|
clippy::all,
|
||||||
|
clippy::suspicious,
|
||||||
|
clippy::perf,
|
||||||
|
rustdoc::missing_errors_doc,
|
||||||
|
rustdoc::missing_panics_doc
|
||||||
|
)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -4,13 +4,11 @@
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use libk::{
|
use libk::{
|
||||||
// scheduling::task::{Executor, Task},
|
|
||||||
drivers::{
|
drivers::{
|
||||||
io::{self, ascii::WRITER, keyboard},
|
io::{self, keyboard},
|
||||||
scheduling::task::{Executor, Task},
|
scheduling::task::{Executor, Task},
|
||||||
},
|
},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
resources::font::FONT_SPLEEN_8X16,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ impl Writer {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_font(&mut self, font: &'static Font) {
|
pub const fn set_font(&mut self, font: &'static Font) {
|
||||||
self.font = font;
|
self.font = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ static WAKER: AtomicWaker = AtomicWaker::new();
|
|||||||
|
|
||||||
pub fn add_scancode(scancode: u8) {
|
pub fn add_scancode(scancode: u8) {
|
||||||
if let Some(queue) = KBD_QUEUE.get() {
|
if let Some(queue) = KBD_QUEUE.get() {
|
||||||
if let Err(_) = queue.push(scancode) {
|
if queue.push(scancode).is_err() {
|
||||||
println!("WARNING: scancode queue full; dropping keyboard input");
|
println!("WARNING: scancode queue full; dropping keyboard input");
|
||||||
} else {
|
} else {
|
||||||
WAKER.wake();
|
WAKER.wake();
|
||||||
@@ -34,7 +34,13 @@ pub struct ScancodeStream {
|
|||||||
impl ScancodeStream {
|
impl ScancodeStream {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
KBD_QUEUE.call_once(|| ArrayQueue::new(5));
|
KBD_QUEUE.call_once(|| ArrayQueue::new(5));
|
||||||
ScancodeStream { _private: () }
|
Self { _private: () }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ScancodeStream {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,15 +54,12 @@ impl Stream for ScancodeStream {
|
|||||||
return Poll::Ready(Some(scancode));
|
return Poll::Ready(Some(scancode));
|
||||||
}
|
}
|
||||||
|
|
||||||
WAKER.register(&cx.waker());
|
WAKER.register(cx.waker());
|
||||||
|
|
||||||
match queue.pop() {
|
queue.pop().map_or(Poll::Pending, |scancode| {
|
||||||
Some(scancode) => {
|
WAKER.take();
|
||||||
WAKER.take();
|
Poll::Ready(Some(scancode))
|
||||||
Poll::Ready(Some(scancode))
|
})
|
||||||
}
|
|
||||||
None => Poll::Pending,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ pub struct Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
pub fn new(future: impl Future<Output = ()> + 'static) -> Task {
|
pub fn new(future: impl Future<Output = ()> + 'static) -> Self {
|
||||||
Task {
|
Self {
|
||||||
id: TaskId::new(),
|
id: TaskId::new(),
|
||||||
future: Box::pin(future),
|
future: Box::pin(future),
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ struct TaskId(u64);
|
|||||||
impl TaskId {
|
impl TaskId {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
static NEXT: AtomicU64 = AtomicU64::new(0);
|
static NEXT: AtomicU64 = AtomicU64::new(0);
|
||||||
TaskId(NEXT.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
|
Self(NEXT.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ pub struct Executor {
|
|||||||
|
|
||||||
impl Executor {
|
impl Executor {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Executor {
|
Self {
|
||||||
tasks: BTreeMap::new(),
|
tasks: BTreeMap::new(),
|
||||||
task_queue: Arc::new(ArrayQueue::new(100)),
|
task_queue: Arc::new(ArrayQueue::new(100)),
|
||||||
waker_cache: BTreeMap::new(),
|
waker_cache: BTreeMap::new(),
|
||||||
@@ -73,7 +73,7 @@ impl Executor {
|
|||||||
};
|
};
|
||||||
let waker = waker_cache
|
let waker = waker_cache
|
||||||
.entry(task_id)
|
.entry(task_id)
|
||||||
.or_insert_with(|| TaskWaker::new(task_id, task_queue.clone()));
|
.or_insert_with(|| TaskWaker::new_waker(task_id, task_queue.clone()));
|
||||||
let mut context = Context::from_waker(waker);
|
let mut context = Context::from_waker(waker);
|
||||||
match task.poll(&mut context) {
|
match task.poll(&mut context) {
|
||||||
Poll::Ready(()) => {
|
Poll::Ready(()) => {
|
||||||
@@ -103,6 +103,12 @@ impl Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Executor {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct TaskWaker {
|
struct TaskWaker {
|
||||||
task_id: TaskId,
|
task_id: TaskId,
|
||||||
task_queue: Arc<ArrayQueue<TaskId>>,
|
task_queue: Arc<ArrayQueue<TaskId>>,
|
||||||
@@ -113,8 +119,8 @@ impl TaskWaker {
|
|||||||
self.task_queue.push(self.task_id).expect("task_queue full");
|
self.task_queue.push(self.task_id).expect("task_queue full");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(task_id: TaskId, task_queue: Arc<ArrayQueue<TaskId>>) -> Waker {
|
fn new_waker(task_id: TaskId, task_queue: Arc<ArrayQueue<TaskId>>) -> Waker {
|
||||||
Waker::from(Arc::new(TaskWaker {
|
Waker::from(Arc::new(Self {
|
||||||
task_id,
|
task_id,
|
||||||
task_queue,
|
task_queue,
|
||||||
}))
|
}))
|
||||||
|
|||||||
+12
-1
@@ -1,7 +1,16 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![allow(async_fn_in_trait)]
|
#![allow(async_fn_in_trait)]
|
||||||
#![warn(tail_expr_drop_order)]
|
#![warn(tail_expr_drop_order)]
|
||||||
#![warn(clippy::correctness, clippy::perf, clippy::nursery)]
|
#![warn(
|
||||||
|
clippy::correctness,
|
||||||
|
clippy::nursery,
|
||||||
|
clippy::unnecessary_cast,
|
||||||
|
clippy::all,
|
||||||
|
clippy::suspicious,
|
||||||
|
clippy::perf,
|
||||||
|
rustdoc::missing_errors_doc,
|
||||||
|
rustdoc::missing_panics_doc
|
||||||
|
)]
|
||||||
// alloc
|
// alloc
|
||||||
// io : serial, framebuffer, ascii(?), keyboard
|
// io : serial, framebuffer, ascii(?), keyboard
|
||||||
// ?????
|
// ?????
|
||||||
@@ -11,6 +20,8 @@ extern crate alloc;
|
|||||||
|
|
||||||
pub mod drivers;
|
pub mod drivers;
|
||||||
pub mod resources;
|
pub mod resources;
|
||||||
|
|
||||||
|
#[allow(unused)] // We aren't using much of this right now.
|
||||||
pub mod std;
|
pub mod std;
|
||||||
|
|
||||||
/// Re-exports most of the IO macros as well as standard allocation stuff
|
/// Re-exports most of the IO macros as well as standard allocation stuff
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
mod window;
|
||||||
|
|
||||||
pub trait Application {
|
pub trait Application {
|
||||||
type Output;
|
type Output;
|
||||||
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
pub mod application;
|
|
||||||
pub mod window;
|
|
||||||
@@ -9,8 +9,8 @@ pub struct Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub const fn new() -> Window {
|
pub const fn new() -> Self {
|
||||||
Window {
|
Self {
|
||||||
dimensions: Vec2::new(0, 0),
|
dimensions: Vec2::new(0, 0),
|
||||||
position: Vec2::new(0, 0),
|
position: Vec2::new(0, 0),
|
||||||
bordered: true,
|
bordered: true,
|
||||||
@@ -19,32 +19,32 @@ impl Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_bordered(&self) -> bool {
|
pub const fn is_bordered(&self) -> bool {
|
||||||
self.bordered
|
self.bordered
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_open(&self) -> bool {
|
pub const fn is_open(&self) -> bool {
|
||||||
self.opened
|
self.opened
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open(&mut self) {
|
pub const fn open(&mut self) {
|
||||||
self.opened = true;
|
self.opened = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(&mut self) {
|
pub const fn close(&mut self) {
|
||||||
self.opened = false;
|
self.opened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// some basic getters and setters for utility.
|
// some basic getters and setters for utility.
|
||||||
pub fn title(&self) -> &str {
|
pub fn title(&'static self) -> &'static str {
|
||||||
&self.title
|
self.title.as_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dimensions(&self) -> Vec2<usize> {
|
pub const fn dimensions(&self) -> Vec2<usize> {
|
||||||
self.dimensions
|
self.dimensions
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(&self) -> Vec2<usize> {
|
pub const fn position(&self) -> Vec2<usize> {
|
||||||
self.position
|
self.position
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,15 +56,21 @@ impl Window {
|
|||||||
self.position += offset;
|
self.position += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&mut self, position: Vec2<usize>) {
|
pub const fn set_position(&mut self, position: Vec2<usize>) {
|
||||||
self.position = position;
|
self.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_dimensions(&mut self, dimensions: Vec2<usize>) {
|
pub const fn set_dimensions(&mut self, dimensions: Vec2<usize>) {
|
||||||
self.dimensions = dimensions;
|
self.dimensions = dimensions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Window {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Drop for Window {
|
impl Drop for Window {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.opened {
|
if self.opened {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ impl Coordinate for i128 {}
|
|||||||
impl Coordinate for f32 {}
|
impl Coordinate for f32 {}
|
||||||
impl Coordinate for f64 {}
|
impl Coordinate for f64 {}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)]
|
||||||
pub struct Vec2<T: Coordinate> {
|
pub struct Vec2<T: Coordinate> {
|
||||||
x: T,
|
x: T,
|
||||||
y: T,
|
y: T,
|
||||||
@@ -32,14 +32,14 @@ impl<T: Coordinate> Vec2<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn into<S: Coordinate + From<T>>(&self) -> Vec2<S> {
|
pub fn into<S: Coordinate + From<T>>(&self) -> Vec2<S> {
|
||||||
Vec2::new(self.x.clone().into(), self.y.clone().into())
|
Vec2::new(self.x.into(), self.y.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn x(&self) -> T {
|
pub const fn x(&self) -> T {
|
||||||
self.x
|
self.x
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn y(&self) -> T {
|
pub const fn y(&self) -> T {
|
||||||
self.y
|
self.y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-8
@@ -1,3 +1,14 @@
|
|||||||
|
#![warn(
|
||||||
|
clippy::correctness,
|
||||||
|
clippy::nursery,
|
||||||
|
clippy::unnecessary_cast,
|
||||||
|
clippy::all,
|
||||||
|
clippy::suspicious,
|
||||||
|
clippy::perf,
|
||||||
|
rustdoc::missing_errors_doc,
|
||||||
|
rustdoc::missing_panics_doc
|
||||||
|
)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
|
|
||||||
@@ -10,13 +21,18 @@ extern crate proc_macro;
|
|||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn include_font(item: TokenStream) -> TokenStream {
|
pub fn include_font(item: TokenStream) -> TokenStream {
|
||||||
let filename = parse_macro_input!(item as LitStr);
|
let filename = parse_macro_input!(item as LitStr);
|
||||||
let file_path = filename.value().to_string();
|
let file_path = filename.value();
|
||||||
|
|
||||||
println!("Loading font: [{}]", file_path);
|
println!("Loading font: [{}]", file_path);
|
||||||
|
|
||||||
let font_data = match Font::new(load_file(file_path)) {
|
let font_bytes = match load_file(file_path) {
|
||||||
|
Ok(bytes) => bytes,
|
||||||
|
Err(why) => panic!("{}", why),
|
||||||
|
};
|
||||||
|
|
||||||
|
let font_data = match Font::new(font_bytes) {
|
||||||
Ok(font) => font.0,
|
Ok(font) => font.0,
|
||||||
Err(e) => panic!("{}", e),
|
Err(why) => panic!("{}", why),
|
||||||
};
|
};
|
||||||
|
|
||||||
quote!(
|
quote!(
|
||||||
@@ -34,7 +50,7 @@ struct Font([[u8; 16]; 512]);
|
|||||||
impl Font {
|
impl Font {
|
||||||
const MAGIC: u16 = 0x3604;
|
const MAGIC: u16 = 0x3604;
|
||||||
|
|
||||||
pub fn new(data: [u8; (32 + 2) * 512 + 4]) -> Result<Font, &'static str> {
|
pub fn new(data: [u8; (32 + 2) * 512 + 4]) -> Result<Self, &'static str> {
|
||||||
let magic: u16 = (data[0] as u16) << 8 | data[1] as u16;
|
let magic: u16 = (data[0] as u16) << 8 | data[1] as u16;
|
||||||
let mode = data[2];
|
let mode = data[2];
|
||||||
let size = data[3];
|
let size = data[3];
|
||||||
@@ -55,15 +71,29 @@ impl Font {
|
|||||||
glyphs[i] = buff;
|
glyphs[i] = buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Font(glyphs))
|
Ok(Self(glyphs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_file(filename: String) -> [u8; (32 + 2) * 512 + 4] {
|
type FileContents = [u8; (32 + 2) * 512 + 4];
|
||||||
|
fn load_file(filename: String) -> Result<FileContents, std::io::Error> {
|
||||||
let mut buf = [0; (32 + 2) * 512 + 4];
|
let mut buf = [0; (32 + 2) * 512 + 4];
|
||||||
let mut f = File::open(filename).unwrap();
|
let mut f = File::open(filename).unwrap();
|
||||||
f.seek(SeekFrom::Start(0)).unwrap();
|
f.seek(SeekFrom::Start(0)).unwrap();
|
||||||
f.read(&mut buf).unwrap();
|
|
||||||
|
|
||||||
return buf;
|
loop {
|
||||||
|
match f.read(&mut buf) {
|
||||||
|
Ok(read) => {
|
||||||
|
if read == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(why) => {
|
||||||
|
eprintln!("Failed to read PS1 font file: {}", why);
|
||||||
|
return Err(why);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user