diff options
| -rw-r--r-- | src/Makefile | 15 | ||||
| -rw-r--r-- | src/comp/back/x86.rs | 2 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 16 | ||||
| -rw-r--r-- | src/comp/middle/trans.rs | 99 |
4 files changed, 107 insertions, 25 deletions
diff --git a/src/Makefile b/src/Makefile index 3d5f5e86..94a0a75c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -500,7 +500,6 @@ TEST_XFAILS_SELF := $(filter-out \ $(addprefix test/run-pass/, \ bool-not.rs \ char.rs \ - div-mod.rs \ hello.rs \ int.rs \ item-name-overload.rs \ @@ -519,6 +518,9 @@ TEST_XFAILS_X86 += test/run-pass/native-mod.rc TEST_XFAILS_LLVM += test/run-pass/native-mod.rc TEST_XFAILS_SELF += test/run-pass/native-mod.rc endif +ifeq ($(CFG_OSTYPE), Darwin) +TEST_XFAILS_SELF += $(wildcard test/*/*.rs) +endif RPASS_RC := $(wildcard test/run-pass/*.rc) RPASS_RS := $(wildcard test/run-pass/*.rs) @@ -704,7 +706,8 @@ test/run-pass/%.out.tmp: test/run-pass/%$(CFG_EXE_SUFFIX) $(CFG_RUNTIME) @$(call CFG_ECHO, run: $<) $(CFG_QUIET)$(call CFG_RUN_TARG, $<) > $@ -test/run-fail/%-boot.out.tmp: test/run-fail/%$(CFG_EXE_SUFFIX) $(CFG_RUNTIME) +test/run-fail/%-boot.x86.out.tmp: test/run-fail/%-boot.x86$(CFG_EXE_SUFFIX) \ + $(CFG_RUNTIME) $(CFG_QUIET)rm -f $<.tmp @$(call CFG_ECHO, run: $<) $(CFG_QUIET)rm -f $@ @@ -712,7 +715,7 @@ test/run-fail/%-boot.out.tmp: test/run-fail/%$(CFG_EXE_SUFFIX) $(CFG_RUNTIME) if [ $$X -eq 0 ] ; then exit 1 ; else exit 0 ; fi $(CFG_QUIET)grep --text --quiet \ "`awk -F: '/error-pattern/ { print $$2 }' \ - $(basename $(basename $(basename $@ -boot.out.tmp))).rs \ + $(subst -boot.x86.out.tmp,.rs,$@) \ | tr -d '\n\r'`" $@ test/compile-fail/%-boot.x86.out.tmp: test/compile-fail/%.rs $(BREQ) @@ -923,9 +926,9 @@ clean: $(CFG_QUIET)rm -f $(CFG_BOOT) $(CFG_RUNTIME) $(CFG_STDLIB) $(CFG_QUIET)rm -Rf $(PKG_NAME)-*.tar.gz dist $(CFG_QUIET)rm -f $(foreach ext,cmx cmi cmo cma o a d exe,\ - $(wildcard boot/*/*.$(ext) boot/*/*/*.$(ext))) \ - $(CFG_QUIET)rm -f $(foreach ext,out llvm x86 o s exe dSYM,\ - $(wildcard test/*/*.$(ext))) \ + $(wildcard boot/*/*.$(ext) boot/*/*/*.$(ext))) + $(CFG_QUIET)rm -Rf $(foreach ext,out llvm x86 o s exe dSYM,\ + $(wildcard test/*/*.$(ext))) # Local Variables: diff --git a/src/comp/back/x86.rs b/src/comp/back/x86.rs index 86631e93..0a5fc506 100644 --- a/src/comp/back/x86.rs +++ b/src/comp/back/x86.rs @@ -131,7 +131,7 @@ fn get_module_asm() -> str { auto align = 4; auto prefix = ""; - if (target_os() == "macos") { + if (_str.eq(target_os(), "macos")) { prefix = "_"; } diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 42ffc4c6..ceb68609 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -705,6 +705,22 @@ io fn parse_stmt(parser p) -> @ast.stmt { } } + case (token.RET) { + p.bump(); + alt (p.peek()) { + case (token.SEMI) { + p.bump(); + ret @spanned(lo, p.get_span(), + ast.stmt_ret(none[@ast.expr])); + } + case (_) { + auto e = parse_expr(p); + expect(p, token.SEMI); + ret @spanned(lo, e.span, + ast.stmt_ret(some[@ast.expr](e))); + } + } + } case (token.LET) { auto decl = parse_let(p); diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index cc1af53f..1a05f76e 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -45,6 +45,7 @@ state type trans_ctxt = rec(session.session sess, hashmap[str, ValueRef] upcalls, hashmap[str, ValueRef] fn_names, hashmap[ast.def_id, ValueRef] fn_ids, + hashmap[ast.def_id, @ast.item] items, @glue_fns glues, namegen names, str path); @@ -656,21 +657,24 @@ fn trans_if(@block_ctxt cx, &ast.expr cond, // (that is represented as an alloca, hence needs a 'load' to be // used as an rval). -fn trans_lval(@block_ctxt cx, &ast.expr e) -> tup(result, bool) { +fn trans_lval(@block_ctxt cx, &ast.expr e) + -> tup(result, bool, ast.def_id) { alt (e.node) { case (ast.expr_name(?n, ?dopt, _)) { alt (dopt) { case (some[ast.def](?def)) { alt (def) { case (ast.def_arg(?did)) { - ret tup(res(cx, cx.fcx.llargs.get(did)), false); + ret tup(res(cx, cx.fcx.llargs.get(did)), + false, did); } case (ast.def_local(?did)) { - ret tup(res(cx, cx.fcx.lllocals.get(did)), true); + ret tup(res(cx, cx.fcx.lllocals.get(did)), + true, did); } case (ast.def_fn(?did)) { ret tup(res(cx, cx.fcx.tcx.fn_ids.get(did)), - false); + false, did); } case (_) { cx.fcx.tcx.sess.unimpl("def variant in trans"); @@ -750,8 +754,18 @@ fn trans_expr(@block_ctxt cx, &ast.expr e) -> result { case (ast.expr_call(?f, ?args, _)) { auto f_res = trans_lval(cx, *f); check (! f_res._1); + + // FIXME: Revolting hack to get the type of the outptr. Can get a + // variety of other ways; will wait until we have a typechecker + // perhaps to pick a more tasteful one. + auto outptr = cx.fcx.lloutptr; + alt (cx.fcx.tcx.items.get(f_res._2).node) { + case (ast.item_fn(_, ?ff, _)) { + outptr = cx.build.Alloca(type_of(cx.fcx.tcx, ff.output)); + } + } auto args_res = trans_exprs(f_res._0.bcx, args); - auto llargs = vec(cx.fcx.lloutptr, + auto llargs = vec(outptr, cx.fcx.lltaskptr); llargs += args_res._1; ret res(args_res._0, @@ -811,6 +825,22 @@ fn trans_check_expr(@block_ctxt cx, &ast.expr e) -> result { ret res(next_cx, C_nil()); } +fn trans_ret(@block_ctxt cx, &option[@ast.expr] e) -> result { + auto r = res(cx, C_nil()); + alt (e) { + case (some[@ast.expr](?x)) { + r = trans_expr(cx, *x); + r.bcx.build.Store(r.val, cx.fcx.lloutptr); + } + } + // FIXME: if we actually ret here, the block structure falls apart; + // need to do something more-clever with terminators and block cleanup. + // Mean time 'ret' means 'copy result to output slot and keep going'. + + // r.val = r.bcx.build.RetVoid(); + ret r; +} + fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result { auto sub = res(cx, C_nil()); alt (s.node) { @@ -822,6 +852,10 @@ fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result { sub.bcx = trans_check_expr(cx, *a).bcx; } + case (ast.stmt_ret(?e)) { + sub.bcx = trans_ret(cx, e).bcx; + } + case (ast.stmt_expr(?e)) { sub.bcx = trans_expr(cx, *e).bcx; } @@ -954,20 +988,8 @@ fn new_fn_ctxt(@trans_ctxt cx, &ast._fn f, ast.def_id fid) -> @fn_ctxt { - let vec[TypeRef] args = vec(T_ptr(type_of(cx, f.output)), // outptr. - T_taskptr() // taskptr - ); - let uint arg_n = _vec.len[TypeRef](args); - - let vec[TypeRef] T_explicit_args = vec(); - for (ast.arg arg in f.inputs) { - T_explicit_args += type_of(cx, arg.ty); - } - args += T_explicit_args; - - let ValueRef llfn = decl_cdecl_fn(cx.llmod, name, args, T_void()); + let ValueRef llfn = cx.fn_ids.get(fid); cx.fn_names.insert(cx.path, llfn); - cx.fn_ids.insert(fid, llfn); let ValueRef lloutptr = llvm.LLVMGetParam(llfn, 0u); let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 1u); @@ -975,6 +997,7 @@ fn new_fn_ctxt(@trans_ctxt cx, let hashmap[ast.def_id, ValueRef] lllocals = new_def_hash[ValueRef](); let hashmap[ast.def_id, ValueRef] llargs = new_def_hash[ValueRef](); + let uint arg_n = 2u; for (ast.arg arg in f.inputs) { llargs.insert(arg.id, llvm.LLVMGetParam(llfn, arg_n)); arg_n += 1u; @@ -1015,6 +1038,44 @@ fn trans_mod(@trans_ctxt cx, &ast._mod m) { } +fn collect_item(&@trans_ctxt cx, @ast.item i) -> @trans_ctxt { + alt (i.node) { + case (ast.item_fn(?name, ?f, ?fid)) { + cx.items.insert(fid, i); + let vec[TypeRef] args = + vec(T_ptr(type_of(cx, f.output)), // outptr. + T_taskptr() // taskptr + ); + let vec[TypeRef] T_explicit_args = vec(); + for (ast.arg arg in f.inputs) { + T_explicit_args += type_of(cx, arg.ty); + } + args += T_explicit_args; + + let str s = cx.names.next("_rust_fn") + "." + name; + let ValueRef llfn = decl_cdecl_fn(cx.llmod, s, args, T_void()); + cx.fn_ids.insert(fid, llfn); + } + + case (ast.item_mod(?name, ?m, ?mid)) { + cx.items.insert(mid, i); + } + } + ret cx; +} + + +fn collect_items(@trans_ctxt cx, @ast.crate crate) { + + let fold.ast_fold[@trans_ctxt] fld = + fold.new_identity_fold[@trans_ctxt](); + + fld = @rec( update_env_for_item = bind collect_item(_,_) + with *fld ); + + fold.fold_crate[@trans_ctxt](cx, fld, crate); +} + fn p2i(ValueRef v) -> ValueRef { ret llvm.LLVMConstPtrToInt(v, T_int()); } @@ -1143,10 +1204,12 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) { upcalls = new_str_hash[ValueRef](), fn_names = new_str_hash[ValueRef](), fn_ids = new_def_hash[ValueRef](), + items = new_def_hash[@ast.item](), glues = glues, names = namegen(0), path = "_rust"); + collect_items(cx, crate); trans_mod(cx, crate.node.module); trans_exit_task_glue(cx); trans_main_fn(cx, crate_constant(cx)); |