goodness gracious it can do integer addition and pointer dereferencing!!!!

This commit is contained in:
Janis 2024-08-18 19:59:13 +02:00
parent 00359a306c
commit f7ec585057
5 changed files with 930 additions and 368 deletions

View file

@ -322,6 +322,13 @@ impl Type {
}
}
pub fn pointee(&self) -> Option<&Type> {
match self {
Self::Pointer { pointee, .. } => Some(&pointee),
_ => None,
}
}
pub fn equal_type(&self, rhs: &Self) -> Option<Type> {
match (self, rhs) {
(Self::ComptimeNumber, Self::Floating(_))

View file

@ -157,3 +157,13 @@ pub trait FallibleParse<I>: Iterator<Item = I> + Clone {
}
impl<I, T> FallibleParse<I> for T where T: Iterator<Item = I> + Clone {}
#[macro_export]
macro_rules! variant {
($value:expr => $pattern:pat) => {
let $pattern = $value else { unreachable!() };
};
($pattern:pat = $value:expr) => {
let $pattern = $value else { unreachable!() };
};
}

View file

@ -8,7 +8,7 @@
#![allow(unused_macros)]
pub mod ast;
pub mod codegen;
// pub mod codegen;
pub mod common;
pub mod error;
pub mod lexer;

View file

@ -10,6 +10,7 @@ use crate::{
string_table::{ImmOrIndex, Index, StringTable},
symbol_table::{SymbolKind, SymbolTable},
tokens::Token,
variant,
};
#[derive(Debug, thiserror::Error)]
@ -132,10 +133,12 @@ impl Tree {
}
}
pub fn global_decls(&self) -> impl Iterator<Item = (Node, String)> {
self.global_decls.iter().map(|decl| {
pub fn global_decls(&self) -> Vec<(Node, String)> {
self.global_decls
.iter()
.map(|decl| {
let name = match self.nodes.get_node(*decl) {
Tag::FunctionDecl { proto, body } => {
Tag::FunctionDecl { proto, .. } => {
let Tag::FunctionProto { name, .. } = self.nodes.get_node(*proto) else {
unreachable!()
};
@ -149,6 +152,7 @@ impl Tree {
};
(*decl, name)
})
.collect::<Vec<_>>()
}
#[allow(unused)]

File diff suppressed because it is too large Load diff