diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/semantic/frame.rs | 44 | ||||
-rw-r--r-- | src/semantic/mod.rs | 2 | ||||
-rw-r--r-- | src/semantic/temp.rs | 26 |
3 files changed, 72 insertions, 0 deletions
diff --git a/src/semantic/frame.rs b/src/semantic/frame.rs new file mode 100644 index 0000000..ddfc330 --- /dev/null +++ b/src/semantic/frame.rs @@ -0,0 +1,44 @@ +use super::temp; + +pub enum Location { + InFrame { + offset: usize, + }, + Register(temp::TempName), +} + +pub enum Escape { + No, + Yes, +} + +pub trait Frame { + fn new(name: temp::TempLabel, formals: Vec<Escape>) -> Self; + fn name(&self) -> temp::TempLabel; + fn formals(&self) -> &[Location]; + fn alloc_local(&mut self, escapes: Escape) -> Location; +} + +pub struct Amd64Frame { + name: temp::TempLabel, +} + +impl Frame for Amd64Frame { + fn new(name: temp::TempLabel, formals: Vec<Escape>) -> Self { + Amd64Frame { + name, + } + } + + fn name(&self) -> temp::TempLabel { + self.name + } + + fn formals(&self) -> &[Location] { + unimplemented!(); + } + + fn alloc_local(&mut self, escapes: Escape) -> Location { + unimplemented!(); + } +} diff --git a/src/semantic/mod.rs b/src/semantic/mod.rs index e2edc24..afc56ef 100644 --- a/src/semantic/mod.rs +++ b/src/semantic/mod.rs @@ -4,5 +4,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. pub mod environment; +pub mod frame; +pub mod temp; pub mod translate; pub mod types; diff --git a/src/semantic/temp.rs b/src/semantic/temp.rs new file mode 100644 index 0000000..abd7e86 --- /dev/null +++ b/src/semantic/temp.rs @@ -0,0 +1,26 @@ +pub struct Temp { + counter: usize, +} + +#[derive(Copy,Clone,Debug,Eq,PartialEq)] +pub struct TempName(usize); +#[derive(Copy,Clone,Debug,Eq,PartialEq)] +pub struct TempLabel(usize); + +impl Temp { + pub fn new() -> Temp { + Temp { counter: 0 } + } + + pub fn next_name(&mut self) -> TempName { + let idx = self.counter; + self.counter += 1; + TempName(idx) + } + + pub fn next_label(&mut self) -> TempLabel { + let idx = self.counter; + self.counter += 1; + TempLabel(idx) + } +} |