-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7bb7a5
commit 39ce0ac
Showing
9 changed files
with
60 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod scope; | |
pub mod stmt; | ||
pub mod types; | ||
pub mod util; | ||
pub mod variables; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use super::{ | ||
analyze::ConstInitializer, | ||
types::{BaseType, Type}, | ||
}; | ||
|
||
#[derive(PartialOrd, Ord, PartialEq, Eq, Clone, Debug)] | ||
pub enum Var { | ||
GVar(GVar), | ||
LVar(LVar), | ||
EnumVariant(EnumVariant), | ||
} | ||
|
||
impl Var { | ||
pub fn ty(&self) -> Type { | ||
match self { | ||
Var::GVar(gvar) => gvar.ty.clone(), | ||
Var::LVar(lvar) => lvar.ty.clone(), | ||
Var::EnumVariant(_) => Type::Base(BaseType::Int), | ||
} | ||
} | ||
} | ||
|
||
#[derive(PartialOrd, Ord, PartialEq, Eq, Clone, Debug)] | ||
pub struct GVar { | ||
pub name: String, | ||
pub ty: Type, | ||
pub init: Option<ConstInitializer>, | ||
pub is_extern: bool, | ||
} | ||
|
||
#[derive(PartialOrd, Ord, PartialEq, Eq, Clone, Debug)] | ||
pub struct LVar { | ||
/// Used like `mov rax, [rbp - offset]` | ||
pub offset: usize, | ||
pub ty: Type, | ||
} | ||
|
||
impl LVar { | ||
pub const fn new_raw(offset: usize, ty: Type) -> Self { | ||
Self { offset, ty } | ||
} | ||
} | ||
|
||
#[derive(PartialOrd, Ord, PartialEq, Eq, Clone, Debug)] | ||
pub struct EnumVariant { | ||
pub name: String, | ||
pub value: usize, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters