Skip to content

Commit 6f9f6fb

Browse files
committed
WIP: debugging bugs with polymorphism
1 parent fb346be commit 6f9f6fb

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

tiger/src/asm_gen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<F: Frame> Gen<F> {
9898
// Error cases:
9999
Exp::Error | Exp::ExpSequence(_, _) | Exp::BinOp { left: box Exp::Error, .. }
100100
| Exp::BinOp { right: box Exp::Error, .. } | Exp::BinOp { right: box Exp::Name(_), .. }
101-
=> unreachable!(),
101+
=> unreachable!("{:?}", expr),
102102

103103
Exp::BinOp { op: BinOp::Plus, left: box Exp::Name(label), right } => {
104104
let instruction = Instruction::Move {

tiger/src/semant.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ impl<'a, F: Clone + Debug + Frame + PartialEq> SemanticAnalyzer<'a, F> {
181181
fn actual_ty(&self, typ: &Type) -> Type {
182182
match *typ {
183183
Type::Var(ref type_var) => {
184+
println!("1: {:?}: {}", typ, self.symbols.name(type_var.0));
184185
if let Some(actual_type) = self.env.look_type(type_var.0) {
186+
println!("2");
185187
if typ != actual_type {
188+
println!("3");
186189
return self.actual_ty(actual_type);
187190
}
188191
}
@@ -959,10 +962,16 @@ impl<'a, F: Clone + Debug + Frame + PartialEq> SemanticAnalyzer<'a, F> {
959962
}
960963
self.unexpected_field(ident, ident.pos, record_type)
961964
},
962-
_ => EXP_TYPE_ERROR,
965+
_ => {
966+
panic!();
967+
EXP_TYPE_ERROR
968+
},
963969
}
964970
},
965-
Type::Error => EXP_TYPE_ERROR,
971+
Type::Error => {
972+
panic!();
973+
EXP_TYPE_ERROR
974+
},
966975
typ => {
967976
self.add_error(Error::NotARecordOrClass {
968977
pos: this.pos,
@@ -1284,7 +1293,10 @@ impl<'a, F: Clone + Debug + Frame + PartialEq> SemanticAnalyzer<'a, F> {
12841293
ty: self.actual_ty(&types[0]),
12851294
}
12861295
},
1287-
_ => EXP_TYPE_ERROR,
1296+
_ => {
1297+
panic!();
1298+
EXP_TYPE_ERROR
1299+
},
12881300
}
12891301
},
12901302
Type::Error => EXP_TYPE_ERROR,

tiger/tests/polymorphism.tig

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ let type list<e> = {
33
tail: list<e>
44
}
55

6+
type MyStruct = {
7+
a: int,
8+
b: int,
9+
c: int
10+
}
11+
612
function append<e>(a: list<e>, b: list<e>): list<e> =
713
if a = nil then
814
b
@@ -37,11 +43,32 @@ let type list<e> = {
3743
first = 4,
3844
second = 2
3945
}
46+
var struct_pair := pair::<MyStruct> {
47+
first = MyStruct {
48+
a = 1,
49+
b = 2,
50+
c = 3
51+
},
52+
second = MyStruct {
53+
a = 4,
54+
b = 5,
55+
c = 6
56+
}
57+
}
58+
/* FIXME: this doesn't parse: */
59+
/*var nested_list := list<list<int>> {
60+
head = two4s,
61+
tail = nil
62+
}*/
4063

4164
in
4265
print(string_pair.second);
4366
print("\n");
44-
printi(two4s.head)
67+
printi(two4s.head);
68+
let var second := struct_pair.second
69+
in
70+
printi(second.c)
71+
end
4572
/* TODO: correct code generation (monomorphisation) for polymorphic code. */
4673
/*f(string_pair); /* Should be an error. */ */
4774
/*f(my_two_some) /* Should be an error. */ */

0 commit comments

Comments
 (0)