Skip to content

Commit 9742672

Browse files
committed
---
yaml --- r: 923 b: refs/heads/master c: c00bda5 h: refs/heads/master i: 921: ac1d934 919: 00c0479 v: v3
1 parent ab0de5b commit 9742672

File tree

6 files changed

+913
-50
lines changed

6 files changed

+913
-50
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: c410d685294e73a944f3e7cfe403f415a0cff849
2+
refs/heads/master: c00bda539d79e4411e086d505c697662942ee00b

trunk/src/comp/driver/rustc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import front.parser;
44
import front.token;
55
import middle.trans;
66
import middle.resolve;
7+
import middle.typeck;
78

89
import std.option;
910
import std.option.some;
@@ -15,6 +16,7 @@ impure fn compile_input(session.session sess, str input, str output) {
1516
auto p = parser.new_parser(sess, 0, input);
1617
auto crate = parser.parse_crate(p);
1718
crate = resolve.resolve_crate(sess, crate);
19+
crate = typeck.check_crate(sess, crate);
1820
trans.trans_crate(sess, crate, output);
1921
}
2022

trunk/src/comp/front/ast.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import std.map.hashmap;
33
import std.option;
4+
import middle.typeck;
45
import util.common.span;
56
import util.common.spanned;
67

@@ -17,7 +18,7 @@ type def_id = tup(crate_num, def_num);
1718
// Annotations added during successive passes.
1819
tag ann {
1920
ann_none;
20-
ann_type(@ty);
21+
ann_type(@typeck.ty);
2122
}
2223

