Skip to content

Commit 7921b9b

Browse files
committed
---
yaml --- r: 4229 b: refs/heads/master c: 86f3374 h: refs/heads/master i: 4227: 980b3f1 v: v3
1 parent dff6803 commit 7921b9b

File tree

12 files changed

+81
-79
lines changed

12 files changed

+81
-79
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 3d7016ae9575a36fd96ec264274bbe0c660a7758
2+
refs/heads/master: 86f337484eeabb5e74060d3549974b3bd85e7f3b

trunk/src/comp/syntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ tag expr_ {
333333
type mac = spanned[mac_];
334334
335335
tag mac_ {
336-
mac_invoc(path, (@expr)[], option::t[str]);
336+
mac_invoc(path, @expr, option::t[str]);
337337
mac_embed_type(@ty);
338338
mac_embed_block(blk);
339339
mac_ellipsis;

trunk/src/comp/syntax/ext/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import std::map::new_str_hash;
77
import codemap;
88

99
type syntax_expander =
10-
fn(&ext_ctxt, span, &(@ast::expr)[], option::t[str]) -> @ast::expr ;
10+
fn(&ext_ctxt, span, @ast::expr, option::t[str]) -> @ast::expr ;
1111
type macro_def = {ident: str, ext: syntax_extension};
1212
type macro_definer =
13-
fn(&ext_ctxt, span, &(@ast::expr)[], option::t[str]) -> macro_def ;
13+
fn(&ext_ctxt, span, @ast::expr, option::t[str]) -> macro_def ;
1414

1515
tag syntax_extension {
1616
normal(syntax_expander);

trunk/src/comp/syntax/ext/env.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import std::generic_os;
1212
import base::*;
1313
export expand_syntax_ext;
1414

15-
fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, args: &(@ast::expr)[],
15+
fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
1616
body: option::t[str]) -> @ast::expr {
17+
let args: (@ast::expr)[] = alt arg.node {
18+
ast::expr_vec(elts, _, _) { elts }
19+
_ { cx.span_fatal(sp, "#env requires arguments of the form `[...]`.") }
20+
};
1721
if ivec::len[@ast::expr](args) != 1u {
1822
cx.span_fatal(sp, "malformed #env call");
1923
}

trunk/src/comp/syntax/ext/fmt.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ import base::*;
1616
import codemap::span;
1717
export expand_syntax_ext;
1818

19-
fn expand_syntax_ext(cx: &ext_ctxt, sp: span, args: &(@ast::expr)[],
19+
fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr,
2020
body: option::t[str]) -> @ast::expr {
21+
let args: (@ast::expr)[] = alt arg.node {
22+
ast::expr_vec(elts, _, _) { elts }
23+
_ { cx.span_fatal(sp, "#fmt requires arguments of the form `[...]`.") }
24+
};
2125
if ivec::len[@ast::expr](args) == 0u {
2226
cx.span_fatal(sp, "#fmt requires a format string");
2327
}

trunk/src/comp/syntax/ext/simplext.rs

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn path_to_ident(pth: &path) -> option::t[ident] {
4242
}
4343

4444
//an ivec of binders might be a little big.
45-
type clause = {params: binders[], body: @expr};
45+
type clause = {params: binders, body: @expr};
4646

4747
/* logically, an arb_depth should contain only one kind of matchable */
4848
tag arb_depth[T] { leaf(T); seq(vec[arb_depth[T]], span); }
@@ -107,6 +107,7 @@ fn elts_to_ell(cx: &ext_ctxt, elts: &(@expr)[]) -> option::t[@expr] {
107107
}
108108
ret some(elts.(0));
109109
}
110+
_ { }
110111
}
111112
}
112113
_ { }
@@ -179,19 +180,19 @@ selectors. */
179180

180181
fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t[bindings] {
181182
let res = new_str_hash[arb_depth[matchable]]();
183+
//need to do this first, to check vec lengths.
184+
for sel: selector in b.literal_ast_matchers {
185+
alt sel(match_expr(e)) { none. { ret none; } _ { } }
186+
}
182187
let never_mind: bool = false;
183188
for each pair: @{key: ident, val: selector} in b.real_binders.items() {
184189
alt pair.val(match_expr(e)) {
185190
none. { never_mind = true; }
186191
some(mtc) { res.insert(pair.key, mtc); }
187192
}
188193
}
189-
if never_mind {
190-
ret none; //HACK: `ret` doesn't work in `for each`
191-
}
192-
for sel: selector in b.literal_ast_matchers {
193-
alt sel(match_expr(e)) { none. { ret none; } _ { } }
194-
}
194+
//HACK: `ret` doesn't work in `for each`
195+
if never_mind { ret none; }
195196
ret some(res);
196197
}
197198

@@ -537,8 +538,8 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
537538
_ { none }
538539
}
539540
}
540-
b.real_binders.insert(id,
541-
bind select_pt_1(cx, _, select_pt_2));
541+
let final_step = bind select_pt_1(cx, _, select_pt_2);
542+
b.real_binders.insert(id, compose_sels(s, final_step));
542543
}
543544
none. { no_des(cx, pth.span, "under `#<>`"); }
544545
}
@@ -557,7 +558,8 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
557558
_ { none }
558559
}
559560
}
560-
b.real_binders.insert(id, bind select_pt_1(cx, _, select_pt_2));
561+
let final_step = bind select_pt_1(cx, _, select_pt_2);
562+
b.real_binders.insert(id, compose_sels(s, final_step));
561563
}
562564
none. { no_des(cx, blk.span, "under `#{}`"); }
563565
}
@@ -576,7 +578,7 @@ fn ivec_to_vec[T](v: &T[]) -> vec[T] {
576578
fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, s: &selector,
577579
b: &binders) {
578580
fn select(cx: &ext_ctxt, repeat_me: @expr, m: &matchable) ->
579-
match_result {
581+
match_result {
580582
ret alt m {
581583
match_expr(e) {
582584
alt e.node {
@@ -640,8 +642,15 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: (@expr)[], s: &selector,
640642
}
641643
}
642644

643-
fn add_new_extension(cx: &ext_ctxt, sp: span, args: &(@expr)[],
645+
fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr,
644646
body: option::t[str]) -> base::macro_def {
647+
let args: (@ast::expr)[] = alt arg.node {
648+
ast::expr_vec(elts, _, _) { elts }
649+
_ {
650+
cx.span_fatal(sp, "#macro requires arguments of the form `[...]`.")
651+
}
652+
};
653+
645654
let macro_name: option::t[str] = none;
646655
let clauses: clause[] = ~[];
647656
for arg: @expr in args {
@@ -657,19 +666,16 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, args: &(@expr)[],
657666
alt elts.(0u).node {
658667
expr_mac(mac) {
659668
alt mac.node {
660-
mac_invoc(pth, invoc_args, body) {
669+
mac_invoc(pth, invoc_arg, body) {
661670
alt path_to_ident(pth) {
662671
some(id) { macro_name = some(id); }
663672
none. {
664673
cx.span_fatal(pth.span,
665-
"macro name " + "must not be a path");
674+
"macro name must not be a path");
666675
}
667676
}
668-
let bdrses = ~[];
669-
for arg: @expr in invoc_args {
670-
bdrses += ~[pattern_to_selectors(cx, arg)];
671-
}
672-
clauses += ~[{params: bdrses, body: elts.(1u)}];
677+
clauses += ~[{params: pattern_to_selectors(cx, invoc_arg),
678+
body: elts.(1u)}];
673679
// FIXME: check duplicates (or just simplify
674680
// the macro arg situation)
675681
}
@@ -702,32 +708,15 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, args: &(@expr)[],
702708
},
703709
ext: normal(ext)};
704710

705-
706-
fn generic_extension(cx: &ext_ctxt, sp: span, args: &(@expr)[],
711+
fn generic_extension(cx: &ext_ctxt, sp: span, arg: @expr,
707712
body: option::t[str], clauses: clause[]) -> @expr {
708-
709-
710713
for c: clause in clauses {
711-
if ivec::len(args) != ivec::len(c.params) { cont; }
712-
let i: uint = 0u;
713-
let bdgs: bindings = new_str_hash[arb_depth[matchable]]();
714-
let abort: bool = false;
715-
while i < ivec::len(args) {
716-
alt use_selectors_to_bind(c.params.(i), args.(i)) {
717-
some(new_bindings) {
718-
719-
/* ick; I wish macros just took one expr */
720-
for each it: @{key: ident, val: arb_depth[matchable]} in
721-
new_bindings.items() {
722-
bdgs.insert(it.key, it.val);
723-
}
724-
}
725-
none. { abort = true; }
726-
}
727-
i += 1u;
714+
alt use_selectors_to_bind(c.params, arg) {
715+
some(bindings) {
716+
ret transcribe(cx, bindings, c.body)
717+
}
718+
none. { cont; }
728719
}
729-
if abort { cont; }
730-
ret transcribe(cx, bdgs, c.body);
731720
}
732721
cx.span_fatal(sp, "no clauses match macro invocation");
733722
}

trunk/src/comp/syntax/fold.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,14 @@ fn fold_arg_(a: &arg, fld: ast_fold) -> arg {
130130
//used in noop_fold_expr, and possibly elsewhere in the future
131131
fn fold_mac_(m: &mac, fld: ast_fold) -> mac {
132132
ret {node:
133-
alt m.node {
134-
mac_invoc(pth, args, body) {
135-
mac_invoc(fld.fold_path(pth),
136-
fld.map_exprs(fld.fold_expr, args), body)
137-
}
138-
mac_embed_type(ty) { mac_embed_type(fld.fold_ty(ty)) }
139-
mac_embed_block(blk) { mac_embed_block(fld.fold_block(blk)) }
140-
mac_ellipsis. { mac_ellipsis }
141-
},
133+
alt m.node {
134+
mac_invoc(pth, arg, body) {
135+
mac_invoc(fld.fold_path(pth), fld.fold_expr(arg), body)
136+
}
137+
mac_embed_type(ty) { mac_embed_type(fld.fold_ty(ty)) }
138+
mac_embed_block(blk) { mac_embed_block(fld.fold_block(blk)) }
139+
mac_ellipsis. { mac_ellipsis }
140+
},
142141
span: m.span};
143142
}
144143

trunk/src/comp/syntax/parse/parser.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,11 +1021,18 @@ fn parse_syntax_ext_naked(p: &parser, lo: uint) -> @ast::expr {
10211021
if ivec::len(pth.node.idents) == 0u {
10221022
p.fatal("expected a syntax expander name");
10231023
}
1024-
let es =
1024+
//temporary for a backwards-compatible cycle:
1025+
let es = if p.peek() == token::LPAREN {
10251026
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
1026-
parse_expr, p);
1027+
parse_expr, p)
1028+
} else {
1029+
parse_seq(token::LBRACKET, token::RBRACKET, some(token::COMMA),
1030+
parse_expr, p)
1031+
};
10271032
let hi = es.span.hi;
1028-
ret mk_mac_expr(p, lo, hi, ast::mac_invoc(pth, es.node, none));
1033+
let e = mk_expr(p, es.span.lo, hi,
1034+
ast::expr_vec(es.node, ast::imm, ast::sk_rc));
1035+
ret mk_mac_expr(p, lo, hi, ast::mac_invoc(pth, e, none));
10291036
}
10301037

10311038
fn parse_self_method(p: &parser) -> @ast::expr {

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,15 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk,
642642

643643
fn print_mac(s: &ps, m: &ast::mac) {
644644
alt m.node {
645-
ast::mac_invoc(path, args, body) {
645+
ast::mac_invoc(path, arg, body) {
646646
word(s.s, "#");
647647
print_path(s, path);
648-
if ivec::len(args) > 0u {
649-
popen(s);
650-
commasep_exprs(s, inconsistent, args);
651-
pclose(s);
648+
alt (arg.node) {
649+
ast::expr_vec(_,_,_) {}
650+
_ { word(s.s, " "); }
652651
}
652+
print_expr(s, arg);
653653
// FIXME: extension 'body'
654-
655654
}
656655
ast::mac_embed_type(ty) {
657656
word(s.s, "#<");

trunk/src/comp/syntax/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ fn visit_exprs[E](exprs: &(@expr)[], e: &E, v: &vt[E]) {
239239

240240
fn visit_mac[E](m: mac, e: &E, v: &vt[E]) {
241241
alt m.node {
242-
ast::mac_invoc(pth, args, body) { visit_exprs(args, e, v); }
242+
ast::mac_invoc(pth, arg, body) { visit_expr(arg, e, v); }
243243
ast::mac_embed_type(ty) { v.visit_ty(ty, e, v); }
244244
ast::mac_embed_block(blk) { v.visit_block(blk, e, v); }
245245
ast::mac_ellipsis. { }

trunk/src/comp/syntax/walk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ fn walk_exprs(v: &ast_visitor, exprs: &(@ast::expr)[]) {
262262

263263
fn walk_mac(v: &ast_visitor, mac: ast::mac) {
264264
alt mac.node {
265-
ast::mac_invoc(pth, args, body) { walk_exprs(v, args); }
265+
ast::mac_invoc(pth, arg, body) { walk_expr(v, arg); }
266266
ast::mac_embed_type(ty) { walk_ty(v, ty); }
267267
ast::mac_embed_block(blk) { walk_block(v, blk); }
268268
ast::mac_ellipsis. { }
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
fn main() {
2-
#macro([#zip_or_unzip([[x, ...], [y, ...]]), [[x, y], ...]],
3-
[#zip_or_unzip([[xx, yy], ...]), [[xx, ...], [yy, ...]]]);
2+
#macro([#zip_or_unzip[[x, ...], [y, ...]], [[x, y], ...]],
3+
[#zip_or_unzip[[xx, yy], ...], [[xx, ...], [yy, ...]]]);
44

55

6-
assert (#zip_or_unzip([[1, 2, 3, 4], [5, 6, 7, 8]]) ==
6+
assert (#zip_or_unzip[[1, 2, 3, 4], [5, 6, 7, 8]] ==
77
[[1, 5], [2, 6], [3, 7], [4, 8]]);
8-
assert (#zip_or_unzip([[1, 5], [2, 6], [3, 7], [4, 8]]) ==
8+
assert (#zip_or_unzip[[1, 5], [2, 6], [3, 7], [4, 8]] ==
99
[[1, 2, 3, 4], [5, 6, 7, 8]]);
1010

1111

12-
#macro([#nested([[[x, ...], ...], [[y, ...], ...]]),
12+
#macro([#nested[[[x, ...], ...], [[y, ...], ...]],
1313
[[[x, y], ...], ...]]);
14-
assert (#nested([[[1, 2, 3, 4, 5], [7, 8, 9, 10, 11, 12]],
15-
[[-1, -2, -3, -4, -5], [-7, -8, -9, -10, -11, -12]]]) ==
14+
assert (#nested[[[1, 2, 3, 4, 5], [7, 8, 9, 10, 11, 12]],
15+
[[-1, -2, -3, -4, -5], [-7, -8, -9, -10, -11, -12]]] ==
1616
[[[1, -1], [2, -2], [3, -3], [4, -4], [5, -5]],
1717
[[7, -7], [8, -8], [9, -9], [10, -10], [11, -11],
1818
[12, -12]]]);
1919

20-
#macro([#dup([y, [x, ...]]), [[y, x], ...]]);
20+
#macro([#dup[y, [x, ...]], [[y, x], ...]]);
2121

22-
assert (#dup([1, [1, 2, 3, 4]]) == [[1, 1], [1, 2], [1, 3], [1, 4]]);
22+
assert (#dup[1, [1, 2, 3, 4]] == [[1, 1], [1, 2], [1, 3], [1, 4]]);
2323

2424

25-
#macro([#lambda(x, #<t>, body, #<s>),
25+
#macro([#lambda[x, #<t>, body, #<s>],
2626
{
2727
fn result(x: t) -> s { ret body }
2828
result
2929
}]);
3030

3131

32-
assert (#lambda(i, #<uint>, i + 4u, #<uint>)(12u) == 16u)
32+
assert ((#lambda[i, #<uint>, i + 4u, #<uint>])(12u) == 16u)
3333

3434
}

0 commit comments

Comments
 (0)