Skip to content

Commit

Permalink
refactor: remove repeating types & move module code to mod.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
MilkeeyCat committed Dec 28, 2024
1 parent 1bb6e16 commit bf4fb60
Show file tree
Hide file tree
Showing 13 changed files with 1,371 additions and 1,593 deletions.
6 changes: 2 additions & 4 deletions src/codegen/amd64_asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ mod register;

use super::Codegen;
use crate::{
ir::{
Block, Expr, ExprKind, ExprLit, Id, IntTy, Item, ItemFn, Node, Stmt, Ty, UintTy, Variable,
},
parser::{BinOp, BitwiseOp, CmpOp, OpParseError, UnOp},
ir::{Block, Expr, ExprKind, ExprLit, Id, Item, ItemFn, Node, Stmt, Ty, Variable},
parser::{BinOp, BitwiseOp, CmpOp, IntTy, OpParseError, UintTy, UnOp},
Context,
};
use allocator::RegisterAllocator;
Expand Down
2 changes: 1 addition & 1 deletion src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::parser::{BinOp, UnOp};
use bumpalo::Bump;

pub use ordered_map::OrderedMap;
pub use types::{IntTy, Ty, TyArray, UintTy};
pub use types::{Ty, TyArray};

#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash)]
pub struct Id {
Expand Down
47 changes: 4 additions & 43 deletions src/ir/types.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use crate::ty_problem;
use crate::{
parser::{IntTy, UintTy},
ty_problem,
};

#[derive(Debug, PartialEq)]
pub struct TyArray<'ir> {
pub ty: &'ir Ty<'ir>,
pub len: usize,
}

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Hash)]
pub enum IntTy {
I8,
I16,
I32,
I64,
Isize,
}

impl IntTy {
fn size(&self) -> Option<usize> {
Some(match self {
Expand All @@ -27,27 +21,6 @@ impl IntTy {
}
}

impl std::fmt::Display for IntTy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::I8 => write!(f, "i8"),
Self::I16 => write!(f, "i16"),
Self::I32 => write!(f, "i32"),
Self::I64 => write!(f, "i64"),
Self::Isize => write!(f, "isize"),
}
}
}

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Hash)]
pub enum UintTy {
U8,
U16,
U32,
U64,
Usize,
}

impl UintTy {
fn size(&self) -> Option<usize> {
Some(match self {
Expand All @@ -70,18 +43,6 @@ impl UintTy {
}
}

impl std::fmt::Display for UintTy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::U8 => write!(f, "u8"),
Self::U16 => write!(f, "u16"),
Self::U32 => write!(f, "u32"),
Self::U64 => write!(f, "u64"),
Self::Usize => write!(f, "usize"),
}
}
}

#[derive(Debug, PartialEq)]
pub enum Ty<'ir> {
Void,
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum LexerError {
pub enum Error {
#[error("Failed to parse char {0}")]
UnknownCharacter(char),
}
Loading

0 comments on commit bf4fb60

Please sign in to comment.