2324
tag def {
@@ -119,6 +120,8 @@ tag lit_ {
119120
lit_bool(bool);
120121
}
121122

123+
// NB: If you change this, you'll probably want to change the corresponding
124+
// type structure in middle/typeck.rs as well.
122125
type ty = spanned[ty_];
123126
tag ty_ {
124127
ty_nil;

trunk/src/comp/middle/trans.rs

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import std.option.none;
99

1010
import front.ast;
1111
import driver.session;
12+
import middle.typeck;
1213
import back.x86;
1314
import back.abi;
1415

@@ -237,13 +238,13 @@ fn T_taskptr() -> TypeRef {
237238
ret T_ptr(T_task());
238239
}
239240

240-
fn type_of(@trans_ctxt cx, @ast.ty t) -> TypeRef {
241-
alt (t.node) {
242-
case (ast.ty_nil) { ret T_nil(); }
243-
case (ast.ty_bool) { ret T_bool(); }
244-
case (ast.ty_int) { ret T_int(); }
245-
case (ast.ty_uint) { ret T_int(); }
246-
case (ast.ty_machine(?tm)) {
241+
fn type_of(@trans_ctxt cx, @typeck.ty t) -> TypeRef {
242+
alt (t.struct) {
243+
case (typeck.ty_nil) { ret T_nil(); }
244+
case (typeck.ty_bool) { ret T_bool(); }
245+
case (typeck.ty_int) { ret T_int(); }
246+
case (typeck.ty_uint) { ret T_int(); }
247+
case (typeck.ty_machine(?tm)) {
247248
alt (tm) {
248249
case (common.ty_i8) { ret T_i8(); }
249250
case (common.ty_u8) { ret T_i8(); }
@@ -257,24 +258,25 @@ fn type_of(@trans_ctxt cx, @ast.ty t) -> TypeRef {
257258
case (common.ty_f64) { ret T_f64(); }
258259
}
259260
}
260-
case (ast.ty_char) { ret T_char(); }
261-
case (ast.ty_str) { ret T_str(0u); }
262-
case (ast.ty_box(?t)) {
261+
case (typeck.ty_char) { ret T_char(); }
262+
case (typeck.ty_str) { ret T_str(0u); }
263+
case (typeck.ty_box(?t)) {
263264
ret T_ptr(T_box(type_of(cx, t)));
264265
}
265-
case (ast.ty_vec(?t)) {
266+
case (typeck.ty_vec(?t)) {
266267
ret T_ptr(T_vec(type_of(cx, t), 0u));
267268
}
268-
case (ast.ty_tup(?elts)) {
269+
case (typeck.ty_tup(?elts)) {
269270
let vec[TypeRef] tys = vec();
270-
for (tup(bool, @ast.ty) elt in elts) {
271+
for (tup(bool, @typeck.ty) elt in elts) {
271272
tys += type_of(cx, elt._1);
272273
}
273274
ret T_struct(tys);
274275
}
275-
case (ast.ty_path(?pth, ?def)) {
276+
case (typeck.ty_var(_)) {
276277
// FIXME: implement.
277-
cx.sess.unimpl("ty_path in trans.type_of");
278+
log "ty_var in trans.type_of";
279+
ret T_i8();
278280
}
279281
}
280282
fail;
@@ -340,27 +342,23 @@ fn C_tydesc(TypeRef t) -> ValueRef {
340342
C_null(T_opaque()))); // is_stateful
341343
}
342344

343-
fn decl_fn(ModuleRef llmod, str name,
344-
uint cc, vec[TypeRef] inputs, TypeRef output) -> ValueRef {
345-
let TypeRef llty = T_fn(inputs, output);
345+
fn decl_fn(ModuleRef llmod, str name, uint cc, TypeRef llty) -> ValueRef {
346346
let ValueRef llfn =
347347
llvm.LLVMAddFunction(llmod, _str.buf(name), llty);
348348
llvm.LLVMSetFunctionCallConv(llfn, cc);
349349
ret llfn;
350350
}
351351

352-
fn decl_cdecl_fn(ModuleRef llmod, str name,
353-
vec[TypeRef] inputs, TypeRef output) -> ValueRef {
354-
ret decl_fn(llmod, name, lib.llvm.LLVMCCallConv, inputs, output);
352+
fn decl_cdecl_fn(ModuleRef llmod, str name, TypeRef llty) -> ValueRef {
353+
ret decl_fn(llmod, name, lib.llvm.LLVMCCallConv, llty);
355354
}
356355

357-
fn decl_fastcall_fn(ModuleRef llmod, str name,
358-
vec[TypeRef] inputs, TypeRef output) -> ValueRef {
359-
ret decl_fn(llmod, name, lib.llvm.LLVMFastCallConv, inputs, output);
356+
fn decl_fastcall_fn(ModuleRef llmod, str name, TypeRef llty) -> ValueRef {
357+
ret decl_fn(llmod, name, lib.llvm.LLVMFastCallConv, llty);
360358
}
361359

362360
fn decl_glue(ModuleRef llmod, str s) -> ValueRef {
363-
ret decl_cdecl_fn(llmod, s, vec(T_taskptr()), T_void());
361+
ret decl_cdecl_fn(llmod, s, T_fn(vec(T_taskptr()), T_void()));
364362
}
365363

366364
fn decl_upcall(ModuleRef llmod, uint _n) -> ValueRef {
@@ -375,7 +373,7 @@ fn decl_upcall(ModuleRef llmod, uint _n) -> ValueRef {
375373
T_int()) // callee
376374
+ _vec.init_elt[TypeRef](T_int(), n as uint);
377375

378-
ret decl_fastcall_fn(llmod, s, args, T_int());
376+
ret decl_fastcall_fn(llmod, s, T_fn(args, T_int()));
379377
}
380378

381379
fn get_upcall(@trans_ctxt cx, str name, int n_args) -> ValueRef {
@@ -385,7 +383,7 @@ fn get_upcall(@trans_ctxt cx, str name, int n_args) -> ValueRef {
385383
auto inputs = vec(T_taskptr());
386384
inputs += _vec.init_elt[TypeRef](T_int(), n_args as uint);
387385
auto output = T_int();
388-
auto f = decl_cdecl_fn(cx.llmod, name, inputs, output);
386+
auto f = decl_cdecl_fn(cx.llmod, name, T_fn(inputs, output));
389387
cx.upcalls.insert(name, f);
390388
ret f;
391389
}
@@ -937,6 +935,7 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
937935
case (ast.expr_call(?f, ?args, _)) {
938936
auto f_res = trans_lval(cx, *f);
939937
check (! f_res._1);
938+
940939
auto args_res = trans_exprs(f_res._0.bcx, args);
941940
auto llargs = vec(cx.fcx.lltaskptr);
942941
llargs += args_res._1;
@@ -1141,15 +1140,7 @@ impure fn trans_block(@block_ctxt cx, &ast.block b) -> result {
11411140
auto bcx = cx;
11421141

11431142
for each (@ast.local local in block_locals(b)) {
1144-
auto ty = T_nil();
1145-
alt (local.ty) {
1146-
case (some[@ast.ty](?t)) {
1147-
ty = type_of(cx.fcx.tcx, t);
1148-
}
1149-
case (none[@ast.ty]) {
1150-
cx.fcx.tcx.sess.err("missing type for local " + local.ident);
1151-
}
1152-
}
1143+
auto ty = node_type(cx.fcx.tcx, local.ann);
11531144
auto val = bcx.build.Alloca(ty);
11541145
cx.fcx.lllocals.insert(local.id, val);
11551146
}
@@ -1236,15 +1227,24 @@ impure fn trans_mod(@trans_ctxt cx, &ast._mod m) {
12361227

12371228
fn collect_item(&@trans_ctxt cx, @ast.item i) -> @trans_ctxt {
12381229
alt (i.node) {
1239-
case (ast.item_fn(?name, ?f, ?fid, _)) {
1240-
cx.items.insert(fid, i);
1241-
let TypeRef out = type_of(cx, f.output);
1242-
auto args = vec(T_taskptr());
1243-
for (ast.arg arg in f.inputs) {
1244-
args += type_of(cx, arg.ty);
1230+
case (ast.item_fn(?name, ?f, ?fid, ?ann)) {
1231+
auto fn_inputs;
1232+
auto fn_output;
1233+
alt (typeck.ann_to_type(ann).struct) {
1234+
case (typeck.ty_fn(?ins, ?out)) {
1235+
fn_inputs = ins;
1236+
fn_output = out;
1237+
}
1238+
case (_) {
1239+
log "trans: fn item doesn't have function type!";
1240+
fail;
1241+
}
12451242
}
1243+
1244+
cx.items.insert(fid, i);
1245+
auto llty = node_type(cx, ann);
12461246
let str s = cx.names.next("_rust_fn") + "." + name;
1247-
let ValueRef llfn = decl_fastcall_fn(cx.llmod, s, args, out);
1247+
let ValueRef llfn = decl_fastcall_fn(cx.llmod, s, llty);
12481248
cx.fn_ids.insert(fid, llfn);
12491249
}
12501250

@@ -1338,10 +1338,10 @@ fn trans_main_fn(@trans_ctxt cx, ValueRef llcrate) {
13381338
}
13391339

13401340
auto llmain =
1341-
decl_cdecl_fn(cx.llmod, main_name, T_main_args, T_int());
1341+
decl_cdecl_fn(cx.llmod, main_name, T_fn(T_main_args, T_int()));
13421342

1343-
auto llrust_start =
1344-
decl_cdecl_fn(cx.llmod, "rust_start", T_rust_start_args, T_int());
1343+
auto llrust_start = decl_cdecl_fn(cx.llmod, "rust_start",
1344+
T_fn(T_rust_start_args, T_int()));
13451345

13461346
auto llargc = llvm.LLVMGetParam(llmain, 0u);
13471347
auto llargv = llvm.LLVMGetParam(llmain, 1u);
@@ -1367,7 +1367,7 @@ fn trans_main_fn(@trans_ctxt cx, ValueRef llcrate) {
13671367

13681368
fn declare_intrinsics(ModuleRef llmod) {
13691369
let vec[TypeRef] T_trap_args = vec();
1370-
decl_cdecl_fn(llmod, "llvm.trap", T_trap_args, T_void());
1370+
decl_cdecl_fn(llmod, "llvm.trap", T_fn(T_trap_args, T_void()));
13711371
}
13721372

13731373
fn trans_crate(session.session sess, @ast.crate crate, str output) {
@@ -1396,7 +1396,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) {
13961396
*/
13971397
exit_task_glue =
13981398
decl_cdecl_fn(llmod, abi.exit_task_glue_name(),
1399-
vec(T_taskptr()), T_void()),
1399+
T_fn(vec(T_taskptr()), T_void())),
14001400

14011401
upcall_glues =
14021402
_vec.init_fn[ValueRef](bind decl_upcall(llmod, _),

0 commit comments

Comments
 (0)