Add test of recursive object types (ha, work by default) and fix effect-walker bug revealed by it.

This commit is contained in:
Graydon Hoare 2010-06-25 12:15:40 -07:00
parent 422b8a6be4
commit c06ea8f944
2 changed files with 41 additions and 0 deletions

View File

@ -72,6 +72,7 @@ let function_effect_propagation_visitor
* - Calling a function with effect e lowers to e.
*)
let curr_fn = Stack.create () in
let visit_mod_item_pre n p i =
begin
match i.node.Ast.decl_item with
@ -80,16 +81,29 @@ let function_effect_propagation_visitor
end;
inner.Walk.visit_mod_item_pre n p i
in
let visit_mod_item_post n p i =
inner.Walk.visit_mod_item_post n p i;
match i.node.Ast.decl_item with
Ast.MOD_ITEM_fn _ -> ignore (Stack.pop curr_fn)
| _ -> ()
in
let visit_obj_fn_pre o i fi =
Stack.push fi.id curr_fn;
inner.Walk.visit_obj_fn_pre o i fi
in
let visit_obj_fn_post o i fi =
inner.Walk.visit_obj_fn_post o i fi;
ignore (Stack.pop curr_fn)
in
let visit_obj_drop_pre o b =
Stack.push b.id curr_fn;
inner.Walk.visit_obj_drop_pre o b
in
let visit_obj_drop_post o b =
inner.Walk.visit_obj_drop_post o b;
ignore (Stack.pop curr_fn);
@ -155,6 +169,8 @@ let function_effect_propagation_visitor
{ inner with
Walk.visit_mod_item_pre = visit_mod_item_pre;
Walk.visit_mod_item_post = visit_mod_item_post;
Walk.visit_obj_fn_pre = visit_obj_fn_pre;
Walk.visit_obj_fn_post = visit_obj_fn_post;
Walk.visit_obj_drop_pre = visit_obj_drop_pre;
Walk.visit_obj_drop_post = visit_obj_drop_post;
Walk.visit_stmt_pre = visit_stmt_pre }

View File

@ -0,0 +1,25 @@
type adder =
obj {
fn add();
};
obj leaf_adder(int x) {
fn add() {
log "leaf";
log x;
}
}
obj delegate_adder(adder a) {
fn add() {
a.add();
}
}
fn main() {
auto x =
delegate_adder
(delegate_adder
(delegate_adder
(leaf_adder(10))));
x.add();
}