Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tiger/gc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(( i = 1 ))

files=(array array_assignment comments conditions escapes functions gc hello hello1 hello2 hello3 hello5 integers lib loops merge nested prettyprint queens record spill strings vars)
files=(comments conditions escapes functional functions gc hello hello1 hello2 hello3 hello5 integers lib merge nested pure pureClosure pureTree record spill strings vars)

while true; do
echo "******************************"
Expand Down
38 changes: 19 additions & 19 deletions tiger/src/asm_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,6 @@ impl<F: Frame> Gen<F> {
self.emit(instruction);
},
Exp::BinOp { op: BinOp::Div, left: expr, right: box Exp::Const(num) } => {
let instruction = Instruction::Move {
assembly: "mov 'd0, 0".to_string(),
source: vec![],
destination: vec![X86_64::rdx()],
stack_destination: vec![],
stack_source: vec![],
};
self.emit(instruction);
let instruction = Instruction::Move {
assembly: "mov 'd0, 's0".to_string(),
source: vec![self.munch_expression(*expr)],
Expand All @@ -288,6 +280,14 @@ impl<F: Frame> Gen<F> {
stack_source: vec![],
};
self.emit(instruction);
let instruction = Instruction::Move {
assembly: "cqo".to_string(),
source: vec![X86_64::rax()],
destination: vec![X86_64::rdx()],
stack_destination: vec![],
stack_source: vec![],
};
self.emit(instruction);
let instruction = Instruction::Operation {
assembly: "idiv 's0".to_string(),
source: vec![immediate, X86_64::rax(), X86_64::rdx()],
Expand All @@ -308,17 +308,17 @@ impl<F: Frame> Gen<F> {
},
Exp::BinOp { op: BinOp::Div, left: box Exp::Const(num), right: expr } => {
let instruction = Instruction::Move {
assembly: "mov 'd0, 0".to_string(),
assembly: format!("mov 'd0, {}", num),
source: vec![],
destination: vec![X86_64::rdx()],
destination: vec![X86_64::rax()],
stack_destination: vec![],
stack_source: vec![],
};
self.emit(instruction);
let instruction = Instruction::Move {
assembly: format!("mov 'd0, {}", num),
source: vec![],
destination: vec![X86_64::rax()],
assembly: "cqo".to_string(),
source: vec![X86_64::rax()],
destination: vec![X86_64::rdx()],
stack_destination: vec![],
stack_source: vec![],
};
Expand Down Expand Up @@ -546,17 +546,17 @@ impl<F: Frame> Gen<F> {
},
Exp::BinOp { op: BinOp::Div, left, right } => {
let instruction = Instruction::Move {
assembly: "mov 'd0, 0".to_string(),
source: vec![],
destination: vec![X86_64::rdx()],
assembly: "mov 'd0, 's0".to_string(),
source: vec![self.munch_expression(*left)],
destination: vec![X86_64::rax()],
stack_destination: vec![],
stack_source: vec![],
};
self.emit(instruction);
let instruction = Instruction::Move {
assembly: "mov 'd0, 's0".to_string(),
source: vec![self.munch_expression(*left)],
destination: vec![X86_64::rax()],
assembly: "cqo".to_string(),
source: vec![X86_64::rax()],
destination: vec![X86_64::rdx()],
stack_destination: vec![],
stack_source: vec![],
};
Expand Down
33 changes: 1 addition & 32 deletions tiger/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@

use position::WithPos;
use symbol::{Symbol, SymbolWithPos};
use temp::Label;

#[allow(clippy::enum_variant_names)]
#[derive(Clone, Debug, PartialEq)]
pub enum Declaration {
ClassDeclaration {
declarations: Vec<DeclarationWithPos>,
name: SymbolWithPos,
parent_class: SymbolWithPos,
},
Function(Vec<FuncDeclarationWithPos>),
Type(Vec<TypeDecWithPos>),
VariableDeclaration {
Expand All @@ -50,19 +44,14 @@ pub enum Expr {
size: Box<ExprWithPos>,
typ: SymbolWithPos,
},
Assign {
expr: Box<ExprWithPos>,
var: Box<ExprWithPos>,
},
Break,
Call {
args: Vec<ExprWithPos>,
function: Box<ExprWithPos>,
},
Closure {
body: Box<ExprWithPos>,
name: SymbolWithPos,
params: Vec<FieldWithPos>,
pure: bool,
result: Option<SymbolWithPos>,
},
ClosureParamField {
Expand All @@ -76,9 +65,6 @@ pub enum Expr {
ident: SymbolWithPos,
this: Box<ExprWithPos>,
},
FunctionPointer {
label: Label,
},
FunctionPointerCall {
args: Vec<ExprWithPos>,
closure_name: Symbol,
Expand All @@ -96,14 +82,6 @@ pub enum Expr {
body: Box<ExprWithPos>,
declarations: Vec<DeclarationWithPos>,
},
MethodCall {
args: Vec<ExprWithPos>,
method: SymbolWithPos,
this: Box<ExprWithPos>,
},
New {
class_name: SymbolWithPos,
},
Nil,
Oper {
left: Box<ExprWithPos>,
Expand All @@ -123,10 +101,6 @@ pub enum Expr {
this: Box<ExprWithPos>,
},
Variable(SymbolWithPos),
While {
body: Box<ExprWithPos>,
test: Box<ExprWithPos>,
},
}

pub type ExprWithPos = WithPos<Expr>;
Expand All @@ -145,7 +119,6 @@ pub struct FuncDeclaration {
pub body: ExprWithPos,
pub name: SymbolWithPos,
pub params: Vec<FieldWithPos>,
pub pure: bool,
pub result: Option<SymbolWithPos>,
}

Expand Down Expand Up @@ -204,7 +177,3 @@ pub struct TypeDec {
pub type TypeDecWithPos = WithPos<TypeDec>;

pub type TyWithPos = WithPos<Ty>;

pub fn dummy_var_expr(symbol: Symbol) -> ExprWithPos {
WithPos::dummy(Expr::Variable(WithPos::dummy(symbol)))
}
49 changes: 0 additions & 49 deletions tiger/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use std::ptr;

use data_layout::{
ARRAY_DATA_LAYOUT_SIZE,
CLASS_DATA_LAYOUT_SIZE,
RECORD_DATA_LAYOUT_SIZE,
STRING_DATA_LAYOUT_SIZE,
STRING_TYPE,
Expand All @@ -42,14 +41,12 @@ const SHOW_STATS: bool = false;
#[derive(Debug)]
pub enum Layout {
Array(usize, bool),
Class(*const c_char),
Record(*const c_char),
String(usize),
}

const ARRAY_TYPE: usize = 0;
const RECORD_TYPE: usize = 1;
const CLASS_TYPE: usize = 3;

impl Layout {
fn write_repr(&self, mut ptr: *mut usize) {
Expand All @@ -62,11 +59,6 @@ impl Layout {
ptr = ptr.offset(1);
ptr::write(ptr, is_pointer as usize);
},
Layout::Class(data_layout) => {
ptr::write(ptr, CLASS_TYPE);
ptr = ptr.offset(1);
ptr::write(ptr, data_layout as usize)
},
Layout::Record(data_layout) => {
ptr::write(ptr, RECORD_TYPE);
ptr = ptr.offset(1);
Expand All @@ -84,12 +76,6 @@ impl Layout {
fn size(&self) -> usize {
match *self {
Layout::Array(length, _) => (length + ARRAY_DATA_LAYOUT_SIZE) * WORD_SIZE,
Layout::Class(data_layout) => {
let string_ptr = string_offset(data_layout);
let fields = unsafe { CStr::from_ptr(string_ptr) };
let field_count = fields.to_bytes().len() + CLASS_DATA_LAYOUT_SIZE;
field_count * WORD_SIZE
},
Layout::Record(data_layout) => {
let string_ptr = string_offset(data_layout);
let fields = unsafe { CStr::from_ptr(string_ptr) };
Expand Down Expand Up @@ -233,14 +219,6 @@ impl Collector {
}
}
},
CLASS_TYPE => {
for (i, &field_layout) in record_layout(pointer).iter().enumerate() {
if field_layout == b'p' {
let field = class_field(pointer, i);
self.dfs(field);
}
}
},
RECORD_TYPE => {
for (i, &field_layout) in record_layout(pointer).iter().enumerate() {
if field_layout == b'p' {
Expand Down Expand Up @@ -281,17 +259,6 @@ impl Collector {
}
}
},
CLASS_TYPE => {
for (i, &field_layout) in record_layout(pointer).iter().enumerate() {
if field_layout == b'p' {
let field = class_field(pointer, i);
if self.in_heap(field) {
locations.insert(class_field_address(pointer, i) as usize, field);
self.dfs_locations(field, locations);
}
}
}
},
RECORD_TYPE => {
for (i, &field_layout) in record_layout(pointer).iter().enumerate() {
if field_layout == b'p' {
Expand Down Expand Up @@ -437,19 +404,6 @@ fn fetch_pointer_map() -> HashMap<usize, Vec<Stack>> {
pointer_map
}

fn class_field(ptr: usize, index: usize) -> usize {
unsafe {
ptr::read_unaligned(class_field_address(ptr, index))
}
}

fn class_field_address(ptr: usize, index: usize) -> *const usize {
let ptr = ptr as *const usize;
unsafe {
ptr.add(index + CLASS_DATA_LAYOUT_SIZE)
}
}

fn field(ptr: usize, index: usize) -> usize {
unsafe {
ptr::read_unaligned(field_address(ptr, index))
Expand Down Expand Up @@ -484,9 +438,6 @@ fn size_of(ptr: usize) -> usize {
let ptr = ptr.offset(1);
ptr::read_unaligned(ptr) + ARRAY_DATA_LAYOUT_SIZE * WORD_SIZE
},
CLASS_TYPE => {
(field_count(ptr as usize) + CLASS_DATA_LAYOUT_SIZE) * WORD_SIZE
},
RECORD_TYPE => {
(field_count(ptr as usize) + RECORD_DATA_LAYOUT_SIZE) * WORD_SIZE
},
Expand Down
3 changes: 0 additions & 3 deletions tiger/src/data_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
// Type, Size, Is pointer.
pub const ARRAY_DATA_LAYOUT_SIZE: usize = 3;

// Type, String of is pointer, Vtable pointer.
pub const CLASS_DATA_LAYOUT_SIZE: usize = 3;

// Type, String of is pointer.
pub const RECORD_DATA_LAYOUT_SIZE: usize = 2;

Expand Down
Loading