Skip to content

Commit 260aa40

Browse files
author
Eric Holk
committed
Merge branch 'master' of github.com:graydon/rust into fastcall
2 parents 405c164 + 9776556 commit 260aa40

28 files changed

+1149
-743
lines changed

mk/stage3.mk

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
stage3/std.o: $(STDLIB_CRATE) $(STDLIB_INPUTS) \
1+
stage3/$(CFG_STDLIB): $(STDLIB_CRATE) $(STDLIB_INPUTS) \
22
stage2/rustc$(X) stage2/$(CFG_STDLIB) stage2/intrinsics.bc \
33
$(LREQ) $(MKFILES)
4-
@$(call E, compile: $@)
5-
$(STAGE2) -c --shared -o $@ $<
6-
7-
stage3/$(CFG_STDLIB): stage2/std.o stage2/glue.o
8-
@$(call E, link: $@)
9-
$(Q)gcc $(CFG_GCCISH_CFLAGS) stage2/glue.o $(CFG_GCCISH_LINK_FLAGS) -o \
10-
$@ $< -Lstage2 -Lrt -lrustrt
4+
@$(call E, compile_and_link: $@)
5+
$(STAGE2) --shared -o $@ $<
116

127
stage3/librustc.o: $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ2)
138
@$(call E, compile: $@)

src/comp/back/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const int closure_elt_bindings = 2;
104104

105105
const int closure_elt_ty_params = 3;
106106

107-
const uint ivec_default_length = 8u;
107+
const uint ivec_default_length = 4u;
108108

109109
const uint ivec_elt_len = 0u;
110110

