Skip to content

Commit 3712ee6

Browse files
committed
Sketch of wiring typeck up to creader.
1 parent 739c4ae commit 3712ee6

File tree

4 files changed

+70
-32
lines changed

4 files changed

+70
-32
lines changed

src/comp/driver/rustc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ impure fn main(vec[str] args) {
114114
float_type = common.ty_f64 );
115115

116116
auto crate_cache = common.new_int_hash[session.crate_metadata]();
117+
auto target_crate_num = 0;
118+
auto sess = session.session(target_crate_num, target_cfg, crate_cache);
117119

118-
auto sess = session.session(target_cfg, crate_cache);
119120
let option.t[str] input_file = none[str];
120121
let option.t[str] output_file = none[str];
121122
let vec[str] library_search_paths = vec();

src/comp/driver/session.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import front.ast;
12
import util.common.span;
23
import util.common.ty_mach;
34
import std._uint;
@@ -23,12 +24,17 @@ type cfg = rec(os os,
2324

2425
type crate_metadata = vec[u8];
2526

26-
obj session(cfg targ, map.hashmap[int, crate_metadata] crates) {
27+
obj session(ast.crate_num cnum, cfg targ,
28+
map.hashmap[int, crate_metadata] crates) {
2729

2830
fn get_targ_cfg() -> cfg {
2931
ret targ;
3032
}
3133

34+
fn get_targ_crate_num() -> ast.crate_num {
35+
ret cnum;
36+
}
37+
3238
fn span_err(span sp, str msg) {
3339
log #fmt("%s:%u:%u:%u:%u: error: %s",
3440
sp.filename,

src/comp/front/creader.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import lib.llvm.mk_object_file;
99
import lib.llvm.mk_section_iter;
1010
import middle.fold;
1111
import middle.ty;
12+
import middle.typeck;
1213
import back.x86;
1314
import util.common;
1415
import util.common.span;
@@ -285,6 +286,11 @@ fn lookup_def(session.session sess, &span sp, int cnum, vec[ast.ident] path)
285286
fail;
286287
}
287288

289+
fn get_type(session.session sess, ast.def_id def) -> typeck.ty_and_params {
290+
// FIXME: fill in.
291+
fail;
292+
}
293+
288294
// Local Variables:
289295
// mode: rust
290296
// fill-column: 78;

src/comp/middle/typeck.rs

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import front.ast;
22
import front.ast.ann;
33
import front.ast.mutability;
4+
import front.creader;
45
import middle.fold;
56
import driver.session;
67
import util.common;
@@ -404,6 +405,12 @@ fn actual_type(@ty.t t, @ast.item item) -> @ty.t {
404405
// ast_ty_to_ty.
405406
fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast.ty ast_ty) -> @ty.t {
406407
fn getter(@crate_ctxt ccx, ast.def_id id) -> ty_and_params {
408+
409+
if (id._0 != ccx.sess.get_targ_crate_num()) {
410+
// This is a type we need to load in from the crate reader.
411+
ret creader.get_type(ccx.sess, id);
412+
}
413+
407414
check (ccx.item_items.contains_key(id));
408415
check (ccx.item_types.contains_key(id));
409416
auto it = ccx.item_items.get(id);
@@ -500,21 +507,29 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
500507
fn collect_item_types(session.session sess, @ast.crate crate)
501508
-> tup(@ast.crate, @ty_table, @ty_item_table, @ty_param_table) {
502509

503-
fn getter(@ty_item_table id_to_ty_item,
510+
fn getter(session.session sess,
511+
@ty_item_table id_to_ty_item,
504512
@ty_table item_to_ty,
505513
ast.def_id id) -> ty_and_params {
514+
515+
if (id._0 != sess.get_targ_crate_num()) {
516+
// This is a type we need to load in from the crate reader.
517+
ret creader.get_type(sess, id);
518+
}
519+
506520
check (id_to_ty_item.contains_key(id));
521+
507522
auto it = id_to_ty_item.get(id);
508523
auto ty;
509524
auto params;
510525
alt (it) {
511526
case (any_item_rust(?item)) {
512-
ty = ty_of_item(id_to_ty_item, item_to_ty, item);
527+
ty = ty_of_item(sess, id_to_ty_item, item_to_ty, item);
513528
ty = actual_type(ty, item);
514529
params = ty_params_of_item(item);
515530
}
516531
case (any_item_native(?native_item, ?abi)) {
517-
ty = ty_of_native_item(id_to_ty_item, item_to_ty,
532+
ty = ty_of_native_item(sess, id_to_ty_item, item_to_ty,
518533
native_item, abi);
519534
params = ty_params_of_native_item(native_item);
520535
}
@@ -523,30 +538,33 @@ fn collect_item_types(session.session sess, @ast.crate crate)
523538
ret rec(params = params, ty = ty);
524539
}
525540

526-
fn ty_of_arg(@ty_item_table id_to_ty_item,
541+
fn ty_of_arg(session.session sess,
542+
@ty_item_table id_to_ty_item,
527543
@ty_table item_to_ty,
528544
&ast.arg a) -> arg {
529-
auto f = bind getter(id_to_ty_item, item_to_ty, _);
545+
auto f = bind getter(sess, id_to_ty_item, item_to_ty, _);
530546
ret rec(mode=a.mode, ty=ast_ty_to_ty(f, a.ty));
531547
}
532548

533-
fn ty_of_method(@ty_item_table id_to_ty_item,
549+
fn ty_of_method(session.session sess,
550+
@ty_item_table id_to_ty_item,
534551
@ty_table item_to_ty,
535552
&@ast.method m) -> method {
536-
auto get = bind getter(id_to_ty_item, item_to_ty, _);
553+
auto get = bind getter(sess, id_to_ty_item, item_to_ty, _);
537554
auto convert = bind ast_ty_to_ty(get, _);
538-
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
555+
auto f = bind ty_of_arg(sess, id_to_ty_item, item_to_ty, _);
539556
auto inputs = _vec.map[ast.arg,arg](f, m.node.meth.decl.inputs);
540557
auto output = convert(m.node.meth.decl.output);
541558
ret rec(proto=m.node.meth.proto, ident=m.node.ident,
542559
inputs=inputs, output=output);
543560
}
544561

545-
fn ty_of_obj(@ty_item_table id_to_ty_item,
562+
fn ty_of_obj(session.session sess,
563+
@ty_item_table id_to_ty_item,
546564
@ty_table item_to_ty,
547565
&ast.ident id,
548566
&ast._obj obj_info) -> @ty.t {
549-
auto f = bind ty_of_method(id_to_ty_item, item_to_ty, _);
567+
auto f = bind ty_of_method(sess, id_to_ty_item, item_to_ty, _);
550568
auto methods =
551569
_vec.map[@ast.method,method](f, obj_info.methods);
552570

@@ -555,26 +573,29 @@ fn collect_item_types(session.session sess, @ast.crate crate)
555573
ret t_obj;
556574
}
557575

558-
fn ty_of_obj_ctor(@ty_item_table id_to_ty_item,
576+
fn ty_of_obj_ctor(session.session sess,
577+
@ty_item_table id_to_ty_item,
559578
@ty_table item_to_ty,
560579
&ast.ident id,
561580
&ast._obj obj_info) -> @ty.t {
562-
auto t_obj = ty_of_obj(id_to_ty_item, item_to_ty, id, obj_info);
581+
auto t_obj = ty_of_obj(sess, id_to_ty_item, item_to_ty,
582+
id, obj_info);
563583
let vec[arg] t_inputs = vec();
564584
for (ast.obj_field f in obj_info.fields) {
565-
auto g = bind getter(id_to_ty_item, item_to_ty, _);
585+
auto g = bind getter(sess, id_to_ty_item, item_to_ty, _);
566586
auto t_field = ast_ty_to_ty(g, f.ty);
567587
_vec.push[arg](t_inputs, rec(mode=ast.alias, ty=t_field));
568588
}
569589
auto t_fn = plain_ty(ty.ty_fn(ast.proto_fn, t_inputs, t_obj));
570590
ret t_fn;
571591
}
572592

573-
fn ty_of_item(@ty_item_table id_to_ty_item,
593+
fn ty_of_item(session.session sess,
594+
@ty_item_table id_to_ty_item,
574595
@ty_table item_to_ty,
575596
@ast.item it) -> @ty.t {
576597

577-
auto get = bind getter(id_to_ty_item, item_to_ty, _);
598+
auto get = bind getter(sess, id_to_ty_item, item_to_ty, _);
578599
auto convert = bind ast_ty_to_ty(get, _);
579600

580601
alt (it.node) {
@@ -584,14 +605,15 @@ fn collect_item_types(session.session sess, @ast.crate crate)
584605
}
585606

586607
case (ast.item_fn(?ident, ?fn_info, _, ?def_id, _)) {
587-
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
588-
ret ty_of_fn_decl(id_to_ty_item, item_to_ty, convert, f,
589-
fn_info.decl, fn_info.proto, def_id);
608+
auto f = bind ty_of_arg(sess, id_to_ty_item, item_to_ty, _);
609+
ret ty_of_fn_decl(id_to_ty_item, item_to_ty, convert,
610+
f, fn_info.decl, fn_info.proto, def_id);
590611
}
591612

592613
case (ast.item_obj(?ident, ?obj_info, _, ?def_id, _)) {
593614
// TODO: handle ty-params
594-
auto t_ctor = ty_of_obj_ctor(id_to_ty_item,
615+
auto t_ctor = ty_of_obj_ctor(sess,
616+
id_to_ty_item,
595617
item_to_ty,
596618
ident,
597619
obj_info);
@@ -628,18 +650,19 @@ fn collect_item_types(session.session sess, @ast.crate crate)
628650
}
629651
}
630652

631-
fn ty_of_native_item(@ty_item_table id_to_ty_item,
653+
fn ty_of_native_item(session.session sess,
654+
@ty_item_table id_to_ty_item,
632655
@ty_table item_to_ty,
633656
@ast.native_item it,
634657
ast.native_abi abi) -> @ty.t {
635658
alt (it.node) {
636659
case (ast.native_item_fn(?ident, ?lname, ?fn_decl,
637660
?params, ?def_id, _)) {
638-
auto get = bind getter(id_to_ty_item, item_to_ty, _);
661+
auto get = bind getter(sess, id_to_ty_item, item_to_ty, _);
639662
auto convert = bind ast_ty_to_ty(get, _);
640-
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
641-
ret ty_of_native_fn_decl(id_to_ty_item, item_to_ty, convert,
642-
f, fn_decl, abi, def_id);
663+
auto f = bind ty_of_arg(sess, id_to_ty_item, item_to_ty, _);
664+
ret ty_of_native_fn_decl(id_to_ty_item, item_to_ty,
665+
convert, f, fn_decl, abi, def_id);
643666
}
644667
case (ast.native_item_ty(_, ?def_id)) {
645668
if (item_to_ty.contains_key(def_id)) {
@@ -653,7 +676,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
653676
}
654677
}
655678

656-
fn get_tag_variant_types(@ty_item_table id_to_ty_item,
679+
fn get_tag_variant_types(session.session sess,
680+
@ty_item_table id_to_ty_item,
657681
@ty_table item_to_ty,
658682
&ast.def_id tag_id,
659683
&vec[ast.variant] variants,
@@ -676,7 +700,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
676700
} else {
677701
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
678702
// should be called to resolve named types.
679-
auto f = bind getter(id_to_ty_item, item_to_ty, _);
703+
auto f = bind getter(sess, id_to_ty_item, item_to_ty, _);
680704

681705
let vec[arg] args = vec();
682706
for (ast.variant_arg va in variant.args) {
@@ -778,14 +802,14 @@ fn collect_item_types(session.session sess, @ast.crate crate)
778802
case (_) {
779803
// This call populates the ty_table with the converted type of
780804
// the item in passing; we don't need to do anything else.
781-
ty_of_item(e.id_to_ty_item, e.item_to_ty, i);
805+
ty_of_item(e.sess, e.id_to_ty_item, e.item_to_ty, i);
782806
}
783807
}
784808
ret @rec(abi=abi with *e);
785809
}
786810

787811
fn convert_native(&@env e, @ast.native_item i) -> @env {
788-
ty_of_native_item(e.id_to_ty_item, e.item_to_ty, i, e.abi);
812+
ty_of_native_item(e.sess, e.id_to_ty_item, e.item_to_ty, i, e.abi);
789813
ret e;
790814
}
791815

@@ -872,7 +896,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
872896
m = @rec(node=m_ with *meth);
873897
_vec.push[@ast.method](methods, m);
874898
}
875-
auto g = bind getter(e.id_to_ty_item, e.item_to_ty, _);
899+
auto g = bind getter(e.sess, e.id_to_ty_item, e.item_to_ty, _);
876900
for (ast.obj_field fld in ob.fields) {
877901
let @ty.t fty = ast_ty_to_ty(g, fld.ty);
878902
let ast.obj_field f = rec(
@@ -908,7 +932,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
908932
ast.def_id id) -> @ast.item {
909933
collect_ty_params(e, id, ty_params);
910934

911-
auto variants_t = get_tag_variant_types(e.id_to_ty_item,
935+
auto variants_t = get_tag_variant_types(e.sess,
936+
e.id_to_ty_item,
912937
e.item_to_ty,
913938
id,
914939
variants,

0 commit comments

Comments
 (0)