Add all of the code gen, want to show it off

This commit is contained in:
2025-03-27 18:49:17 +02:00
parent f338f07e7d
commit 06d8c1b0f3
33 changed files with 1199 additions and 95 deletions

View File

@@ -4,12 +4,13 @@ use std::fmt::Display;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Ident(pub String);
impl ToString for Ident {
fn to_string(&self) -> String {
self.0.clone()
impl Display for Ident {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Number {
pub val: usize,
@@ -17,6 +18,24 @@ pub struct Number {
pub signed: bool,
}
impl Display for Number {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.base {
2 => write!(f, "{:#b}", self.val),
8 => write!(f, "{:#o}", self.val),
10 => {
if self.signed {
write!(f, "{}", self.val as isize)
} else {
write!(f, "{}", self.val as usize)
}
}
16 => write!(f, "{:#x}", self.val),
_ => unreachable!()
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct TString {
pub val: String,
@@ -24,7 +43,7 @@ pub struct TString {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Char(char);
pub struct Char(pub char);
impl Into<char> for Char {
fn into(self) -> char {