From 70bf54bcac587c0bc8a3a593bda75115e4c23aa8 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 1 Feb 2011 16:23:48 -0800 Subject: Implement 'else if' --- src/comp/middle/fold.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 67c26014..7e6839a8 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -28,6 +28,7 @@ import front.ast.def; import front.ast.def_id; import front.ast.ann; +import std._uint; import std._vec; type ast_fold[ENV] = @@ -100,6 +101,7 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, @expr cond, &block thn, + &vec[tup(@expr, block)] elifs, &option.t[block] els, ann a) -> @expr) fold_expr_if, @@ -501,9 +503,19 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { ret fld.fold_expr_cast(env_, e.span, ee, tt, at); } - case (ast.expr_if(?cnd, ?thn, ?els, ?t)) { + case (ast.expr_if(?cnd, ?thn, ?elifs, ?els, ?t)) { auto ccnd = fold_expr(env_, fld, cnd); auto tthn = fold_block(env_, fld, thn); + + let vec[tup(@ast.expr, ast.block)] eelifs = vec(); + for (tup(@expr, block) elif in elifs) { + auto elifcnd = elif._0; + auto elifthn = elif._1; + auto elifccnd = fold_expr(env_, fld, elifcnd); + auto eliftthn = fold_block(env_, fld, elifthn); + eelifs += tup(elifccnd, eliftthn); + } + auto eels = none[block]; alt (els) { case (some[block](?b)) { @@ -511,7 +523,7 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { } case (_) { /* fall through */ } } - ret fld.fold_expr_if(env_, e.span, ccnd, tthn, eels, t); + ret fld.fold_expr_if(env_, e.span, ccnd, tthn, eelifs, eels, t); } case (ast.expr_for(?decl, ?seq, ?body, ?t)) { @@ -961,8 +973,9 @@ fn identity_fold_expr_cast[ENV](&ENV env, &span sp, @ast.expr e, fn identity_fold_expr_if[ENV](&ENV env, &span sp, @expr cond, &block thn, + &vec[tup(@expr, block)] elifs, &option.t[block] els, ann a) -> @expr { - ret @respan(sp, ast.expr_if(cond, thn, els, a)); + ret @respan(sp, ast.expr_if(cond, thn, elifs, els, a)); } fn identity_fold_expr_for[ENV](&ENV env, &span sp, @@ -1237,7 +1250,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_expr_unary = bind identity_fold_expr_unary[ENV](_,_,_,_,_), fold_expr_lit = bind identity_fold_expr_lit[ENV](_,_,_,_), fold_expr_cast = bind identity_fold_expr_cast[ENV](_,_,_,_,_), - fold_expr_if = bind identity_fold_expr_if[ENV](_,_,_,_,_,_), + fold_expr_if = bind identity_fold_expr_if[ENV](_,_,_,_,_,_,_), fold_expr_for = bind identity_fold_expr_for[ENV](_,_,_,_,_,_), fold_expr_while = bind identity_fold_expr_while[ENV](_,_,_,_,_), fold_expr_do_while -- cgit v1.2.3 From 4b06dc574ba7d3ae50795cbe4f10d4be6e9c64a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Tue, 1 Feb 2011 13:40:04 -0500 Subject: Add very minimal support for native modules. For now they must be empty. --- src/comp/middle/fold.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 7e6839a8..2426d8ae 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -196,6 +196,9 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, ident ident, &ast._mod m, def_id id) -> @item) fold_item_mod, + (fn(&ENV e, &span sp, ident ident, + &ast.native_mod m, def_id id) -> @item) fold_item_native_mod, + (fn(&ENV e, &span sp, ident ident, @ty t, vec[ast.ty_param] ty_params, def_id id, ann a) -> @item) fold_item_ty, @@ -229,6 +232,8 @@ type ast_fold[ENV] = (fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod, + (fn(&ENV e, &ast.native_mod m) -> ast.native_mod) fold_native_mod, + (fn(&ENV e, &span sp, &ast._mod m) -> @ast.crate) fold_crate, @@ -780,6 +785,11 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item { ret fld.fold_item_mod(env_, i.span, ident, mm_, id); } + case (ast.item_native_mod(?ident, ?mm, ?id)) { + let ast.native_mod mm_ = fold_native_mod[ENV](env_, fld, mm); + ret fld.fold_item_native_mod(env_, i.span, ident, mm_, id); + } + case (ast.item_ty(?ident, ?ty, ?params, ?id, ?ann)) { let @ast.ty ty_ = fold_ty[ENV](env_, fld, ty); ret fld.fold_item_ty(env_, i.span, ident, ty_, params, id, ann); @@ -810,7 +820,6 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item { fail; } - fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod { let vec[@view_item] view_items = vec(); @@ -830,7 +839,12 @@ fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod { } ret fld.fold_mod(e, rec(view_items=view_items, items=items, index=index)); - } +} + +fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld, + &ast.native_mod m) -> ast.native_mod { + ret fld.fold_native_mod(e, rec(native_name = m.native_name)); +} fn fold_crate[ENV](&ENV env, ast_fold[ENV] fld, @ast.crate c) -> @ast.crate { let ENV env_ = fld.update_env_for_crate(env, c); @@ -1105,6 +1119,11 @@ fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i, ret @respan(sp, ast.item_mod(i, m, id)); } +fn identity_fold_item_native_mod[ENV](&ENV e, &span sp, ident i, + &ast.native_mod m, def_id id) -> @item { + ret @respan(sp, ast.item_native_mod(i, m, id)); +} + fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i, @ty t, vec[ast.ty_param] ty_params, def_id id, ann a) -> @item { @@ -1159,6 +1178,11 @@ fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod { ret m; } +fn identity_fold_native_mod[ENV](&ENV e, + &ast.native_mod m) -> ast.native_mod { + ret m; +} + fn identity_fold_crate[ENV](&ENV e, &span sp, &ast._mod m) -> @ast.crate { ret @respan(sp, rec(module=m)); } @@ -1281,6 +1305,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_), fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_), fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_), + fold_item_native_mod = + bind identity_fold_item_native_mod[ENV](_,_,_,_,_), fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_,_), fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_), fold_item_obj = bind identity_fold_item_obj[ENV](_,_,_,_,_,_,_), @@ -1293,6 +1319,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_block = bind identity_fold_block[ENV](_,_,_), fold_fn = bind identity_fold_fn[ENV](_,_,_,_,_,_), fold_mod = bind identity_fold_mod[ENV](_,_), + fold_native_mod = bind identity_fold_native_mod[ENV](_,_), fold_crate = bind identity_fold_crate[ENV](_,_,_), fold_obj = bind identity_fold_obj[ENV](_,_,_), -- cgit v1.2.3 From dd3ed6139a6fc6fda15403d0b5679535959945e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Wed, 2 Feb 2011 10:43:57 -0500 Subject: Add most of the plumbing for native items and add support for parsing native type declarations. --- src/comp/middle/fold.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 2426d8ae..b9027836 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -20,6 +20,7 @@ import front.ast.block; import front.ast.item; import front.ast.view_item; import front.ast.meta_item; +import front.ast.native_item; import front.ast.arg; import front.ast.pat; import front.ast.decl; @@ -203,6 +204,9 @@ type ast_fold[ENV] = @ty t, vec[ast.ty_param] ty_params, def_id id, ann a) -> @item) fold_item_ty, + (fn(&ENV e, &span sp, ident ident, + def_id id) -> @native_item) fold_native_item_ty, + (fn(&ENV e, &span sp, ident ident, vec[ast.variant] variants, vec[ast.ty_param] ty_params, @@ -244,6 +248,7 @@ type ast_fold[ENV] = // Env updates. (fn(&ENV e, @ast.crate c) -> ENV) update_env_for_crate, (fn(&ENV e, @item i) -> ENV) update_env_for_item, + (fn(&ENV e, @native_item i) -> ENV) update_env_for_native_item, (fn(&ENV e, @view_item i) -> ENV) update_env_for_view_item, (fn(&ENV e, &block b) -> ENV) update_env_for_block, (fn(&ENV e, @stmt s) -> ENV) update_env_for_stmt, @@ -841,9 +846,34 @@ fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod { ret fld.fold_mod(e, rec(view_items=view_items, items=items, index=index)); } +fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld, + @native_item i) -> @native_item { + let ENV env_ = fld.update_env_for_native_item(env, i); + + if (!fld.keep_going(env_)) { + ret i; + } + alt (i.node) { + case (ast.native_item_ty(?ident, ?id)) { + ret fld.fold_native_item_ty(env_, i.span, ident, id); + } + } +} + fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast.native_mod m) -> ast.native_mod { - ret fld.fold_native_mod(e, rec(native_name = m.native_name)); + let vec[@native_item] items = vec(); + auto index = new_str_hash[@ast.native_item](); + + for (@native_item i in m.items) { + auto new_item = fold_native_item[ENV](e, fld, i); + append[@native_item](items, new_item); + ast.index_native_item(index, new_item); + } + + ret fld.fold_native_mod(e, rec(native_name=m.native_name, + items=items, + index=index)); } fn fold_crate[ENV](&ENV env, ast_fold[ENV] fld, @ast.crate c) -> @ast.crate { @@ -1130,6 +1160,11 @@ fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i, ret @respan(sp, ast.item_ty(i, t, ty_params, id, a)); } +fn identity_fold_native_item_ty[ENV](&ENV e, &span sp, ident i, + def_id id) -> @native_item { + ret @respan(sp, ast.native_item_ty(i, id)); +} + fn identity_fold_item_tag[ENV](&ENV e, &span sp, ident i, vec[ast.variant] variants, vec[ast.ty_param] ty_params, @@ -1204,6 +1239,10 @@ fn identity_update_env_for_item[ENV](&ENV e, @item i) -> ENV { ret e; } +fn identity_update_env_for_native_item[ENV](&ENV e, @native_item i) -> ENV { + ret e; +} + fn identity_update_env_for_view_item[ENV](&ENV e, @view_item i) -> ENV { ret e; } @@ -1308,6 +1347,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_item_native_mod = bind identity_fold_item_native_mod[ENV](_,_,_,_,_), fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_,_), + fold_native_item_ty = + bind identity_fold_native_item_ty[ENV](_,_,_,_), fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_), fold_item_obj = bind identity_fold_item_obj[ENV](_,_,_,_,_,_,_), @@ -1325,6 +1366,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { update_env_for_crate = bind identity_update_env_for_crate[ENV](_,_), update_env_for_item = bind identity_update_env_for_item[ENV](_,_), + update_env_for_native_item = + bind identity_update_env_for_native_item[ENV](_,_), update_env_for_view_item = bind identity_update_env_for_view_item[ENV](_,_), update_env_for_block = bind identity_update_env_for_block[ENV](_,_), -- cgit v1.2.3 From 57bb9d809bb029caf7b38042a433153bb965e1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 4 Feb 2011 11:10:04 -0500 Subject: Parse function declarations. --- src/comp/middle/fold.rs | 60 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 14 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index b9027836..688d21d2 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -10,6 +10,7 @@ import util.common.ty_mach; import util.common.append; import front.ast; +import front.ast.fn_decl; import front.ast.ident; import front.ast.path; import front.ast.mutability; @@ -194,6 +195,11 @@ type ast_fold[ENV] = vec[ast.ty_param] ty_params, def_id id, ann a) -> @item) fold_item_fn, + (fn(&ENV e, &span sp, ident ident, + &ast.fn_decl decl, + vec[ast.ty_param] ty_params, + def_id id) -> @native_item) fold_native_item_fn, + (fn(&ENV e, &span sp, ident ident, &ast._mod m, def_id id) -> @item) fold_item_mod, @@ -229,10 +235,13 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, &ast.block_) -> block) fold_block, - (fn(&ENV e, ast.effect effect, + (fn(&ENV e, &fn_decl decl, bool is_iter, + &block body) -> ast._fn) fold_fn, + + (fn(&ENV e, ast.effect effect, vec[arg] inputs, - @ty output, &block body) -> ast._fn) fold_fn, + @ty output) -> ast.fn_decl) fold_fn_decl, (fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod, @@ -688,17 +697,22 @@ fn fold_arg[ENV](&ENV env, ast_fold[ENV] fld, &arg a) -> arg { ret rec(ty=ty with a); } - -fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn { - +fn fold_fn_decl[ENV](&ENV env, ast_fold[ENV] fld, + &ast.fn_decl decl) -> ast.fn_decl { let vec[ast.arg] inputs = vec(); - for (ast.arg a in f.inputs) { + for (ast.arg a in decl.inputs) { inputs += fold_arg(env, fld, a); } - auto output = fold_ty[ENV](env, fld, f.output); + auto output = fold_ty[ENV](env, fld, decl.output); + ret fld.fold_fn_decl(env, decl.effect, inputs, output); +} + +fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn { + auto decl = fold_fn_decl(env, fld, f.decl); + auto body = fold_block[ENV](env, fld, f.body); - ret fld.fold_fn(env, f.effect, f.is_iter, inputs, output, body); + ret fld.fold_fn(env, decl, f.is_iter, body); } @@ -857,6 +871,10 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld, case (ast.native_item_ty(?ident, ?id)) { ret fld.fold_native_item_ty(env_, i.span, ident, id); } + case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id)) { + ret fld.fold_native_item_fn(env_, i.span, ident, fn_decl, + ty_params, id); + } } } @@ -1144,6 +1162,13 @@ fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i, ret @respan(sp, ast.item_fn(i, f, ty_params, id, a)); } +fn identity_fold_native_item_fn[ENV](&ENV e, &span sp, ident i, + &ast.fn_decl decl, + vec[ast.ty_param] ty_params, + def_id id) -> @native_item { + ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id)); +} + fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i, &ast._mod m, def_id id) -> @item { ret @respan(sp, ast.item_mod(i, m, id)); @@ -1199,14 +1224,18 @@ fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block { ret respan(sp, blk); } +fn identity_fold_fn_decl[ENV](&ENV e, + ast.effect effect, + vec[arg] inputs, + @ty output) -> ast.fn_decl { + ret rec(effect=effect, inputs=inputs, output=output); +} + fn identity_fold_fn[ENV](&ENV e, - ast.effect effect, + &fn_decl decl, bool is_iter, - vec[arg] inputs, - @ast.ty output, &block body) -> ast._fn { - ret rec(effect=effect, is_iter=is_iter, inputs=inputs, - output=output, body=body); + ret rec(decl=decl, is_iter=is_iter, body=body); } fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod { @@ -1343,6 +1372,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_), fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_), + fold_native_item_fn = + bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_), fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_), fold_item_native_mod = bind identity_fold_item_native_mod[ENV](_,_,_,_,_), @@ -1358,7 +1389,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { bind identity_fold_view_item_import[ENV](_,_,_,_,_,_), fold_block = bind identity_fold_block[ENV](_,_,_), - fold_fn = bind identity_fold_fn[ENV](_,_,_,_,_,_), + fold_fn = bind identity_fold_fn[ENV](_,_,_,_), + fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_), fold_mod = bind identity_fold_mod[ENV](_,_), fold_native_mod = bind identity_fold_native_mod[ENV](_,_), fold_crate = bind identity_fold_crate[ENV](_,_,_), -- cgit v1.2.3 From 580d527aa2972ad1f7cbe65f2a98a0dbc92d14f7 Mon Sep 17 00:00:00 2001 From: Rafael Avila de Espindola Date: Thu, 10 Feb 2011 14:32:22 -0500 Subject: Add missing fold of native functions. --- src/comp/middle/fold.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 688d21d2..7e5c2d26 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -872,7 +872,8 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld, ret fld.fold_native_item_ty(env_, i.span, ident, id); } case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id)) { - ret fld.fold_native_item_fn(env_, i.span, ident, fn_decl, + auto d = fold_fn_decl[ENV](env_, fld, fn_decl); + ret fld.fold_native_item_fn(env_, i.span, ident, d, ty_params, id); } } -- cgit v1.2.3 From 378c0087ca7572cd17726c704fe04d57bf4687af Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 30 Jan 2011 17:18:19 -0500 Subject: Parse 'be' statement. Pass tailcall tests. No actual tailcalls yet. --- src/comp/middle/fold.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 7e5c2d26..9194f734 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -176,6 +176,9 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, &option.t[@expr] rv) -> @stmt) fold_stmt_ret, + (fn(&ENV e, &span sp, + @expr e) -> @stmt) fold_stmt_be, + (fn(&ENV e, &span sp, @expr e) -> @stmt) fold_stmt_log, @@ -636,6 +639,11 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt { ret fld.fold_stmt_ret(env_, s.span, oee); } + case (ast.stmt_be(?e)) { + auto ee = fold_expr(env_, fld, e); + ret fld.fold_stmt_be(env_, s.span, ee); + } + case (ast.stmt_log(?e)) { auto ee = fold_expr(env_, fld, e); ret fld.fold_stmt_log(env_, s.span, ee); @@ -1136,6 +1144,10 @@ fn identity_fold_stmt_ret[ENV](&ENV env, &span sp, ret @respan(sp, ast.stmt_ret(rv)); } +fn identity_fold_stmt_be[ENV](&ENV env, &span sp, @expr x) -> @stmt { + ret @respan(sp, ast.stmt_be(x)); +} + fn identity_fold_stmt_log[ENV](&ENV e, &span sp, @expr x) -> @stmt { ret @respan(sp, ast.stmt_log(x)); } @@ -1366,6 +1378,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_stmt_decl = bind identity_fold_stmt_decl[ENV](_,_,_), fold_stmt_ret = bind identity_fold_stmt_ret[ENV](_,_,_), + fold_stmt_be = bind identity_fold_stmt_be[ENV](_,_,_), fold_stmt_log = bind identity_fold_stmt_log[ENV](_,_,_), fold_stmt_check_expr = bind identity_fold_stmt_check_expr[ENV](_,_,_), -- cgit v1.2.3 From f951b52e91c5c0487ad4d3a5454b193f15146d6a Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 10 Feb 2011 19:13:47 -0800 Subject: Add support to pat_lit to fold. --- src/comp/middle/fold.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 9194f734..5930ba75 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -160,6 +160,9 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, ann a) -> @pat) fold_pat_wild, + (fn(&ENV e, &span sp, + @ast.lit lit, ann a) -> @pat) fold_pat_lit, + (fn(&ENV e, &span sp, ident i, def_id did, ann a) -> @pat) fold_pat_bind, @@ -421,6 +424,9 @@ fn fold_pat[ENV](&ENV env, ast_fold[ENV] fld, @ast.pat p) -> @ast.pat { alt (p.node) { case (ast.pat_wild(?t)) { ret fld.fold_pat_wild(env_, p.span, t); } + case (ast.pat_lit(?lt, ?t)) { + ret fld.fold_pat_lit(env_, p.span, lt, t); + } case (ast.pat_bind(?id, ?did, ?t)) { ret fld.fold_pat_bind(env_, p.span, id, did, t); } @@ -1122,6 +1128,10 @@ fn identity_fold_pat_wild[ENV](&ENV e, &span sp, ann a) -> @pat { ret @respan(sp, ast.pat_wild(a)); } +fn identity_fold_pat_lit[ENV](&ENV e, &span sp, @ast.lit lit, ann a) -> @pat { + ret @respan(sp, ast.pat_lit(lit, a)); +} + fn identity_fold_pat_bind[ENV](&ENV e, &span sp, ident i, def_id did, ann a) -> @pat { ret @respan(sp, ast.pat_bind(i, did, a)); @@ -1373,6 +1383,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_decl_item = bind identity_fold_decl_item[ENV](_,_,_), fold_pat_wild = bind identity_fold_pat_wild[ENV](_,_,_), + fold_pat_lit = bind identity_fold_pat_lit[ENV](_,_,_,_), fold_pat_bind = bind identity_fold_pat_bind[ENV](_,_,_,_,_), fold_pat_tag = bind identity_fold_pat_tag[ENV](_,_,_,_,_,_), -- cgit v1.2.3 From 59bce06a967b3806c3d874b8956857f0f01287e1 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 14 Feb 2011 15:52:38 -0800 Subject: Expand expr_rec to take its optional trailing 'with' parameter. --- src/comp/middle/fold.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 5930ba75..4ba65a7b 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -75,7 +75,8 @@ type ast_fold[ENV] = vec[ast.elt] es, ann a) -> @expr) fold_expr_tup, (fn(&ENV e, &span sp, - vec[ast.field] fields, ann a) -> @expr) fold_expr_rec, + vec[ast.field] fields, + option.t[@expr] base, ann a) -> @expr) fold_expr_rec, (fn(&ENV e, &span sp, @expr f, vec[@expr] args, @@ -479,12 +480,19 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { ret fld.fold_expr_tup(env_, e.span, elts, t); } - case (ast.expr_rec(?fs, ?t)) { + case (ast.expr_rec(?fs, ?base, ?t)) { let vec[ast.field] fields = vec(); + let option.t[@expr] b = none[@expr]; for (ast.field f in fs) { fields += fold_rec_field(env, fld, f); } - ret fld.fold_expr_rec(env_, e.span, fields, t); + alt (base) { + case (none[@ast.expr]) { } + case (some[@ast.expr](?eb)) { + b = some[@expr](fold_expr(env_, fld, eb)); + } + } + ret fld.fold_expr_rec(env_, e.span, fields, b, t); } case (ast.expr_call(?f, ?args, ?t)) { @@ -1011,8 +1019,9 @@ fn identity_fold_expr_tup[ENV](&ENV env, &span sp, } fn identity_fold_expr_rec[ENV](&ENV env, &span sp, - vec[ast.field] fields, ann a) -> @expr { - ret @respan(sp, ast.expr_rec(fields, a)); + vec[ast.field] fields, + option.t[@expr] base, ann a) -> @expr { + ret @respan(sp, ast.expr_rec(fields, base, a)); } fn identity_fold_expr_call[ENV](&ENV env, &span sp, @expr f, @@ -1358,7 +1367,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_expr_vec = bind identity_fold_expr_vec[ENV](_,_,_,_), fold_expr_tup = bind identity_fold_expr_tup[ENV](_,_,_,_), - fold_expr_rec = bind identity_fold_expr_rec[ENV](_,_,_,_), + fold_expr_rec = bind identity_fold_expr_rec[ENV](_,_,_,_,_), fold_expr_call = bind identity_fold_expr_call[ENV](_,_,_,_,_), fold_expr_bind = bind identity_fold_expr_bind[ENV](_,_,_,_,_), fold_expr_binary = bind identity_fold_expr_binary[ENV](_,_,_,_,_,_), -- cgit v1.2.3 From f1f33abdeba156523d6db1752bbff75dc4088724 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 14 Feb 2011 17:46:28 -0800 Subject: Move all non-decl/non-expr stmts to exprs. --- src/comp/middle/fold.rs | 136 +++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 64 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 4ba65a7b..4e8ea317 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -149,6 +149,20 @@ type ast_fold[ENV] = &option.t[def] d, ann a) -> @expr) fold_expr_path, + (fn(&ENV e, &span sp) -> @expr) fold_expr_fail, + + (fn(&ENV e, &span sp, + &option.t[@expr] rv) -> @expr) fold_expr_ret, + + (fn(&ENV e, &span sp, + @expr e) -> @expr) fold_expr_be, + + (fn(&ENV e, &span sp, + @expr e) -> @expr) fold_expr_log, + + (fn(&ENV e, &span sp, + @expr e) -> @expr) fold_expr_check_expr, + // Decl folds. (fn(&ENV e, &span sp, @ast.local local) -> @decl) fold_decl_local, @@ -177,18 +191,6 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, @decl decl) -> @stmt) fold_stmt_decl, - (fn(&ENV e, &span sp, - &option.t[@expr] rv) -> @stmt) fold_stmt_ret, - - (fn(&ENV e, &span sp, - @expr e) -> @stmt) fold_stmt_be, - - (fn(&ENV e, &span sp, - @expr e) -> @stmt) fold_stmt_log, - - (fn(&ENV e, &span sp, - @expr e) -> @stmt) fold_stmt_check_expr, - (fn(&ENV e, &span sp, @expr e) -> @stmt) fold_stmt_expr, @@ -622,6 +624,37 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { auto p_ = fold_path(env_, fld, p); ret fld.fold_expr_path(env_, e.span, p_, r, t); } + + case (ast.expr_fail) { + ret fld.fold_expr_fail(env_, e.span); + } + + case (ast.expr_ret(?oe)) { + auto oee = none[@expr]; + alt (oe) { + case (some[@expr](?x)) { + oee = some(fold_expr(env_, fld, x)); + } + case (_) { /* fall through */ } + } + ret fld.fold_expr_ret(env_, e.span, oee); + } + + case (ast.expr_be(?x)) { + auto ee = fold_expr(env_, fld, x); + ret fld.fold_expr_be(env_, e.span, ee); + } + + case (ast.expr_log(?x)) { + auto ee = fold_expr(env_, fld, x); + ret fld.fold_expr_log(env_, e.span, ee); + } + + case (ast.expr_check_expr(?x)) { + auto ee = fold_expr(env_, fld, x); + ret fld.fold_expr_check_expr(env_, e.span, ee); + } + } ret e; @@ -642,36 +675,6 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt { ret fld.fold_stmt_decl(env_, s.span, dd); } - case (ast.stmt_ret(?oe)) { - auto oee = none[@expr]; - alt (oe) { - case (some[@expr](?e)) { - oee = some(fold_expr(env_, fld, e)); - } - case (_) { /* fall through */ } - } - ret fld.fold_stmt_ret(env_, s.span, oee); - } - - case (ast.stmt_be(?e)) { - auto ee = fold_expr(env_, fld, e); - ret fld.fold_stmt_be(env_, s.span, ee); - } - - case (ast.stmt_log(?e)) { - auto ee = fold_expr(env_, fld, e); - ret fld.fold_stmt_log(env_, s.span, ee); - } - - case (ast.stmt_check_expr(?e)) { - auto ee = fold_expr(env_, fld, e); - ret fld.fold_stmt_check_expr(env_, s.span, ee); - } - - case (ast.stmt_fail) { - ret s; - } - case (ast.stmt_expr(?e)) { auto ee = fold_expr(env_, fld, e); ret fld.fold_stmt_expr(env_, s.span, ee); @@ -1118,6 +1121,27 @@ fn identity_fold_expr_path[ENV](&ENV env, &span sp, ret @respan(sp, ast.expr_path(p, d, a)); } +fn identity_fold_expr_fail[ENV](&ENV env, &span sp) -> @expr { + ret @respan(sp, ast.expr_fail); +} + +fn identity_fold_expr_ret[ENV](&ENV env, &span sp, + &option.t[@expr] rv) -> @expr { + ret @respan(sp, ast.expr_ret(rv)); +} + +fn identity_fold_expr_be[ENV](&ENV env, &span sp, @expr x) -> @expr { + ret @respan(sp, ast.expr_be(x)); +} + +fn identity_fold_expr_log[ENV](&ENV e, &span sp, @expr x) -> @expr { + ret @respan(sp, ast.expr_log(x)); +} + +fn identity_fold_expr_check_expr[ENV](&ENV e, &span sp, @expr x) -> @expr { + ret @respan(sp, ast.expr_check_expr(x)); +} + // Decl identities. @@ -1158,23 +1182,6 @@ fn identity_fold_stmt_decl[ENV](&ENV env, &span sp, @decl d) -> @stmt { ret @respan(sp, ast.stmt_decl(d)); } -fn identity_fold_stmt_ret[ENV](&ENV env, &span sp, - &option.t[@expr] rv) -> @stmt { - ret @respan(sp, ast.stmt_ret(rv)); -} - -fn identity_fold_stmt_be[ENV](&ENV env, &span sp, @expr x) -> @stmt { - ret @respan(sp, ast.stmt_be(x)); -} - -fn identity_fold_stmt_log[ENV](&ENV e, &span sp, @expr x) -> @stmt { - ret @respan(sp, ast.stmt_log(x)); -} - -fn identity_fold_stmt_check_expr[ENV](&ENV e, &span sp, @expr x) -> @stmt { - ret @respan(sp, ast.stmt_check_expr(x)); -} - fn identity_fold_stmt_expr[ENV](&ENV e, &span sp, @expr x) -> @stmt { ret @respan(sp, ast.stmt_expr(x)); } @@ -1387,6 +1394,12 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_expr_field = bind identity_fold_expr_field[ENV](_,_,_,_,_), fold_expr_index = bind identity_fold_expr_index[ENV](_,_,_,_,_), fold_expr_path = bind identity_fold_expr_path[ENV](_,_,_,_,_), + fold_expr_fail = bind identity_fold_expr_fail[ENV](_,_), + fold_expr_ret = bind identity_fold_expr_ret[ENV](_,_,_), + fold_expr_be = bind identity_fold_expr_be[ENV](_,_,_), + fold_expr_log = bind identity_fold_expr_log[ENV](_,_,_), + fold_expr_check_expr + = bind identity_fold_expr_check_expr[ENV](_,_,_), fold_decl_local = bind identity_fold_decl_local[ENV](_,_,_), fold_decl_item = bind identity_fold_decl_item[ENV](_,_,_), @@ -1397,11 +1410,6 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_pat_tag = bind identity_fold_pat_tag[ENV](_,_,_,_,_,_), fold_stmt_decl = bind identity_fold_stmt_decl[ENV](_,_,_), - fold_stmt_ret = bind identity_fold_stmt_ret[ENV](_,_,_), - fold_stmt_be = bind identity_fold_stmt_be[ENV](_,_,_), - fold_stmt_log = bind identity_fold_stmt_log[ENV](_,_,_), - fold_stmt_check_expr - = bind identity_fold_stmt_check_expr[ENV](_,_,_), fold_stmt_expr = bind identity_fold_stmt_expr[ENV](_,_,_), fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_), -- cgit v1.2.3 From 15a01f5c3691a152793d8933a7be9d16a0fc7030 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 14 Feb 2011 17:58:32 -0800 Subject: Add basic front-end support for expr_put. --- src/comp/middle/fold.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 4e8ea317..4d3c2e2d 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -154,6 +154,9 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, &option.t[@expr] rv) -> @expr) fold_expr_ret, + (fn(&ENV e, &span sp, + &option.t[@expr] rv) -> @expr) fold_expr_put, + (fn(&ENV e, &span sp, @expr e) -> @expr) fold_expr_be, @@ -640,6 +643,17 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { ret fld.fold_expr_ret(env_, e.span, oee); } + case (ast.expr_put(?oe)) { + auto oee = none[@expr]; + alt (oe) { + case (some[@expr](?x)) { + oee = some(fold_expr(env_, fld, x)); + } + case (_) { /* fall through */ } + } + ret fld.fold_expr_put(env_, e.span, oee); + } + case (ast.expr_be(?x)) { auto ee = fold_expr(env_, fld, x); ret fld.fold_expr_be(env_, e.span, ee); @@ -1130,6 +1144,11 @@ fn identity_fold_expr_ret[ENV](&ENV env, &span sp, ret @respan(sp, ast.expr_ret(rv)); } +fn identity_fold_expr_put[ENV](&ENV env, &span sp, + &option.t[@expr] rv) -> @expr { + ret @respan(sp, ast.expr_put(rv)); +} + fn identity_fold_expr_be[ENV](&ENV env, &span sp, @expr x) -> @expr { ret @respan(sp, ast.expr_be(x)); } @@ -1396,6 +1415,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_expr_path = bind identity_fold_expr_path[ENV](_,_,_,_,_), fold_expr_fail = bind identity_fold_expr_fail[ENV](_,_), fold_expr_ret = bind identity_fold_expr_ret[ENV](_,_,_), + fold_expr_put = bind identity_fold_expr_put[ENV](_,_,_), fold_expr_be = bind identity_fold_expr_be[ENV](_,_,_), fold_expr_log = bind identity_fold_expr_log[ENV](_,_,_), fold_expr_check_expr -- cgit v1.2.3 From 4a72a23171d87fb5a0f9b7ad039944856b93bf0f Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 14 Feb 2011 18:17:31 -0800 Subject: Add basic front-end support for 'for each' loops. --- src/comp/middle/fold.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 4d3c2e2d..3cafa961 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -112,6 +112,10 @@ type ast_fold[ENV] = @decl decl, @expr seq, &block body, ann a) -> @expr) fold_expr_for, + (fn(&ENV e, &span sp, + @decl decl, @expr seq, &block body, + ann a) -> @expr) fold_expr_for_each, + (fn(&ENV e, &span sp, @expr cond, &block body, ann a) -> @expr) fold_expr_while, @@ -574,6 +578,13 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { ret fld.fold_expr_for(env_, e.span, ddecl, sseq, bbody, t); } + case (ast.expr_for_each(?decl, ?seq, ?body, ?t)) { + auto ddecl = fold_decl(env_, fld, decl); + auto sseq = fold_expr(env_, fld, seq); + auto bbody = fold_block(env_, fld, body); + ret fld.fold_expr_for_each(env_, e.span, ddecl, sseq, bbody, t); + } + case (ast.expr_while(?cnd, ?body, ?t)) { auto ccnd = fold_expr(env_, fld, cnd); auto bbody = fold_block(env_, fld, body); @@ -1087,6 +1098,12 @@ fn identity_fold_expr_for[ENV](&ENV env, &span sp, ret @respan(sp, ast.expr_for(d, seq, body, a)); } +fn identity_fold_expr_for_each[ENV](&ENV env, &span sp, + @decl d, @expr seq, + &block body, ann a) -> @expr { + ret @respan(sp, ast.expr_for_each(d, seq, body, a)); +} + fn identity_fold_expr_while[ENV](&ENV env, &span sp, @expr cond, &block body, ann a) -> @expr { ret @respan(sp, ast.expr_while(cond, body, a)); @@ -1402,6 +1419,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_expr_cast = bind identity_fold_expr_cast[ENV](_,_,_,_,_), fold_expr_if = bind identity_fold_expr_if[ENV](_,_,_,_,_,_,_), fold_expr_for = bind identity_fold_expr_for[ENV](_,_,_,_,_,_), + fold_expr_for_each + = bind identity_fold_expr_for_each[ENV](_,_,_,_,_,_), fold_expr_while = bind identity_fold_expr_while[ENV](_,_,_,_,_), fold_expr_do_while = bind identity_fold_expr_do_while[ENV](_,_,_,_,_), -- cgit v1.2.3 From 012fa69ea500aa31cb3dd2cd3df67ecd3eefd44e Mon Sep 17 00:00:00 2001 From: Rafael Avila de Espindola Date: Wed, 16 Feb 2011 14:02:02 -0500 Subject: More typechecking for native types and the needed plumbing in codegen. --- src/comp/middle/fold.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 3cafa961..db215ea9 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -214,7 +214,7 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, ident ident, &ast.fn_decl decl, vec[ast.ty_param] ty_params, - def_id id) -> @native_item) fold_native_item_fn, + def_id id, ann a) -> @native_item) fold_native_item_fn, (fn(&ENV e, &span sp, ident ident, &ast._mod m, def_id id) -> @item) fold_item_mod, @@ -921,10 +921,10 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld, case (ast.native_item_ty(?ident, ?id)) { ret fld.fold_native_item_ty(env_, i.span, ident, id); } - case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id)) { + case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id, ?ann)) { auto d = fold_fn_decl[ENV](env_, fld, fn_decl); ret fld.fold_native_item_fn(env_, i.span, ident, d, - ty_params, id); + ty_params, id, ann); } } } @@ -1240,8 +1240,8 @@ fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i, fn identity_fold_native_item_fn[ENV](&ENV e, &span sp, ident i, &ast.fn_decl decl, vec[ast.ty_param] ty_params, - def_id id) -> @native_item { - ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id)); + def_id id, ann a) -> @native_item { + ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id, a)); } fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i, @@ -1454,7 +1454,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_), fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_), fold_native_item_fn = - bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_), + bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_,_), fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_), fold_item_native_mod = bind identity_fold_item_native_mod[ENV](_,_,_,_,_), -- cgit v1.2.3 From 34c60b6edb810d9f142d248b27d8e6e34c95d63c Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 18 Feb 2011 17:30:57 -0800 Subject: Make a tag for iterness / fnness, teach many places about it. --- src/comp/middle/fold.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index db215ea9..abe94b89 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -59,6 +59,7 @@ type ast_fold[ENV] = vec[ast.ty_method] meths) -> @ty) fold_ty_obj, (fn(&ENV e, &span sp, + ast.proto proto, vec[rec(ast.mode mode, @ty ty)] inputs, @ty output) -> @ty) fold_ty_fn, @@ -252,11 +253,10 @@ type ast_fold[ENV] = &ast.block_) -> block) fold_block, (fn(&ENV e, &fn_decl decl, - bool is_iter, &block body) -> ast._fn) fold_fn, (fn(&ENV e, ast.effect effect, - vec[arg] inputs, + ast.proto proto, vec[arg] inputs, @ty output) -> ast.fn_decl) fold_fn_decl, (fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod, @@ -349,11 +349,13 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty { case (ast.ty_obj(?meths)) { let vec[ast.ty_method] meths_ = vec(); for (ast.ty_method m in meths) { - auto tfn = fold_ty_fn(env_, fld, t.span, m.inputs, m.output); + auto tfn = fold_ty_fn(env_, fld, t.span, m.proto, + m.inputs, m.output); alt (tfn.node) { - case (ast.ty_fn(?ins, ?out)) { + case (ast.ty_fn(?p, ?ins, ?out)) { append[ast.ty_method] - (meths_, rec(inputs=ins, output=out with m)); + (meths_, rec(proto=p, inputs=ins, output=out + with m)); } } } @@ -370,13 +372,14 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty { ret fld.fold_ty_mutable(env_, t.span, ty_); } - case (ast.ty_fn(?inputs, ?output)) { - ret fold_ty_fn(env_, fld, t.span, inputs, output); + case (ast.ty_fn(?proto, ?inputs, ?output)) { + ret fold_ty_fn(env_, fld, t.span, proto, inputs, output); } } } fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp, + ast.proto proto, vec[rec(ast.mode mode, @ty ty)] inputs, @ty output) -> @ty { auto output_ = fold_ty(env, fld, output); @@ -386,7 +389,7 @@ fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp, auto input_ = rec(ty=ty_ with input); inputs_ += vec(input_); } - ret fld.fold_ty_fn(env, sp, inputs_, output_); + ret fld.fold_ty_fn(env, sp, proto, inputs_, output_); } fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl { @@ -754,7 +757,7 @@ fn fold_fn_decl[ENV](&ENV env, ast_fold[ENV] fld, inputs += fold_arg(env, fld, a); } auto output = fold_ty[ENV](env, fld, decl.output); - ret fld.fold_fn_decl(env, decl.effect, inputs, output); + ret fld.fold_fn_decl(env, decl.effect, decl.proto, inputs, output); } fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn { @@ -762,7 +765,7 @@ fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn { auto body = fold_block[ENV](env, fld, f.body); - ret fld.fold_fn(env, decl, f.is_iter, body); + ret fld.fold_fn(env, decl, body); } @@ -1019,9 +1022,10 @@ fn identity_fold_ty_obj[ENV](&ENV env, &span sp, } fn identity_fold_ty_fn[ENV](&ENV env, &span sp, + ast.proto proto, vec[rec(ast.mode mode, @ty ty)] inputs, @ty output) -> @ty { - ret @respan(sp, ast.ty_fn(inputs, output)); + ret @respan(sp, ast.ty_fn(proto, inputs, output)); } fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p, @@ -1301,16 +1305,16 @@ fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block { fn identity_fold_fn_decl[ENV](&ENV e, ast.effect effect, + ast.proto proto, vec[arg] inputs, @ty output) -> ast.fn_decl { - ret rec(effect=effect, inputs=inputs, output=output); + ret rec(effect=effect, proto=proto, inputs=inputs, output=output); } fn identity_fold_fn[ENV](&ENV e, &fn_decl decl, - bool is_iter, &block body) -> ast._fn { - ret rec(decl=decl, is_iter=is_iter, body=body); + ret rec(decl=decl, body=body); } fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod { @@ -1404,7 +1408,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_), fold_ty_rec = bind identity_fold_ty_rec[ENV](_,_,_), fold_ty_obj = bind identity_fold_ty_obj[ENV](_,_,_), - fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_), + fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_), fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_), fold_ty_mutable = bind identity_fold_ty_mutable[ENV](_,_,_), @@ -1470,8 +1474,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { bind identity_fold_view_item_import[ENV](_,_,_,_,_,_), fold_block = bind identity_fold_block[ENV](_,_,_), - fold_fn = bind identity_fold_fn[ENV](_,_,_,_), - fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_), + fold_fn = bind identity_fold_fn[ENV](_,_,_), + fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_,_), fold_mod = bind identity_fold_mod[ENV](_,_), fold_native_mod = bind identity_fold_native_mod[ENV](_,_), fold_crate = bind identity_fold_crate[ENV](_,_,_), -- cgit v1.2.3 From ffcb4613700c968041f891985927b77f70a51c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Wed, 23 Feb 2011 14:06:37 -0500 Subject: Parse the abi in native modules. --- src/comp/middle/fold.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index abe94b89..968d4737 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -944,6 +944,7 @@ fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld, } ret fld.fold_native_mod(e, rec(native_name=m.native_name, + abi=m.abi, items=items, index=index)); } -- cgit v1.2.3 From f8f6f078c505dd0f20526e3ad86c360605fce109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 25 Feb 2011 12:08:21 -0500 Subject: There are no native iterators (or at least they are not going to be supported soon.). --- src/comp/middle/fold.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 968d4737..65bbe602 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -253,10 +253,11 @@ type ast_fold[ENV] = &ast.block_) -> block) fold_block, (fn(&ENV e, &fn_decl decl, + ast.proto proto, &block body) -> ast._fn) fold_fn, (fn(&ENV e, ast.effect effect, - ast.proto proto, vec[arg] inputs, + vec[arg] inputs, @ty output) -> ast.fn_decl) fold_fn_decl, (fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod, @@ -757,7 +758,7 @@ fn fold_fn_decl[ENV](&ENV env, ast_fold[ENV] fld, inputs += fold_arg(env, fld, a); } auto output = fold_ty[ENV](env, fld, decl.output); - ret fld.fold_fn_decl(env, decl.effect, decl.proto, inputs, output); + ret fld.fold_fn_decl(env, decl.effect, inputs, output); } fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn { @@ -765,7 +766,7 @@ fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn { auto body = fold_block[ENV](env, fld, f.body); - ret fld.fold_fn(env, decl, body); + ret fld.fold_fn(env, decl, f.proto, body); } @@ -1306,16 +1307,16 @@ fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block { fn identity_fold_fn_decl[ENV](&ENV e, ast.effect effect, - ast.proto proto, vec[arg] inputs, @ty output) -> ast.fn_decl { - ret rec(effect=effect, proto=proto, inputs=inputs, output=output); + ret rec(effect=effect, inputs=inputs, output=output); } fn identity_fold_fn[ENV](&ENV e, &fn_decl decl, + ast.proto proto, &block body) -> ast._fn { - ret rec(decl=decl, body=body); + ret rec(decl=decl, proto=proto, body=body); } fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod { @@ -1475,8 +1476,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { bind identity_fold_view_item_import[ENV](_,_,_,_,_,_), fold_block = bind identity_fold_block[ENV](_,_,_), - fold_fn = bind identity_fold_fn[ENV](_,_,_), - fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_,_), + fold_fn = bind identity_fold_fn[ENV](_,_,_,_), + fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_), fold_mod = bind identity_fold_mod[ENV](_,_), fold_native_mod = bind identity_fold_native_mod[ENV](_,_), fold_crate = bind identity_fold_crate[ENV](_,_,_), -- cgit v1.2.3 From 64ab5eaaf09de6a75392554c13784c492ed19465 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 1 Mar 2011 17:32:16 -0800 Subject: Parse (and ignore) dtors on objs. --- src/comp/middle/fold.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 65bbe602..09783070 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -269,7 +269,8 @@ type ast_fold[ENV] = (fn(&ENV e, vec[ast.obj_field] fields, - vec[@ast.method] methods) -> ast._obj) fold_obj, + vec[@ast.method] methods, + option.t[block] dtor) -> ast._obj) fold_obj, // Env updates. (fn(&ENV e, @ast.crate c) -> ENV) update_env_for_crate, @@ -791,6 +792,13 @@ fn fold_obj[ENV](&ENV env, ast_fold[ENV] fld, &ast._obj ob) -> ast._obj { for (ast.obj_field f in ob.fields) { fields += fold_obj_field(env, fld, f); } + let option.t[block] dtor = none[block]; + alt (ob.dtor) { + case (none[block]) { } + case (some[block](?b)) { + dtor = some[block](fold_block[ENV](env, fld, b)); + } + } let vec[ast.ty_param] tp = vec(); for (@ast.method m in ob.methods) { // Fake-up an ast.item for this method. @@ -805,7 +813,7 @@ fn fold_obj[ENV](&ENV env, ast_fold[ENV] fld, &ast._obj ob) -> ast._obj { let ENV _env = fld.update_env_for_item(env, i); append[@ast.method](meths, fold_method(_env, fld, m)); } - ret fld.fold_obj(env, fields, meths); + ret fld.fold_obj(env, fields, meths, dtor); } fn fold_view_item[ENV](&ENV env, ast_fold[ENV] fld, @view_item vi) @@ -1334,8 +1342,9 @@ fn identity_fold_crate[ENV](&ENV e, &span sp, &ast._mod m) -> @ast.crate { fn identity_fold_obj[ENV](&ENV e, vec[ast.obj_field] fields, - vec[@ast.method] methods) -> ast._obj { - ret rec(fields=fields, methods=methods); + vec[@ast.method] methods, + option.t[block] dtor) -> ast._obj { + ret rec(fields=fields, methods=methods, dtor=dtor); } @@ -1481,7 +1490,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_mod = bind identity_fold_mod[ENV](_,_), fold_native_mod = bind identity_fold_native_mod[ENV](_,_), fold_crate = bind identity_fold_crate[ENV](_,_,_), - fold_obj = bind identity_fold_obj[ENV](_,_,_), + fold_obj = bind identity_fold_obj[ENV](_,_,_,_), update_env_for_crate = bind identity_update_env_for_crate[ENV](_,_), update_env_for_item = bind identity_update_env_for_item[ENV](_,_), -- cgit v1.2.3 From f1500e5872d03e3ec3b140060641136a2ff5a15a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 26 Feb 2011 20:51:02 -0500 Subject: Add fold, typecheck and trans for expr_ext --- src/comp/middle/fold.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 09783070..d533082c 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -154,6 +154,12 @@ type ast_fold[ENV] = &option.t[def] d, ann a) -> @expr) fold_expr_path, + (fn(&ENV e, &span sp, + &path p, vec[@expr] args, + option.t[@expr] body, + option.t[@expr] expanded, + ann a) -> @expr) fold_expr_ext, + (fn(&ENV e, &span sp) -> @expr) fold_expr_fail, (fn(&ENV e, &span sp, @@ -644,6 +650,15 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { ret fld.fold_expr_path(env_, e.span, p_, r, t); } + case (ast.expr_ext(?p, ?args, ?body, ?expanded, ?t)) { + // Only fold the expanded expression, not the + // expressions involved in syntax extension + auto exp = option.get[@expr](expanded); + auto exp_ = fold_expr(env_, fld, exp); + ret fld.fold_expr_ext(env_, e.span, p, args, body, + some[@ast.expr](exp_), t); + } + case (ast.expr_fail) { ret fld.fold_expr_fail(env_, e.span); } @@ -1166,6 +1181,14 @@ fn identity_fold_expr_path[ENV](&ENV env, &span sp, ret @respan(sp, ast.expr_path(p, d, a)); } +fn identity_fold_expr_ext[ENV](&ENV env, &span sp, + &path p, vec[@expr] args, + option.t[@expr] body, + option.t[@expr] expanded, + ann a) -> @expr { + ret @respan(sp, ast.expr_ext(p, args, body, expanded, a)); +} + fn identity_fold_expr_fail[ENV](&ENV env, &span sp) -> @expr { ret @respan(sp, ast.expr_fail); } @@ -1447,6 +1470,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_expr_field = bind identity_fold_expr_field[ENV](_,_,_,_,_), fold_expr_index = bind identity_fold_expr_index[ENV](_,_,_,_,_), fold_expr_path = bind identity_fold_expr_path[ENV](_,_,_,_,_), + fold_expr_ext = bind identity_fold_expr_ext[ENV](_,_,_,_,_,_,_), fold_expr_fail = bind identity_fold_expr_fail[ENV](_,_), fold_expr_ret = bind identity_fold_expr_ret[ENV](_,_,_), fold_expr_put = bind identity_fold_expr_put[ENV](_,_,_), -- cgit v1.2.3 From c1e6f5328c3f46884ed7a7e29c780e307b02100a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 27 Feb 2011 22:35:27 -0500 Subject: Make the expanded expression in expr_ext not optional --- src/comp/middle/fold.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index d533082c..c7041b26 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -157,7 +157,7 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, &path p, vec[@expr] args, option.t[@expr] body, - option.t[@expr] expanded, + @expr expanded, ann a) -> @expr) fold_expr_ext, (fn(&ENV e, &span sp) -> @expr) fold_expr_fail, @@ -653,10 +653,9 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { case (ast.expr_ext(?p, ?args, ?body, ?expanded, ?t)) { // Only fold the expanded expression, not the // expressions involved in syntax extension - auto exp = option.get[@expr](expanded); - auto exp_ = fold_expr(env_, fld, exp); + auto exp = fold_expr(env_, fld, expanded); ret fld.fold_expr_ext(env_, e.span, p, args, body, - some[@ast.expr](exp_), t); + exp, t); } case (ast.expr_fail) { @@ -1184,7 +1183,7 @@ fn identity_fold_expr_path[ENV](&ENV env, &span sp, fn identity_fold_expr_ext[ENV](&ENV env, &span sp, &path p, vec[@expr] args, option.t[@expr] body, - option.t[@expr] expanded, + @expr expanded, ann a) -> @expr { ret @respan(sp, ast.expr_ext(p, args, body, expanded, a)); } -- cgit v1.2.3 From d97c800e3179604db82e35bff682ea1ed6ec3909 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Sat, 5 Mar 2011 20:05:02 +0000 Subject: Make ret and fail stmts have 0 out-edges, Closes #250. --- src/comp/middle/fold.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index c7041b26..935f426b 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -701,7 +701,7 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { } - ret e; + fail; } @@ -724,7 +724,7 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt { ret fld.fold_stmt_expr(env_, s.span, ee); } } - ret s; + fail; } fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block { -- cgit v1.2.3 From 90f299e710c49d689d5bc815e32db375cca00394 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 7 Mar 2011 11:48:43 -0800 Subject: Permit view items in native modules. --- src/comp/middle/fold.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 935f426b..8a1dc70f 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -957,8 +957,14 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld, fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast.native_mod m) -> ast.native_mod { + let vec[@view_item] view_items = vec(); let vec[@native_item] items = vec(); - auto index = new_str_hash[@ast.native_item](); + auto index = new_str_hash[ast.native_mod_index_entry](); + + for (@view_item vi in m.view_items) { + auto new_vi = fold_view_item[ENV](e, fld, vi); + append[@view_item](view_items, new_vi); + } for (@native_item i in m.items) { auto new_item = fold_native_item[ENV](e, fld, i); @@ -968,6 +974,7 @@ fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld, ret fld.fold_native_mod(e, rec(native_name=m.native_name, abi=m.abi, + view_items=view_items, items=items, index=index)); } -- cgit v1.2.3