summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs2
-rw-r--r--src/semantic/analysis.rs15
-rw-r--r--src/semantic/translate.rs36
3 files changed, 40 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index a8114ac..e4b0cd5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,7 +13,7 @@ fn main() {
let stdin = io::stdin();
let mut handle = stdin.lock();
loop {
- let mut translate = semantic::translate::Translate::new();
+ let mut translate = semantic::translate::Translate::<semantic::frame::Amd64Frame>::new();
let mut input = String::new();
print!("taiga> ");
io::stdout().flush().unwrap();
diff --git a/src/semantic/analysis.rs b/src/semantic/analysis.rs
index edc229f..cf19351 100644
--- a/src/semantic/analysis.rs
+++ b/src/semantic/analysis.rs
@@ -5,6 +5,7 @@
use ::ast::{self, WithLocation};
use super::environment;
+use super::frame;
use super::translate::{self, Translate};
use super::types::{self, Ty};
@@ -25,8 +26,10 @@ pub enum TypeError {
type TypeEnvironment<'a> = environment::Environment<'a, String, Ty>;
pub type Result<T> = ::std::result::Result<T, WithLocation<TypeError>>;
-pub fn translate(translate: &mut Translate, program: &ast::Program)
- -> Result<(translate::Expression, Ty)> {
+pub fn translate<F: frame::Frame>(
+ translate: &mut Translate<F>,
+ program: &ast::Program)
+ -> Result<(translate::Expression, Ty)> {
let mut venv = TypeEnvironment::new(None);
let mut tenv = TypeEnvironment::new(None);
tenv.add_binding("int".into(), Ty::Int);
@@ -65,8 +68,8 @@ fn trans_ty<'a>(
}
}
-fn trans_decl<'a>(
- tr: &mut Translate,
+fn trans_decl<'a, F: frame::Frame>(
+ tr: &mut Translate<F>,
venv: &mut TypeEnvironment<'a>,
tenv: &mut TypeEnvironment<'a>,
decl: &WithLocation<ast::Declaration>) -> Result<Ty> {
@@ -119,8 +122,8 @@ fn trans_decl<'a>(
}
}
-fn trans_exp<'a>(
- tr: &mut Translate,
+fn trans_exp<'a, F: frame::Frame>(
+ tr: &mut Translate<F>,
venv: &mut TypeEnvironment<'a>,
tenv: &mut TypeEnvironment<'a>,
exp: &WithLocation<ast::Expression>)
diff --git a/src/semantic/translate.rs b/src/semantic/translate.rs
index cc5aec0..179eb62 100644
--- a/src/semantic/translate.rs
+++ b/src/semantic/translate.rs
@@ -1,4 +1,6 @@
+use super::frame;
use super::ir;
+use super::temp;
#[derive(Debug)]
pub enum Expression {
@@ -6,18 +8,40 @@ pub enum Expression {
Void(ir::Statement),
}
-pub struct Translate {
-
+pub struct Translate<F> {
+ level_counter: usize,
+ _frametype: ::std::marker::PhantomData<F>,
}
-pub enum Level {
+pub enum Level<'a, F>
+ where F: 'a + frame::Frame {
Top,
- Level,
+ Level {
+ parent: &'a Level<'a, F>,
+ frame: F,
+ unique_id: usize,
+ },
}
-impl Translate {
- pub fn new() -> Translate {
+impl<F: frame::Frame> Translate<F> {
+ pub fn new() -> Translate<F> {
Translate {
+ level_counter: 0,
+ _frametype: ::std::marker::PhantomData,
+ }
+ }
+
+ pub fn make_level<'a>(
+ &mut self,
+ parent: &'a Level<F>,
+ name: temp::TempLabel,
+ formals: Vec<frame::Escape>) -> Level<'a, F> {
+ let id = self.level_counter;
+ self.level_counter += 1;
+ Level::Level {
+ parent: parent,
+ frame: F::new(name, formals),
+ unique_id: id,
}
}