src/comp/back/link.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ mod write {
209209
*
210210
* There are a few issues to handle:
211211
*
212-
* - Linkers operate on a flat namespace, so we have to flatten names.
212+
* - Linnkers operate on a flat namespace, so we have to flatten names.
213213
* We do this using the C++ namespace-mangling technique. Foo::bar
214214
* symbols and such.
215215
*
@@ -221,15 +221,15 @@ mod write {
221221
* symbols in the same process before you're even hitting birthday-paradox
222222
* collision probability.
223223
*
224-
* - Symbols in dirrerent crates but with same names "within" the crate need
224+
* - Symbols in different crates but with same names "within" the crate need
225225
* to get different linkage-names.
226226
*
227227
* So here is what we do:
228228
*
229229
* - Separate the meta tags into two sets: exported and local. Only work with
230230
* the exported ones when considering linkage.
231231
*
232-
* - Consider two exported tags as special (and madatory): name and vers.
232+
* - Consider two exported tags as special (and mandatory): name and vers.
233233
* Every crate gets them; if it doesn't name them explicitly we infer them
234234
* as basename(crate) and "0.1", respectively. Call these CNAME, CVERS.
235235
*

src/comp/driver/rustc.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ fn compile_input(session::session sess, eval::env env, str input,
8181
auto crate =
8282
time(time_passes, "parsing", bind parse_input(sess, p, input));
8383
if (sess.get_opts().output_type == link::output_type_none) { ret; }
84-
auto def_map =
84+
auto d =
8585
time(time_passes, "resolution",
8686
bind resolve::resolve_crate(sess, crate));
87-
auto ty_cx = ty::mk_ctxt(sess, def_map);
87+
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1);
8888
time[()](time_passes, "typechecking",
8989
bind typeck::check_crate(ty_cx, crate));
9090
if (sess.get_opts().run_typestate) {
9191
time(time_passes, "typestate checking",
9292
bind middle::tstate::ck::check_crate(ty_cx, crate));
9393
}
9494
time(time_passes, "alias checking",
95-
bind middle::alias::check_crate(@ty_cx, def_map, crate));
95+
bind middle::alias::check_crate(@ty_cx, crate));
9696
auto llmod =
9797
time[llvm::llvm::ModuleRef](time_passes, "translation",
9898
bind trans::trans_crate(sess, crate,
@@ -109,8 +109,8 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
109109
auto mode;
110110
alt (ppm) {
111111
case (ppm_typed) {
112-
auto def_map = resolve::resolve_crate(sess, crate);
113-
auto ty_cx = ty::mk_ctxt(sess, def_map);
112+
auto d = resolve::resolve_crate(sess, crate);
113+
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1);
114114
typeck::check_crate(ty_cx, crate);
115115
mode = ppaux::mo_typed(ty_cx);
116116
}
@@ -399,37 +399,34 @@ fn main(vec[str] args) {
399399
let str prog = "gcc";
400400
// The invocations of gcc share some flags across platforms
401401

402-
let vec[str] common_cflags =
403-
["-fno-strict-aliasing", "-fPIC", "-Wall", "-fno-rtti",
404-
"-fno-exceptions", "-g"];
405-
let vec[str] common_libs =
406-
[stage, "-Lrustllvm", "-Lrt", "-lrustrt", "-lrustllvm", "-lstd",
407-
"-lm"];
402+
let vec[str] common_args = [stage, "-Lrt", "-lrustrt",
403+
"-fno-strict-aliasing", "-fPIC", "-Wall",
404+
"-fno-rtti", "-fno-exceptions", "-g", glu, "-o",
405+
saved_out_filename, saved_out_filename + ".o"];
406+
407+
auto shared_cmd;
408+
408409
alt (sess.get_targ_cfg().os) {
409410
case (session::os_win32) {
410-
gcc_args =
411-
common_cflags +
412-
["-march=i686", "-O2", glu, main, "-o",
413-
saved_out_filename, saved_out_filename + ".o"] +
414-
common_libs;
411+
shared_cmd = "-shared";
412+
gcc_args = common_args + ["-march=i686", "-O2"];
415413
}
416414
case (session::os_macos) {
417-
gcc_args =
418-
common_cflags +
419-
["-arch i386", "-O0", "-m32", glu, main, "-o",
420-
saved_out_filename, saved_out_filename + ".o"] +
421-
common_libs;
415+
shared_cmd = "-dynamiclib";
416+
gcc_args = common_args + ["-arch i386", "-O0", "-m32"];
422417
}
423418
case (session::os_linux) {
424-
gcc_args =
425-
common_cflags +
426-
["-march=i686", "-O2", "-m32", glu, main, "-o",
427-
saved_out_filename, saved_out_filename + ".o"] +
428-
common_libs;
419+
shared_cmd = "-shared";
420+
gcc_args = common_args + ["-march=i686", "-O2", "-m32"];
429421
}
430422
}
431-
// We run 'gcc' here
423+
if (sopts.shared) {
424+
gcc_args += [shared_cmd];
425+
} else {
426+
gcc_args += ["-Lrustllvm", "-lrustllvm", "-lstd", "-lm", main];
427+
}
432428

429+
// We run 'gcc' here
433430
run::run_program(prog, gcc_args);
434431
// Clean up on Darwin
435432

src/comp/front/ast.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,19 +359,17 @@ tag constr_arg_general_[T] { carg_base; carg_ident(T); carg_lit(@lit); }
359359
360360
type constr_arg = constr_arg_general[uint];
361361
362-
type constr_arg_use = constr_arg_general[ident];
363-
364362
type constr_arg_general[T] = spanned[constr_arg_general_[T]];
365363
364+
type constr_ = rec(path path,
365+
vec[@constr_arg_general[uint]] args,
366+
ann ann);
366367
367-
// The ann field is there so that using the def_map in the type
368-
// context, we can get the def_id for the path.
369-
type constr_general[T] =
370-
rec(path path, vec[@constr_arg_general[T]] args, ann ann);
371-
372-
type constr = spanned[constr_general[uint]];
368+
type constr = spanned[constr_];
373369
374-
type constr_use = spanned[constr_general[ident]];
370+
/* The parser generates ast::constrs; resolve generates
371+
a mapping from each function to a list of ty::constr_defs,
372+
corresponding to these. */
375373
376374
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
377375

src/comp/front/creader.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ fn parse_ty_or_bang(@pstate st, str_def sd) -> ty_or_bang {
7878
}
7979
}
8080

81-
fn parse_constrs(@pstate st, str_def sd) -> vec[@ast::constr] {
82-
let vec[@ast::constr] res = [];
81+
fn parse_constrs(@pstate st, str_def sd) -> vec[@ty::constr_def] {
82+
let vec[@ty::constr_def] res = [];
8383
alt (peek(st) as char) {
8484
case (':') {
8585
do {
@@ -92,7 +92,7 @@ fn parse_constrs(@pstate st, str_def sd) -> vec[@ast::constr] {
9292
ret res;
9393
}
9494

95-
fn parse_constr(@pstate st, str_def sd) -> @ast::constr {
95+
fn parse_constr(@pstate st, str_def sd) -> @ty::constr_def {
9696
st.tcx.sess.unimpl("Reading constraints " + " isn't implemented");
9797
/*
9898
let vec[@ast::constr_arg] args = [];
@@ -318,7 +318,7 @@ fn parse_hex(@pstate st) -> uint {
318318
}
319319

320320
fn parse_ty_fn(@pstate st, str_def sd) ->
321-
tup(vec[ty::arg], ty::t, ast::controlflow, vec[@ast::constr]) {
321+
tup(vec[ty::arg], ty::t, ast::controlflow, vec[@ty::constr_def]) {
322322
assert (next(st) as char == '[');
323323
let vec[ty::arg] inputs = [];
324324
while (peek(st) as char != ']') {

src/comp/front/parser.rs

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import std::str;
55
import std::option;
66
import std::option::some;
77
import std::option::none;
8+
import std::either;
9+
import std::either::left;
10+
import std::either::right;
811
import std::map::hashmap;
912
import driver::session;
1013
import util::common;
@@ -816,14 +819,9 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
816819
hi = es.span.hi;
817820
ex = ast::expr_bind(e, es.node, p.get_ann());
818821
} else if (p.peek() == token::POUND) {
819-
p.bump();
820-
auto pth = parse_path(p);
821-
auto es =
822-
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
823-
parse_expr, p);
824-
hi = es.span.hi;
825-
auto ext_span = rec(lo=lo, hi=hi);
826-
ex = expand_syntax_ext(p, ext_span, pth, es.node, none);
822+
auto ex_ext = parse_syntax_ext(p);
823+
lo = ex_ext.span.lo;
824+
ex = ex_ext.node;
827825
} else if (eat_word(p, "fail")) {
828826
auto msg;
829827
alt (p.peek()) {
@@ -917,6 +915,21 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
917915
ret @spanned(lo, hi, ex);
918916
}
919917

918+
fn parse_syntax_ext(&parser p) -> @ast::expr {
919+
auto lo = p.get_lo_pos();
920+
expect(p, token::POUND);
921+
ret parse_syntax_ext_inner(p, lo);
922+
}
923+
924+
fn parse_syntax_ext_inner(&parser p, uint lo) -> @ast::expr {
925+
auto pth = parse_path(p);
926+
auto es = parse_seq(token::LPAREN, token::RPAREN,
927+
some(token::COMMA), parse_expr, p);
928+
auto hi = es.span.hi;
929+
auto ext_span = rec(lo=lo, hi=hi);
930+
auto ex = expand_syntax_ext(p, ext_span, pth, es.node, none);
931+
ret @spanned(lo, hi, ex);
932+
}
920933

921934
/*
922935
* FIXME: This is a crude approximation of the syntax-extension system,
@@ -1423,7 +1436,22 @@ fn parse_source_stmt(&parser p) -> @ast::stmt {
14231436
auto hi = p.get_span();
14241437
ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_ann()));
14251438
} else {
1426-
alt (parse_item(p, [])) {
1439+
1440+
auto item_attrs;
1441+
alt (parse_attrs_or_ext(p)) {
1442+
case (none) {
1443+
item_attrs = [];
1444+
}
1445+
case (some(left(?attrs))) {
1446+
item_attrs = attrs;
1447+
}
1448+
case (some(right(?ext))) {
1449+
ret @spanned(lo, ext.span.hi,
1450+
ast::stmt_expr(ext, p.get_ann()));
1451+
}
1452+
}
1453+
1454+
alt (parse_item(p, item_attrs)) {
14271455
case (got_item(?i)) {
14281456
auto hi = i.span.hi;
14291457
auto decl = @spanned(lo, hi, ast::decl_item(i));
@@ -1936,6 +1964,26 @@ fn parse_item(&parser p, vec[ast::attribute] attrs) -> parsed_item {
19361964
} else { ret no_item; }
19371965
}
19381966

1967+
// A type to distingush between the parsing of item attributes or syntax
1968+
// extensions, which both begin with token.POUND
1969+
type attr_or_ext = option::t[either::t[vec[ast::attribute],
1970+
@ast::expr]];
1971+
1972+
fn parse_attrs_or_ext(&parser p) -> attr_or_ext {
1973+
if (p.peek() == token::POUND) {
1974+
auto lo = p.get_lo_pos();
1975+
p.bump();
1976+
if (p.peek() == token::LBRACKET) {
1977+
auto first_attr = parse_attribute_inner(p, lo);
1978+
ret some(left([first_attr] + parse_attributes(p)));
1979+
} else {
1980+
ret some(right(parse_syntax_ext_inner(p, lo)));
1981+
}
1982+
} else {
1983+
ret none;
1984+
}
1985+
}
1986+
19391987
fn parse_attributes(&parser p) -> vec[ast::attribute] {
19401988
let vec[ast::attribute] attrs = [];
19411989
while (p.peek() == token::POUND) { attrs += [parse_attribute(p)]; }
@@ -1945,6 +1993,10 @@ fn parse_attributes(&parser p) -> vec[ast::attribute] {
19451993
fn parse_attribute(&parser p) -> ast::attribute {
19461994
auto lo = p.get_lo_pos();
19471995
expect(p, token::POUND);
1996+
ret parse_attribute_inner(p, lo);
1997+
}
1998+
1999+
fn parse_attribute_inner(&parser p, uint lo) -> ast::attribute {
19482000
expect(p, token::LBRACKET);
19492001
auto meta_item = parse_meta_item(p);
19502002
expect(p, token::RBRACKET);
@@ -2181,13 +2233,7 @@ fn parse_crate_directive(&parser p) -> ast::crate_directive {
21812233
auto hi = p.get_hi_pos();
21822234
expect(p, token::RBRACE);
21832235
ret spanned(lo, hi, ast::cdir_let(id, x, v));
2184-
} else if (is_word(p, "use")) {
2185-
auto vi = parse_view_item(p);
2186-
ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
2187-
} else if (is_word(p, "import")) {
2188-
auto vi = parse_view_item(p);
2189-
ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
2190-
} else if (is_word(p, "export")) {
2236+
} else if (is_view_item(p)) {
21912237
auto vi = parse_view_item(p);
21922238
ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
21932239
} else {

0 commit comments

Comments
 (0)