Merge branch 'master' into recursive-elseif
Conflicts: src/comp/middle/typeck.rs
This commit is contained in:
commit
bbb6836da0
44 changed files with 1856 additions and 961 deletions
|
|
@ -253,6 +253,8 @@ type ast_fold[ENV] =
|
|||
(fn(&ENV e, &span sp, ident i, vec[ident] idents,
|
||||
def_id id, option.t[def]) -> @view_item) fold_view_item_import,
|
||||
|
||||
(fn(&ENV e, &span sp, ident i) -> @view_item) fold_view_item_export,
|
||||
|
||||
// Additional nodes.
|
||||
(fn(&ENV e, &span sp,
|
||||
&ast.block_) -> block) fold_block,
|
||||
|
|
@ -270,6 +272,7 @@ type ast_fold[ENV] =
|
|||
(fn(&ENV e, &ast.native_mod m) -> ast.native_mod) fold_native_mod,
|
||||
|
||||
(fn(&ENV e, &span sp,
|
||||
vec[@ast.crate_directive] cdirs,
|
||||
&ast._mod m) -> @ast.crate) fold_crate,
|
||||
|
||||
(fn(&ENV e,
|
||||
|
|
@ -451,11 +454,14 @@ fn fold_pat[ENV](&ENV env, ast_fold[ENV] fld, @ast.pat p) -> @ast.pat {
|
|||
ret fld.fold_pat_bind(env_, p.span, id, did, t);
|
||||
}
|
||||
case (ast.pat_tag(?path, ?pats, ?d, ?t)) {
|
||||
auto ppath = fold_path(env, fld, path);
|
||||
|
||||
let vec[@ast.pat] ppats = vec();
|
||||
for (@ast.pat pat in pats) {
|
||||
ppats += vec(fold_pat(env_, fld, pat));
|
||||
}
|
||||
ret fld.fold_pat_tag(env_, p.span, path, ppats, d, t);
|
||||
|
||||
ret fld.fold_pat_tag(env_, p.span, ppath, ppats, d, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -718,6 +724,7 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt {
|
|||
|
||||
fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
|
||||
|
||||
auto index = new_str_hash[ast.block_index_entry]();
|
||||
let ENV env_ = fld.update_env_for_block(env, blk);
|
||||
|
||||
if (!fld.keep_going(env_)) {
|
||||
|
|
@ -726,7 +733,9 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
|
|||
|
||||
let vec[@ast.stmt] stmts = vec();
|
||||
for (@ast.stmt s in blk.node.stmts) {
|
||||
append[@ast.stmt](stmts, fold_stmt[ENV](env_, fld, s));
|
||||
auto new_stmt = fold_stmt[ENV](env_, fld, s);
|
||||
append[@ast.stmt](stmts, new_stmt);
|
||||
ast.index_stmt(index, new_stmt);
|
||||
}
|
||||
|
||||
auto expr = none[@ast.expr];
|
||||
|
|
@ -739,8 +748,7 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: should we reindex?
|
||||
ret respan(blk.span, rec(stmts=stmts, expr=expr, index=blk.node.index));
|
||||
ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index));
|
||||
}
|
||||
|
||||
fn fold_arm[ENV](&ENV env, ast_fold[ENV] fld, &arm a) -> arm {
|
||||
|
|
@ -838,6 +846,10 @@ fn fold_view_item[ENV](&ENV env, ast_fold[ENV] fld, @view_item vi)
|
|||
ret fld.fold_view_item_import(env_, vi.span, def_ident, idents,
|
||||
def_id, target_def);
|
||||
}
|
||||
|
||||
case (ast.view_item_export(?def_ident)) {
|
||||
ret fld.fold_view_item_export(env_, vi.span, def_ident);
|
||||
}
|
||||
}
|
||||
|
||||
fail;
|
||||
|
|
@ -969,9 +981,12 @@ fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld,
|
|||
}
|
||||
|
||||
fn fold_crate[ENV](&ENV env, ast_fold[ENV] fld, @ast.crate c) -> @ast.crate {
|
||||
// FIXME: possibly fold the directives so you process any expressions
|
||||
// within them? Not clear. After front/eval.rs, nothing else should look
|
||||
// at crate directives.
|
||||
let ENV env_ = fld.update_env_for_crate(env, c);
|
||||
let ast._mod m = fold_mod[ENV](env_, fld, c.node.module);
|
||||
ret fld.fold_crate(env_, c.span, m);
|
||||
ret fld.fold_crate(env_, c.span, c.node.directives, m);
|
||||
}
|
||||
|
||||
//// Identity folds.
|
||||
|
|
@ -1324,6 +1339,11 @@ fn identity_fold_view_item_import[ENV](&ENV e, &span sp, ident i,
|
|||
ret @respan(sp, ast.view_item_import(i, is, id, target_def));
|
||||
}
|
||||
|
||||
fn identity_fold_view_item_export[ENV](&ENV e, &span sp, ident i)
|
||||
-> @view_item {
|
||||
ret @respan(sp, ast.view_item_export(i));
|
||||
}
|
||||
|
||||
// Additional identities.
|
||||
|
||||
fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block {
|
||||
|
|
@ -1353,8 +1373,10 @@ fn identity_fold_native_mod[ENV](&ENV e,
|
|||
ret m;
|
||||
}
|
||||
|
||||
fn identity_fold_crate[ENV](&ENV e, &span sp, &ast._mod m) -> @ast.crate {
|
||||
ret @respan(sp, rec(module=m));
|
||||
fn identity_fold_crate[ENV](&ENV e, &span sp,
|
||||
vec[@ast.crate_directive] cdirs,
|
||||
&ast._mod m) -> @ast.crate {
|
||||
ret @respan(sp, rec(directives=cdirs, module=m));
|
||||
}
|
||||
|
||||
fn identity_fold_obj[ENV](&ENV e,
|
||||
|
|
@ -1501,13 +1523,15 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
|||
bind identity_fold_view_item_use[ENV](_,_,_,_,_),
|
||||
fold_view_item_import =
|
||||
bind identity_fold_view_item_import[ENV](_,_,_,_,_,_),
|
||||
fold_view_item_export =
|
||||
bind identity_fold_view_item_export[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_mod = bind identity_fold_mod[ENV](_,_),
|
||||
fold_native_mod = bind identity_fold_native_mod[ENV](_,_),
|
||||
fold_crate = bind identity_fold_crate[ENV](_,_,_),
|
||||
fold_crate = bind identity_fold_crate[ENV](_,_,_,_),
|
||||
fold_obj = bind identity_fold_obj[ENV](_,_,_,_),
|
||||
|
||||
update_env_for_crate = bind identity_update_env_for_crate[ENV](_,_),
|
||||
|
|
|
|||
29
src/comp/middle/metadata.rs
Normal file
29
src/comp/middle/metadata.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import std._str;
|
||||
import front.ast;
|
||||
import middle.trans;
|
||||
import back.x86;
|
||||
|
||||
import lib.llvm.llvm;
|
||||
import lib.llvm.llvm.ValueRef;
|
||||
import lib.llvm.False;
|
||||
|
||||
// Returns a Plain Old LLVM String.
|
||||
fn C_postr(str s) -> ValueRef {
|
||||
ret llvm.LLVMConstString(_str.buf(s), _str.byte_len(s), False);
|
||||
}
|
||||
|
||||
fn collect_meta_directives(@trans.crate_ctxt cx, @ast.crate crate)
|
||||
-> ValueRef {
|
||||
ret C_postr("Hello world!"); // TODO
|
||||
}
|
||||
|
||||
fn write_metadata(@trans.crate_ctxt cx, @ast.crate crate) {
|
||||
auto llmeta = collect_meta_directives(cx, crate);
|
||||
|
||||
auto llconst = trans.C_struct(vec(llmeta));
|
||||
auto llglobal = llvm.LLVMAddGlobal(cx.llmod, trans.val_ty(llconst),
|
||||
_str.buf("rust_metadata"));
|
||||
llvm.LLVMSetInitializer(llglobal, llconst);
|
||||
llvm.LLVMSetSection(llglobal, _str.buf(x86.get_meta_sect_name()));
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +71,13 @@ fn unwrap_def(def_wrap d) -> def {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (def_wrap_native_mod(?m)) {
|
||||
alt (m.node) {
|
||||
case (ast.item_native_mod(_, _, ?id)) {
|
||||
ret ast.def_native_mod(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
case (def_wrap_other(?d)) {
|
||||
ret d;
|
||||
}
|
||||
|
|
@ -335,6 +342,40 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
|
|||
ret none[def_wrap];
|
||||
}
|
||||
|
||||
fn found_tag(@ast.item item, uint variant_idx) -> def_wrap {
|
||||
alt (item.node) {
|
||||
case (ast.item_tag(_, ?variants, _, ?tid)) {
|
||||
auto vid = variants.(variant_idx).id;
|
||||
auto t = ast.def_variant(tid, vid);
|
||||
ret def_wrap_other(t);
|
||||
}
|
||||
case (_) {
|
||||
log "tag item not actually a tag";
|
||||
fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_block(ast.ident i, &ast.block_ b) -> option.t[def_wrap] {
|
||||
alt (b.index.find(i)) {
|
||||
case (some[ast.block_index_entry](?ix)) {
|
||||
alt(ix) {
|
||||
case (ast.bie_item(?it)) {
|
||||
ret some(found_def_item(it));
|
||||
}
|
||||
case (ast.bie_local(?l)) {
|
||||
auto t = ast.def_local(l.id);
|
||||
ret some(def_wrap_other(t));
|
||||
}
|
||||
case (ast.bie_tag_variant(?item, ?variant_idx)) {
|
||||
ret some(found_tag(item, variant_idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
case (_) { ret none[def_wrap]; }
|
||||
}
|
||||
}
|
||||
|
||||
fn in_scope(ast.ident i, &scope s) -> option.t[def_wrap] {
|
||||
alt (s) {
|
||||
|
||||
|
|
@ -361,7 +402,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast.item_tag(_, _, ?ty_params, _)) {
|
||||
case (ast.item_tag(_, ?variants, ?ty_params, ?tag_id)) {
|
||||
for (ast.ty_param tp in ty_params) {
|
||||
if (_str.eq(tp.ident, i)) {
|
||||
auto t = ast.def_ty_arg(tp.id);
|
||||
|
|
@ -407,13 +448,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
|
|||
}
|
||||
|
||||
case (scope_block(?b)) {
|
||||
alt (b.node.index.find(i)) {
|
||||
case (some[uint](?ix)) {
|
||||
auto x = found_decl_stmt(b.node.stmts.(ix));
|
||||
ret some(x);
|
||||
}
|
||||
case (_) { /* fall through */ }
|
||||
}
|
||||
ret check_block(i, b.node);
|
||||
}
|
||||
|
||||
case (scope_arm(?a)) {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -81,87 +81,10 @@ tag unify_result {
|
|||
|
||||
// Stringification
|
||||
|
||||
fn ast_ty_to_str(&@ast.ty ty) -> str {
|
||||
|
||||
fn ast_fn_input_to_str(&rec(ast.mode mode, @ast.ty ty) input) -> str {
|
||||
auto s;
|
||||
if (mode_is_alias(input.mode)) {
|
||||
s = "&";
|
||||
} else {
|
||||
s = "";
|
||||
}
|
||||
|
||||
ret s + ast_ty_to_str(input.ty);
|
||||
}
|
||||
|
||||
fn ast_ty_field_to_str(&ast.ty_field f) -> str {
|
||||
ret ast_ty_to_str(f.ty) + " " + f.ident;
|
||||
}
|
||||
|
||||
auto s;
|
||||
alt (ty.node) {
|
||||
case (ast.ty_nil) { s = "()"; }
|
||||
case (ast.ty_bool) { s = "bool"; }
|
||||
case (ast.ty_int) { s = "int"; }
|
||||
case (ast.ty_uint) { s = "uint"; }
|
||||
case (ast.ty_machine(?tm)) { s = common.ty_mach_to_str(tm); }
|
||||
case (ast.ty_char) { s = "char"; }
|
||||
case (ast.ty_str) { s = "str"; }
|
||||
case (ast.ty_box(?t)) { s = "@" + ast_ty_to_str(t); }
|
||||
case (ast.ty_vec(?t)) { s = "vec[" + ast_ty_to_str(t) + "]"; }
|
||||
case (ast.ty_type) { s = "type"; }
|
||||
|
||||
case (ast.ty_tup(?elts)) {
|
||||
auto f = ast_ty_to_str;
|
||||
s = "tup(";
|
||||
s += _str.connect(_vec.map[@ast.ty,str](f, elts), ",");
|
||||
s += ")";
|
||||
}
|
||||
|
||||
case (ast.ty_rec(?fields)) {
|
||||
auto f = ast_ty_field_to_str;
|
||||
s = "rec(";
|
||||
s += _str.connect(_vec.map[ast.ty_field,str](f, fields), ",");
|
||||
s += ")";
|
||||
}
|
||||
|
||||
case (ast.ty_fn(?proto, ?inputs, ?output)) {
|
||||
auto f = ast_fn_input_to_str;
|
||||
if (proto == ast.proto_fn) {
|
||||
s = "fn(";
|
||||
} else {
|
||||
s = "iter(";
|
||||
}
|
||||
auto is = _vec.map[rec(ast.mode mode, @ast.ty ty),str](f, inputs);
|
||||
s += _str.connect(is, ", ");
|
||||
s += ")";
|
||||
|
||||
if (output.node != ast.ty_nil) {
|
||||
s += " -> " + ast_ty_to_str(output);
|
||||
}
|
||||
}
|
||||
|
||||
case (ast.ty_path(?path, _)) {
|
||||
s = path_to_str(path);
|
||||
}
|
||||
|
||||
case (ast.ty_mutable(?t)) {
|
||||
s = "mutable " + ast_ty_to_str(t);
|
||||
}
|
||||
|
||||
|
||||
case (_) {
|
||||
fail; // FIXME: typestate bug
|
||||
}
|
||||
}
|
||||
|
||||
ret s;
|
||||
}
|
||||
|
||||
fn path_to_str(&ast.path pth) -> str {
|
||||
auto result = _str.connect(pth.node.idents, ".");
|
||||
if (_vec.len[@ast.ty](pth.node.types) > 0u) {
|
||||
auto f = ast_ty_to_str;
|
||||
auto f = pretty.pprust.ty_to_str;
|
||||
result += "[";
|
||||
result += _str.connect(_vec.map[@ast.ty,str](f, pth.node.types), ",");
|
||||
result += "]";
|
||||
|
|
@ -169,8 +92,6 @@ fn path_to_str(&ast.path pth) -> str {
|
|||
ret result;
|
||||
}
|
||||
|
||||
// FIXME use the pretty-printer for this once it has a concept of an
|
||||
// abstract stream
|
||||
fn ty_to_str(&@t typ) -> str {
|
||||
|
||||
fn fn_input_to_str(&rec(ast.mode mode, @t ty) input) -> str {
|
||||
|
|
@ -452,6 +373,14 @@ fn get_element_type(@t ty, uint i) -> @t {
|
|||
fail;
|
||||
}
|
||||
|
||||
fn type_is_box(@t ty) -> bool {
|
||||
alt (ty.struct) {
|
||||
case (ty_box(_)) { ret true; }
|
||||
case (_) { ret false; }
|
||||
}
|
||||
fail;
|
||||
}
|
||||
|
||||
fn type_is_boxed(@t ty) -> bool {
|
||||
alt (ty.struct) {
|
||||
case (ty_str) { ret true; }
|
||||
|
|
@ -596,10 +525,10 @@ fn eq_ty(&@t a, &@t b) -> bool {
|
|||
fn ann_to_type(&ast.ann ann) -> @t {
|
||||
alt (ann) {
|
||||
case (ast.ann_none) {
|
||||
// shouldn't happen, but can until the typechecker is complete
|
||||
ret plain_ty(ty_var(-1)); // FIXME: broken, broken, broken
|
||||
log "ann_to_type() called on node with no type";
|
||||
fail;
|
||||
}
|
||||
case (ast.ann_type(?ty)) {
|
||||
case (ast.ann_type(?ty, _)) {
|
||||
ret ty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue