mirror of https://github.com/rust-lang/rust.git
Remove effect system from src.
This commit is contained in:
parent
d9d5eb82a7
commit
d2bd07dcb0
|
@ -264,7 +264,7 @@ BOOT_MLS := \
|
|||
extfmt pexp item cexp fuzz) \
|
||||
$(addprefix boot/be/, asm il abi) \
|
||||
$(addprefix boot/me/, walk semant resolve alias \
|
||||
simplify type dead layer effect typestate \
|
||||
simplify type dead layer typestate \
|
||||
loop layout transutil trans dwarf) \
|
||||
$(addprefix boot/be/, x86 ra pe elf macho) \
|
||||
$(addprefix boot/driver/, lib glue main)) \
|
||||
|
|
|
@ -43,7 +43,6 @@ let (sess:Session.sess) =
|
|||
Session.sess_log_type = false;
|
||||
Session.sess_log_simplify = false;
|
||||
Session.sess_log_layer = false;
|
||||
Session.sess_log_effect = false;
|
||||
Session.sess_log_typestate = false;
|
||||
Session.sess_log_loop = false;
|
||||
Session.sess_log_alias = false;
|
||||
|
@ -192,8 +191,6 @@ let argspecs =
|
|||
"-lsimplify" "log simplification");
|
||||
(flag (fun _ -> sess.Session.sess_log_layer <- true)
|
||||
"-llayer" "log layer checking");
|
||||
(flag (fun _ -> sess.Session.sess_log_effect <- true)
|
||||
"-leffect" "log effect checking");
|
||||
(flag (fun _ -> sess.Session.sess_log_typestate <- true)
|
||||
"-ltypestate" "log typestate pass");
|
||||
(flag (fun _ -> sess.Session.sess_log_loop <- true)
|
||||
|
@ -408,7 +405,6 @@ let main_pipeline _ =
|
|||
Type.process_crate;
|
||||
Typestate.process_crate;
|
||||
Layer.process_crate;
|
||||
Effect.process_crate;
|
||||
Loop.process_crate;
|
||||
Alias.process_crate;
|
||||
Dead.process_crate;
|
||||
|
|
|
@ -25,7 +25,6 @@ type sess =
|
|||
mutable sess_log_type: bool;
|
||||
mutable sess_log_simplify: bool;
|
||||
mutable sess_log_layer: bool;
|
||||
mutable sess_log_effect: bool;
|
||||
mutable sess_log_typestate: bool;
|
||||
mutable sess_log_dead: bool;
|
||||
mutable sess_log_loop: bool;
|
||||
|
|
|
@ -28,10 +28,7 @@ type slot_key =
|
|||
write foo[int,int].bar but not foo.bar.
|
||||
*)
|
||||
|
||||
type effect =
|
||||
EFF_pure
|
||||
| EFF_impure
|
||||
| EFF_unsafe
|
||||
type auth = AUTH_unsafe
|
||||
;;
|
||||
|
||||
type layer =
|
||||
|
@ -174,7 +171,6 @@ and ty_sig =
|
|||
and ty_fn_aux =
|
||||
{
|
||||
fn_is_iter: bool;
|
||||
fn_effect: effect;
|
||||
}
|
||||
|
||||
and ty_fn = (ty_sig * ty_fn_aux)
|
||||
|
@ -485,7 +481,7 @@ and crate' =
|
|||
{
|
||||
crate_items: (mod_view * mod_items);
|
||||
crate_meta: Session.meta;
|
||||
crate_auth: (name, effect) Hashtbl.t;
|
||||
crate_auth: (name, auth) Hashtbl.t;
|
||||
crate_required: (node_id, (required_lib * nabi_conv)) Hashtbl.t;
|
||||
crate_required_syms: (node_id, string) Hashtbl.t;
|
||||
crate_files: (node_id,filename) Hashtbl.t;
|
||||
|
@ -708,22 +704,6 @@ and fmt_slots
|
|||
done;
|
||||
fmt ff "@])"
|
||||
|
||||
and fmt_effect
|
||||
(ff:Format.formatter)
|
||||
(effect:effect)
|
||||
: unit =
|
||||
match effect with
|
||||
EFF_pure -> ()
|
||||
| EFF_impure -> fmt ff "impure"
|
||||
| EFF_unsafe -> fmt ff "unsafe"
|
||||
|
||||
and fmt_effect_qual
|
||||
(ff:Format.formatter)
|
||||
(e:effect)
|
||||
: unit =
|
||||
fmt_effect ff e;
|
||||
if e <> EFF_pure then fmt ff " ";
|
||||
|
||||
and fmt_layer
|
||||
(ff:Format.formatter)
|
||||
(la:layer)
|
||||
|
@ -762,7 +742,6 @@ and fmt_ty_fn
|
|||
(tf:ty_fn)
|
||||
: unit =
|
||||
let (tsig, ta) = tf in
|
||||
fmt_effect_qual ff ta.fn_effect;
|
||||
fmt ff "%s" (if ta.fn_is_iter then "iter" else "fn");
|
||||
begin
|
||||
match ident_and_params with
|
||||
|
@ -1667,7 +1646,6 @@ and fmt_fn
|
|||
(f:fn)
|
||||
: unit =
|
||||
fmt_obox ff;
|
||||
fmt_effect_qual ff f.fn_aux.fn_effect;
|
||||
fmt ff "%s "(if f.fn_aux.fn_is_iter then "iter" else "fn");
|
||||
fmt_ident_and_params ff id params;
|
||||
fmt_header_slots ff f.fn_input_slots;
|
||||
|
@ -1816,7 +1794,6 @@ let sprintf_atom = sprintf_fmt fmt_atom;;
|
|||
let sprintf_slot = sprintf_fmt fmt_slot;;
|
||||
let sprintf_slot_key = sprintf_fmt fmt_slot_key;;
|
||||
let sprintf_ty = sprintf_fmt fmt_ty;;
|
||||
let sprintf_effect = sprintf_fmt fmt_effect;;
|
||||
let sprintf_carg = sprintf_fmt fmt_carg;;
|
||||
let sprintf_constr = sprintf_fmt fmt_constr;;
|
||||
let sprintf_mod_item =
|
||||
|
|
|
@ -29,7 +29,7 @@ type meta = (Ast.ident * Ast.pexp) array;;
|
|||
|
||||
type meta_pat = (Ast.ident * (Ast.pexp option)) array;;
|
||||
|
||||
type auth = (Ast.name * Ast.effect);;
|
||||
type auth = (Ast.name * Ast.auth);;
|
||||
|
||||
type cexp =
|
||||
CEXP_alt of cexp_alt identified
|
||||
|
@ -274,10 +274,10 @@ and parse_cexp (ps:pstate) : cexp =
|
|||
bump ps;
|
||||
let name = Pexp.parse_name ps in
|
||||
expect ps EQ;
|
||||
let effect = Pexp.parse_effect ps in
|
||||
let au = Pexp.parse_auth ps in
|
||||
expect ps SEMI;
|
||||
let bpos = lexpos ps in
|
||||
CEXP_auth (span ps apos bpos (name, effect))
|
||||
CEXP_auth (span ps apos bpos (name, au))
|
||||
|
||||
| _ -> raise (unexpected ps)
|
||||
|
||||
|
|
|
@ -610,7 +610,6 @@ and parse_stmts_including_none (ps:pstate) : Ast.stmt array =
|
|||
|
||||
|
||||
| STATE | GC
|
||||
| IMPURE | UNSAFE
|
||||
| ABS | NATIVE
|
||||
| MOD | OBJ | TAG | TYPE | FN | USE ->
|
||||
let items = ctxt "stmt: decl" parse_mod_item ps in
|
||||
|
@ -794,7 +793,6 @@ and parse_in_and_out
|
|||
(* parse_fn starts at the first lparen of the sig. *)
|
||||
and parse_fn
|
||||
(is_iter:bool)
|
||||
(effect:Ast.effect)
|
||||
(ps:pstate)
|
||||
: Ast.fn =
|
||||
let (inputs, constrs, output) =
|
||||
|
@ -804,8 +802,7 @@ and parse_fn
|
|||
{ Ast.fn_input_slots = inputs;
|
||||
Ast.fn_input_constrs = constrs;
|
||||
Ast.fn_output_slot = output;
|
||||
Ast.fn_aux = { Ast.fn_effect = effect;
|
||||
Ast.fn_is_iter = is_iter; };
|
||||
Ast.fn_aux = { Ast.fn_is_iter = is_iter; };
|
||||
Ast.fn_body = body; }
|
||||
|
||||
and parse_meta_input (ps:pstate) : (Ast.ident * string option) =
|
||||
|
@ -859,12 +856,11 @@ and parse_obj_item
|
|||
do
|
||||
let apos = lexpos ps in
|
||||
match peek ps with
|
||||
IMPURE | UNSAFE | FN | ITER ->
|
||||
let effect = Pexp.parse_effect ps in
|
||||
FN | ITER ->
|
||||
let is_iter = (peek ps) = ITER in
|
||||
bump ps;
|
||||
let ident = ctxt "obj fn: ident" Pexp.parse_ident ps in
|
||||
let fn = ctxt "obj fn: fn" (parse_fn is_iter effect) ps in
|
||||
let fn = ctxt "obj fn: fn" (parse_fn is_iter) ps in
|
||||
let bpos = lexpos ps in
|
||||
htab_put fns ident (span ps apos bpos fn)
|
||||
| DROP ->
|
||||
|
@ -994,24 +990,17 @@ and parse_mod_item (ps:pstate)
|
|||
|
||||
match peek ps with
|
||||
|
||||
STATE | GC | IMPURE | UNSAFE | ABS
|
||||
STATE | GC | ABS
|
||||
| TYPE | OBJ | TAG | FN | ITER ->
|
||||
let _ = Pexp.parse_opacity ps in
|
||||
let layer = Pexp.parse_layer ps in
|
||||
let effect = Pexp.parse_effect ps in
|
||||
begin
|
||||
match peek ps with
|
||||
OBJ ->
|
||||
if effect <> Ast.EFF_pure
|
||||
then raise (err "effect specified for obj" ps);
|
||||
[| parse_obj_item ps apos layer |]
|
||||
| TAG ->
|
||||
if effect <> Ast.EFF_pure
|
||||
then raise (err "effect specified for tag" ps);
|
||||
parse_tag_item ps apos layer
|
||||
| TYPE ->
|
||||
if effect <> Ast.EFF_pure
|
||||
then raise (err "effect specified for type" ps);
|
||||
[| parse_type_item ps apos layer |]
|
||||
| _ ->
|
||||
if layer <> Ast.LAYER_value
|
||||
|
@ -1020,7 +1009,7 @@ and parse_mod_item (ps:pstate)
|
|||
bump ps;
|
||||
let (ident, params) = parse_ident_and_params ps "fn" in
|
||||
let fn =
|
||||
ctxt "mod fn item: fn" (parse_fn is_iter effect) ps
|
||||
ctxt "mod fn item: fn" (parse_fn is_iter) ps
|
||||
in
|
||||
let bpos = lexpos ps in
|
||||
[| (ident,
|
||||
|
@ -1119,8 +1108,7 @@ and parse_native_mod_item_from_signature (ps:pstate)
|
|||
[| (ident,
|
||||
span ps apos bpos (decl params (Ast.MOD_ITEM_mod items))) |]
|
||||
|
||||
| IMPURE | UNSAFE | FN | ITER ->
|
||||
let effect = Pexp.parse_effect ps in
|
||||
| FN | ITER ->
|
||||
let is_iter = (peek ps) = ITER in
|
||||
bump ps;
|
||||
let (ident, params) = parse_ident_and_params ps "fn signature" in
|
||||
|
@ -1132,8 +1120,7 @@ and parse_native_mod_item_from_signature (ps:pstate)
|
|||
{ Ast.fn_input_slots = inputs;
|
||||
Ast.fn_input_constrs = constrs;
|
||||
Ast.fn_output_slot = output;
|
||||
Ast.fn_aux = { Ast.fn_effect = effect;
|
||||
Ast.fn_is_iter = is_iter; };
|
||||
Ast.fn_aux = { Ast.fn_is_iter = is_iter; };
|
||||
Ast.fn_body = body; }
|
||||
in
|
||||
let node = span ps apos bpos (decl params fn) in
|
||||
|
|
|
@ -100,7 +100,6 @@
|
|||
("state", STATE);
|
||||
("gc", GC);
|
||||
|
||||
("impure", IMPURE);
|
||||
("unsafe", UNSAFE);
|
||||
|
||||
("native", NATIVE);
|
||||
|
|
|
@ -151,11 +151,10 @@ and parse_layer (ps:pstate) : Ast.layer =
|
|||
| GC -> bump ps; Ast.LAYER_gc
|
||||
| _ -> Ast.LAYER_value
|
||||
|
||||
and parse_effect (ps:pstate) : Ast.effect =
|
||||
and parse_auth (ps:pstate) : Ast.auth =
|
||||
match peek ps with
|
||||
IMPURE -> bump ps; Ast.EFF_impure
|
||||
| UNSAFE -> bump ps; Ast.EFF_unsafe
|
||||
| _ -> Ast.EFF_pure
|
||||
| UNSAFE -> bump ps; Ast.AUTH_unsafe
|
||||
| _ -> raise (unexpected ps)
|
||||
|
||||
and parse_mutability (ps:pstate) : Ast.mutability =
|
||||
match peek ps with
|
||||
|
@ -170,7 +169,6 @@ and parse_mutability (ps:pstate) : Ast.mutability =
|
|||
| _ -> Ast.MUT_immutable
|
||||
|
||||
and parse_ty_fn
|
||||
(effect:Ast.effect)
|
||||
(ps:pstate)
|
||||
: (Ast.ty_fn * Ast.ident option) =
|
||||
match peek ps with
|
||||
|
@ -198,8 +196,7 @@ and parse_ty_fn
|
|||
Ast.sig_input_constrs = constrs;
|
||||
Ast.sig_output_slot = out_slot; }
|
||||
in
|
||||
let taux = { Ast.fn_effect = effect;
|
||||
Ast.fn_is_iter = is_iter; }
|
||||
let taux = { Ast.fn_is_iter = is_iter; }
|
||||
in
|
||||
let tfn = (tsig, taux) in
|
||||
(tfn, ident)
|
||||
|
@ -280,19 +277,15 @@ and parse_atomic_ty (ps:pstate) : Ast.ty =
|
|||
bump ps;
|
||||
Ast.TY_mach m
|
||||
|
||||
| STATE | GC | IMPURE | UNSAFE | OBJ | FN | ITER ->
|
||||
| STATE | GC | UNSAFE | OBJ | FN | ITER ->
|
||||
let layer = parse_layer ps in
|
||||
let effect = parse_effect ps in
|
||||
begin
|
||||
match peek ps with
|
||||
OBJ ->
|
||||
bump ps;
|
||||
if effect <> Ast.EFF_pure
|
||||
then raise (err "effect specified for obj" ps);
|
||||
let methods = Hashtbl.create 0 in
|
||||
let parse_method ps =
|
||||
let effect = parse_effect ps in
|
||||
let (tfn, ident) = parse_ty_fn effect ps in
|
||||
let (tfn, ident) = parse_ty_fn ps in
|
||||
expect ps SEMI;
|
||||
match ident with
|
||||
None ->
|
||||
|
@ -307,7 +300,7 @@ and parse_atomic_ty (ps:pstate) : Ast.ty =
|
|||
| FN | ITER ->
|
||||
if layer <> Ast.LAYER_value
|
||||
then raise (err "layer specified for fn or iter" ps);
|
||||
Ast.TY_fn (fst (parse_ty_fn effect ps))
|
||||
Ast.TY_fn (fst (parse_ty_fn ps))
|
||||
| _ -> raise (unexpected ps)
|
||||
end
|
||||
|
||||
|
|
|
@ -87,8 +87,7 @@ type token =
|
|||
| STATE
|
||||
| GC
|
||||
|
||||
(* Effect keywords *)
|
||||
| IMPURE
|
||||
(* Unsafe-block keyword *)
|
||||
| UNSAFE
|
||||
|
||||
(* Type qualifiers *)
|
||||
|
@ -251,8 +250,7 @@ let rec string_of_tok t =
|
|||
| STATE -> "state"
|
||||
| GC -> "gc"
|
||||
|
||||
(* Effect keywords *)
|
||||
| IMPURE -> "impure"
|
||||
(* Unsafe-block keyword *)
|
||||
| UNSAFE -> "unsafe"
|
||||
|
||||
(* Type qualifiers *)
|
||||
|
|
|
@ -1205,8 +1205,6 @@ let (abbrev_subprogram:abbrev) =
|
|||
(DW_AT_high_pc, DW_FORM_addr);
|
||||
(DW_AT_frame_base, DW_FORM_block1);
|
||||
(DW_AT_return_addr, DW_FORM_block1);
|
||||
(DW_AT_mutable, DW_FORM_flag);
|
||||
(DW_AT_pure, DW_FORM_flag);
|
||||
(DW_AT_rust_iterator, DW_FORM_flag);
|
||||
|])
|
||||
;;
|
||||
|
@ -1389,8 +1387,6 @@ let (abbrev_subroutine_type:abbrev) =
|
|||
(DW_TAG_subroutine_type, DW_CHILDREN_yes,
|
||||
[|
|
||||
(DW_AT_type, DW_FORM_ref_addr); (* NB: output type. *)
|
||||
(DW_AT_mutable, DW_FORM_flag);
|
||||
(DW_AT_pure, DW_FORM_flag);
|
||||
(DW_AT_rust_iterator, DW_FORM_flag);
|
||||
|])
|
||||
;;
|
||||
|
@ -1408,8 +1404,6 @@ let (abbrev_obj_subroutine_type:abbrev) =
|
|||
[|
|
||||
(DW_AT_name, DW_FORM_string);
|
||||
(DW_AT_type, DW_FORM_ref_addr); (* NB: output type. *)
|
||||
(DW_AT_mutable, DW_FORM_flag);
|
||||
(DW_AT_pure, DW_FORM_flag);
|
||||
(DW_AT_rust_iterator, DW_FORM_flag);
|
||||
|])
|
||||
;;
|
||||
|
@ -1523,26 +1517,10 @@ let dwarf_visitor
|
|||
SUB ((M_POS fix), M_POS cu_info_section_fixup))
|
||||
in
|
||||
|
||||
let encode_effect eff =
|
||||
(* Note: weird encoding: mutable+pure = unsafe. *)
|
||||
let mut_byte, pure_byte =
|
||||
match eff with
|
||||
Ast.EFF_unsafe -> (1,1)
|
||||
| Ast.EFF_impure -> (0,0)
|
||||
| Ast.EFF_pure -> (0,1)
|
||||
in
|
||||
SEQ [|
|
||||
(* DW_AT_mutable: DW_FORM_flag *)
|
||||
BYTE mut_byte;
|
||||
(* DW_AT_pure: DW_FORM_flag *)
|
||||
BYTE pure_byte;
|
||||
|]
|
||||
in
|
||||
|
||||
let encode_layer eff =
|
||||
let encode_layer lyr =
|
||||
(* Note: weird encoding: mutable+pure = gc. *)
|
||||
let mut_byte, pure_byte =
|
||||
match eff with
|
||||
match lyr with
|
||||
Ast.LAYER_value -> (0,1)
|
||||
| Ast.LAYER_state -> (1,0)
|
||||
| Ast.LAYER_gc -> (1,1)
|
||||
|
@ -1855,7 +1833,6 @@ let dwarf_visitor
|
|||
uleb (get_abbrev_code abbrev_subroutine_type);
|
||||
(* DW_AT_type: DW_FORM_ref_addr *)
|
||||
(ref_slot_die tsig.Ast.sig_output_slot);
|
||||
encode_effect taux.Ast.fn_effect;
|
||||
(* DW_AT_rust_iterator: DW_FORM_flag *)
|
||||
BYTE (if taux.Ast.fn_is_iter then 1 else 0)
|
||||
|])
|
||||
|
@ -1876,7 +1853,6 @@ let dwarf_visitor
|
|||
ZSTRING ident;
|
||||
(* DW_AT_type: DW_FORM_ref_addr *)
|
||||
(ref_slot_die tsig.Ast.sig_output_slot);
|
||||
encode_effect taux.Ast.fn_effect;
|
||||
(* DW_AT_rust_iterator: DW_FORM_flag *)
|
||||
BYTE (if taux.Ast.fn_is_iter then 1 else 0)
|
||||
|]
|
||||
|
@ -2295,7 +2271,6 @@ let dwarf_visitor
|
|||
let emit_subprogram_die
|
||||
(id:Ast.ident)
|
||||
(ret_slot:Ast.slot)
|
||||
(effect:Ast.effect)
|
||||
(iter:bool)
|
||||
(fix:fixup)
|
||||
: unit =
|
||||
|
@ -2315,7 +2290,6 @@ let dwarf_visitor
|
|||
dw_form_block1 [| DW_OP_reg abi.Abi.abi_dwarf_fp_reg |];
|
||||
(* DW_AT_return_addr *)
|
||||
dw_form_block1 [| DW_OP_fbreg (Asm.IMM retpc); |];
|
||||
encode_effect effect;
|
||||
(* DW_AT_rust_iterator: DW_FORM_flag *)
|
||||
BYTE (if iter then 1 else 0)
|
||||
|])
|
||||
|
@ -2429,7 +2403,7 @@ let dwarf_visitor
|
|||
(Array.length item.node.Ast.decl_params);
|
||||
emit_subprogram_die
|
||||
id tsig.Ast.sig_output_slot
|
||||
taux.Ast.fn_effect taux.Ast.fn_is_iter
|
||||
taux.Ast.fn_is_iter
|
||||
(Hashtbl.find cx.ctxt_fn_fixups item.id);
|
||||
emit_type_param_decl_dies item.node.Ast.decl_params;
|
||||
end
|
||||
|
@ -2900,15 +2874,6 @@ let rec extract_mod_items
|
|||
| _ -> bug () "unexpected non-flag form for %s" (dw_at_to_string attr)
|
||||
in
|
||||
|
||||
let get_effect die =
|
||||
match (get_flag die DW_AT_mutable, get_flag die DW_AT_pure) with
|
||||
(* Note: weird encoding: mutable+pure = unsafe. *)
|
||||
(true, true) -> Ast.EFF_unsafe
|
||||
| (false, false) -> Ast.EFF_impure
|
||||
| (false, true) -> Ast.EFF_pure
|
||||
| _ -> failwith "bad effect encoding"
|
||||
in
|
||||
|
||||
let get_layer die =
|
||||
match (get_flag die DW_AT_mutable, get_flag die DW_AT_pure) with
|
||||
(* Note: weird encoding: mutable+pure = gc. *)
|
||||
|
@ -3123,7 +3088,6 @@ let rec extract_mod_items
|
|||
else None
|
||||
end
|
||||
in
|
||||
let effect = get_effect die in
|
||||
let iter = get_flag die DW_AT_rust_iterator in
|
||||
let tsig =
|
||||
{ Ast.sig_input_slots = ins;
|
||||
|
@ -3131,8 +3095,7 @@ let rec extract_mod_items
|
|||
Ast.sig_output_slot = out; }
|
||||
in
|
||||
let taux =
|
||||
{ Ast.fn_is_iter = iter;
|
||||
Ast.fn_effect = effect }
|
||||
{ Ast.fn_is_iter = iter; }
|
||||
in
|
||||
(tsig, taux)
|
||||
in
|
||||
|
@ -3223,11 +3186,9 @@ let rec extract_mod_items
|
|||
(* FIXME (issue #74): finish this. *)
|
||||
let ident = get_name die in
|
||||
let oslot = get_referenced_slot die in
|
||||
let effect = get_effect die in
|
||||
let iter = get_flag die DW_AT_rust_iterator in
|
||||
let (params, islots) = get_formals die in
|
||||
let taux = { Ast.fn_effect = effect;
|
||||
Ast.fn_is_iter = iter }
|
||||
let taux = { Ast.fn_is_iter = iter }
|
||||
in
|
||||
let tfn = { Ast.fn_input_slots = form_header_slots islots;
|
||||
Ast.fn_input_constrs = [| |];
|
||||
|
|
|
@ -1,317 +0,0 @@
|
|||
open Semant;;
|
||||
open Common;;
|
||||
|
||||
let log cx = Session.log "effect"
|
||||
(should_log cx cx.ctxt_sess.Session.sess_log_effect)
|
||||
cx.ctxt_sess.Session.sess_log_out
|
||||
;;
|
||||
|
||||
let iflog cx thunk =
|
||||
if (should_log cx cx.ctxt_sess.Session.sess_log_effect)
|
||||
then thunk ()
|
||||
else ()
|
||||
;;
|
||||
|
||||
let effect_calculating_visitor
|
||||
(item_effect:(node_id, Ast.effect) Hashtbl.t)
|
||||
(cx:ctxt)
|
||||
(inner:Walk.visitor)
|
||||
: Walk.visitor =
|
||||
(*
|
||||
* This visitor calculates the effect of each function according to
|
||||
* its statements:
|
||||
*
|
||||
* - Communication statements lower to 'impure'
|
||||
* - Writing to anything other than a local slot lowers to 'impure'
|
||||
* - Native calls lower to 'unsafe'
|
||||
* - Calling a function with effect e lowers to e.
|
||||
*)
|
||||
let curr_fn = Stack.create () in
|
||||
|
||||
let visit_mod_item_pre n p i =
|
||||
begin
|
||||
match i.node.Ast.decl_item with
|
||||
Ast.MOD_ITEM_fn _ -> Stack.push i.id curr_fn
|
||||
| _ -> ()
|
||||
end;
|
||||
inner.Walk.visit_mod_item_pre n p i
|
||||
in
|
||||
|
||||
let visit_mod_item_post n p i =
|
||||
inner.Walk.visit_mod_item_post n p i;
|
||||
match i.node.Ast.decl_item with
|
||||
Ast.MOD_ITEM_fn _ -> ignore (Stack.pop curr_fn)
|
||||
| _ -> ()
|
||||
in
|
||||
|
||||
let visit_obj_fn_pre o i fi =
|
||||
Stack.push fi.id curr_fn;
|
||||
inner.Walk.visit_obj_fn_pre o i fi
|
||||
in
|
||||
|
||||
let visit_obj_fn_post o i fi =
|
||||
inner.Walk.visit_obj_fn_post o i fi;
|
||||
ignore (Stack.pop curr_fn)
|
||||
in
|
||||
|
||||
let visit_obj_drop_pre o b =
|
||||
Stack.push b.id curr_fn;
|
||||
inner.Walk.visit_obj_drop_pre o b
|
||||
in
|
||||
|
||||
let visit_obj_drop_post o b =
|
||||
inner.Walk.visit_obj_drop_post o b;
|
||||
ignore (Stack.pop curr_fn);
|
||||
in
|
||||
|
||||
let lower_to s ne =
|
||||
let fn_id = Stack.top curr_fn in
|
||||
let e =
|
||||
match htab_search item_effect fn_id with
|
||||
None -> Ast.EFF_pure
|
||||
| Some e -> e
|
||||
in
|
||||
let ne = lower_effect_of ne e in
|
||||
if ne <> e
|
||||
then
|
||||
begin
|
||||
iflog cx
|
||||
begin
|
||||
fun _ ->
|
||||
let name = Hashtbl.find cx.ctxt_all_item_names fn_id in
|
||||
log cx "lowering calculated effect on '%a': '%a' -> '%a'"
|
||||
Ast.sprintf_name name
|
||||
Ast.sprintf_effect e
|
||||
Ast.sprintf_effect ne;
|
||||
log cx "at stmt %a" Ast.sprintf_stmt s
|
||||
end;
|
||||
Hashtbl.replace item_effect fn_id ne
|
||||
end;
|
||||
in
|
||||
|
||||
let note_write s dst =
|
||||
(* FIXME (issue #182): this is too aggressive; won't permit writes to
|
||||
* interior components of records or tuples. It should at least do that,
|
||||
* possibly handle escape analysis on the pointee for things like vecs as
|
||||
* well. *)
|
||||
if lval_base_is_slot cx dst
|
||||
then
|
||||
let base_slot = lval_base_slot cx dst in
|
||||
match dst, base_slot.Ast.slot_mode with
|
||||
(Ast.LVAL_base _, Ast.MODE_local) -> ()
|
||||
| _ -> lower_to s Ast.EFF_impure
|
||||
in
|
||||
|
||||
let visit_stmt_pre s =
|
||||
begin
|
||||
match s.node with
|
||||
Ast.STMT_send _
|
||||
| Ast.STMT_recv _ -> lower_to s Ast.EFF_impure
|
||||
|
||||
| Ast.STMT_call (lv_dst, fn, _) ->
|
||||
note_write s lv_dst;
|
||||
let lower_to_callee_ty t =
|
||||
match simplified_ty t with
|
||||
Ast.TY_fn (_, taux) ->
|
||||
lower_to s taux.Ast.fn_effect;
|
||||
| _ -> bug () "non-fn callee"
|
||||
in
|
||||
if lval_base_is_slot cx fn
|
||||
then
|
||||
lower_to_callee_ty (lval_ty cx fn)
|
||||
else
|
||||
begin
|
||||
let item = lval_item cx fn in
|
||||
let t = Hashtbl.find cx.ctxt_all_item_types item.id in
|
||||
lower_to_callee_ty t;
|
||||
match htab_search cx.ctxt_required_items item.id with
|
||||
None -> ()
|
||||
| Some (REQUIRED_LIB_rust _, _) -> ()
|
||||
| Some _ -> lower_to s Ast.EFF_unsafe
|
||||
end
|
||||
|
||||
| Ast.STMT_copy (lv_dst, _)
|
||||
| Ast.STMT_spawn (lv_dst, _, _, _, _)
|
||||
| Ast.STMT_bind (lv_dst, _, _)
|
||||
| Ast.STMT_new_rec (lv_dst, _, _)
|
||||
| Ast.STMT_new_tup (lv_dst, _)
|
||||
| Ast.STMT_new_vec (lv_dst, _, _)
|
||||
| Ast.STMT_new_str (lv_dst, _)
|
||||
| Ast.STMT_new_port lv_dst
|
||||
| Ast.STMT_new_chan (lv_dst, _)
|
||||
| Ast.STMT_new_box (lv_dst, _, _) ->
|
||||
note_write s lv_dst
|
||||
|
||||
| _ -> ()
|
||||
end;
|
||||
inner.Walk.visit_stmt_pre s
|
||||
in
|
||||
|
||||
{ inner with
|
||||
Walk.visit_mod_item_pre = visit_mod_item_pre;
|
||||
Walk.visit_mod_item_post = visit_mod_item_post;
|
||||
Walk.visit_obj_fn_pre = visit_obj_fn_pre;
|
||||
Walk.visit_obj_fn_post = visit_obj_fn_post;
|
||||
Walk.visit_obj_drop_pre = visit_obj_drop_pre;
|
||||
Walk.visit_obj_drop_post = visit_obj_drop_post;
|
||||
Walk.visit_stmt_pre = visit_stmt_pre }
|
||||
;;
|
||||
|
||||
|
||||
let effect_checking_visitor
|
||||
(item_auth:(node_id, Ast.effect) Hashtbl.t)
|
||||
(item_effect:(node_id, Ast.effect) Hashtbl.t)
|
||||
(cx:ctxt)
|
||||
(inner:Walk.visitor)
|
||||
: Walk.visitor =
|
||||
(*
|
||||
* This visitor checks that each fn declares
|
||||
* effects consistent with what we calculated.
|
||||
*)
|
||||
let auth_stack = Stack.create () in
|
||||
let visit_mod_item_pre n p i =
|
||||
begin
|
||||
match htab_search item_auth i.id with
|
||||
None -> ()
|
||||
| Some e ->
|
||||
let curr =
|
||||
if Stack.is_empty auth_stack
|
||||
then Ast.EFF_pure
|
||||
else Stack.top auth_stack
|
||||
in
|
||||
Stack.push e auth_stack;
|
||||
iflog cx
|
||||
begin
|
||||
fun _ ->
|
||||
let name = Hashtbl.find cx.ctxt_all_item_names i.id in
|
||||
log cx
|
||||
"entering '%a', adjusting auth effect: '%a' -> '%a'"
|
||||
Ast.sprintf_name name
|
||||
Ast.sprintf_effect curr
|
||||
Ast.sprintf_effect e
|
||||
end
|
||||
end;
|
||||
let report_mismatch declared_effect calculated_effect =
|
||||
let name = Hashtbl.find cx.ctxt_all_item_names i.id in
|
||||
err (Some i.id)
|
||||
"%a claims effect '%a' but calculated effect is '%a'%s"
|
||||
Ast.sprintf_name name
|
||||
Ast.sprintf_effect declared_effect
|
||||
Ast.sprintf_effect calculated_effect
|
||||
begin
|
||||
if Stack.is_empty auth_stack
|
||||
then ""
|
||||
else
|
||||
Printf.sprintf " (auth effects are '%s')"
|
||||
(stk_fold
|
||||
auth_stack
|
||||
(fun e s ->
|
||||
if s = ""
|
||||
then
|
||||
Printf.sprintf "%a"
|
||||
Ast.sprintf_effect e
|
||||
else
|
||||
Printf.sprintf "%s, %a" s
|
||||
Ast.sprintf_effect e) "")
|
||||
end
|
||||
in
|
||||
begin
|
||||
match i.node.Ast.decl_item with
|
||||
Ast.MOD_ITEM_fn f
|
||||
when htab_search cx.ctxt_required_items i.id = None ->
|
||||
let calculated_effect =
|
||||
match htab_search item_effect i.id with
|
||||
None -> Ast.EFF_pure
|
||||
| Some e -> e
|
||||
in
|
||||
let declared_effect = f.Ast.fn_aux.Ast.fn_effect in
|
||||
if calculated_effect <> declared_effect
|
||||
then
|
||||
(* Something's fishy in this case. If the calculated effect
|
||||
* is equal to one auth'ed by an enclosing scope -- not just
|
||||
* a lower one -- we accept this mismatch; otherwise we
|
||||
* complain.
|
||||
*
|
||||
* FIXME: this choice of "what constitutes an error" in
|
||||
* auth/effect mismatches is subjective and could do
|
||||
* with some discussion. *)
|
||||
begin
|
||||
match
|
||||
stk_search auth_stack
|
||||
(fun e ->
|
||||
if e = calculated_effect then Some e else None)
|
||||
with
|
||||
Some _ -> ()
|
||||
| None ->
|
||||
report_mismatch declared_effect calculated_effect
|
||||
end
|
||||
| _ -> ()
|
||||
end;
|
||||
inner.Walk.visit_mod_item_pre n p i
|
||||
in
|
||||
let visit_mod_item_post n p i =
|
||||
inner.Walk.visit_mod_item_post n p i;
|
||||
match htab_search item_auth i.id with
|
||||
None -> ()
|
||||
| Some _ ->
|
||||
let curr = Stack.pop auth_stack in
|
||||
let next =
|
||||
if Stack.is_empty auth_stack
|
||||
then Ast.EFF_pure
|
||||
else Stack.top auth_stack
|
||||
in
|
||||
iflog cx
|
||||
begin
|
||||
fun _ ->
|
||||
let name = Hashtbl.find cx.ctxt_all_item_names i.id in
|
||||
log cx
|
||||
"leaving '%a', restoring auth effect: '%a' -> '%a'"
|
||||
Ast.sprintf_name name
|
||||
Ast.sprintf_effect curr
|
||||
Ast.sprintf_effect next
|
||||
end
|
||||
in
|
||||
{ inner with
|
||||
Walk.visit_mod_item_pre = visit_mod_item_pre;
|
||||
Walk.visit_mod_item_post = visit_mod_item_post; }
|
||||
;;
|
||||
|
||||
|
||||
let process_crate
|
||||
(_cx:ctxt)
|
||||
(_crate:Ast.crate)
|
||||
: unit = (*
|
||||
let item_auth = Hashtbl.create 0 in
|
||||
let item_effect = Hashtbl.create 0 in
|
||||
let passes =
|
||||
[|
|
||||
(effect_calculating_visitor item_effect cx
|
||||
Walk.empty_visitor);
|
||||
(effect_checking_visitor item_auth item_effect cx
|
||||
Walk.empty_visitor);
|
||||
|]
|
||||
in
|
||||
let root_scope = [ SCOPE_crate crate ] in
|
||||
let auth_effect name eff =
|
||||
match lookup_by_name cx [] root_scope name with
|
||||
RES_failed _ -> ()
|
||||
| RES_ok (_, id) ->
|
||||
if defn_id_is_item cx id
|
||||
then htab_put item_auth id eff
|
||||
else err (Some id) "auth clause in crate refers to non-item"
|
||||
in
|
||||
Hashtbl.iter auth_effect crate.node.Ast.crate_auth;
|
||||
run_passes cx "effect" passes
|
||||
cx.ctxt_sess.Session.sess_log_effect log crate
|
||||
*)
|
||||
()
|
||||
;;
|
||||
|
||||
(*
|
||||
* Local Variables:
|
||||
* fill-column: 78;
|
||||
* indent-tabs-mode: nil
|
||||
* buffer-file-coding-system: utf-8-unix
|
||||
* compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
* End:
|
||||
*)
|
|
@ -1010,13 +1010,11 @@ let rec pretty_ty_str (cx:ctxt) (fallback:(Ast.ty -> string)) (ty:Ast.ty) =
|
|||
None -> Common.bug () "no ty in slot"
|
||||
| Some ty' -> prefix ^ (pretty_ty_str cx fallback ty')
|
||||
in
|
||||
let effect = aux.Ast.fn_effect in
|
||||
let qual = Fmt.sprintf_fmt Ast.fmt_effect_qual () effect in
|
||||
let keyword = if aux.Ast.fn_is_iter then "iter" else "fn" in
|
||||
let fn_args = Array.map format_slot fnsig.Ast.sig_input_slots in
|
||||
let fn_args_str = String.concat ", " (Array.to_list fn_args) in
|
||||
let fn_rv_str = format_slot fnsig.Ast.sig_output_slot in
|
||||
Printf.sprintf "%s%s(%s) -> %s" qual keyword fn_args_str fn_rv_str
|
||||
Printf.sprintf "%s(%s) -> %s" keyword fn_args_str fn_rv_str
|
||||
| Ast.TY_tag { Ast.tag_id = tag_id; Ast.tag_args = _ }
|
||||
when Hashtbl.mem cx.ctxt_user_tag_names tag_id ->
|
||||
let name = Hashtbl.find cx.ctxt_user_tag_names tag_id in
|
||||
|
@ -1156,8 +1154,7 @@ let generic_fn_ty =
|
|||
Ast.sig_output_slot =
|
||||
{ Ast.slot_mode = Ast.MODE_local;
|
||||
Ast.slot_ty = Some Ast.TY_nil }; },
|
||||
{ Ast.fn_is_iter = false;
|
||||
Ast.fn_effect = Ast.EFF_pure })
|
||||
{ Ast.fn_is_iter = false })
|
||||
;;
|
||||
|
||||
let rec get_genericized_ty ty =
|
||||
|
@ -1271,19 +1268,6 @@ let type_points_to_heap (cx:ctxt) (t:Ast.ty) : bool =
|
|||
|
||||
(* Type qualifier analysis. *)
|
||||
|
||||
let effect_le x y =
|
||||
match (x,y) with
|
||||
(Ast.EFF_unsafe, _) -> true
|
||||
| (Ast.EFF_impure, Ast.EFF_pure) -> true
|
||||
| (Ast.EFF_impure, Ast.EFF_impure) -> true
|
||||
| (Ast.EFF_pure, Ast.EFF_pure) -> true
|
||||
| _ -> false
|
||||
;;
|
||||
|
||||
let lower_effect_of x y =
|
||||
if effect_le x y then x else y
|
||||
;;
|
||||
|
||||
let layer_le x y =
|
||||
match (x,y) with
|
||||
(Ast.LAYER_gc, _) -> true
|
||||
|
@ -1682,8 +1666,7 @@ let ty_of_mod_item (item:Ast.mod_item) : Ast.ty =
|
|||
| Ast.MOD_ITEM_mod _ -> bug () "Semant.ty_of_mod_item on mod"
|
||||
| Ast.MOD_ITEM_const (ty, _) -> ty
|
||||
| Ast.MOD_ITEM_obj ob ->
|
||||
let taux = { Ast.fn_effect = Ast.EFF_pure;
|
||||
Ast.fn_is_iter = false }
|
||||
let taux = { Ast.fn_is_iter = false }
|
||||
in
|
||||
let tobj = Ast.TY_obj (ty_obj_of_obj ob) in
|
||||
let tsig = { Ast.sig_input_slots = arg_slots ob.Ast.obj_state;
|
||||
|
@ -1705,8 +1688,7 @@ let ty_of_mod_item (item:Ast.mod_item) : Ast.ty =
|
|||
if Array.length hdr = 0
|
||||
then Ast.TY_tag ttag
|
||||
else
|
||||
let taux = { Ast.fn_effect = Ast.EFF_pure;
|
||||
Ast.fn_is_iter = false }
|
||||
let taux = { Ast.fn_is_iter = false }
|
||||
in
|
||||
let inputs = Array.map (fun (s, _) -> s.node) hdr in
|
||||
let tsig = { Ast.sig_input_slots = inputs;
|
||||
|
@ -2642,8 +2624,7 @@ let mk_ty_fn_or_iter
|
|||
(is_iter:bool)
|
||||
: Ast.ty =
|
||||
(* In some cases we don't care what aux or constrs are. *)
|
||||
let taux = { Ast.fn_effect = Ast.EFF_pure;
|
||||
Ast.fn_is_iter = is_iter; }
|
||||
let taux = { Ast.fn_is_iter = is_iter; }
|
||||
in
|
||||
let tsig = { Ast.sig_input_slots = arg_slots;
|
||||
Ast.sig_input_constrs = [| |];
|
||||
|
@ -2816,6 +2797,6 @@ let glue_str (cx:ctxt) (g:glue) : string =
|
|||
* fill-column: 78;
|
||||
* indent-tabs-mode: nil
|
||||
* buffer-file-coding-system: utf-8-unix
|
||||
* compile-command: "make -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
* compile-command: "make -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
* End:
|
||||
*)
|
||||
|
|
|
@ -122,12 +122,7 @@ let determine_constr_key
|
|||
then
|
||||
begin
|
||||
match Hashtbl.find cx.ctxt_all_item_types cid with
|
||||
Ast.TY_fn (_, taux) ->
|
||||
begin
|
||||
if taux.Ast.fn_effect = Ast.EFF_pure
|
||||
then cid
|
||||
else err (Some cid) "impure function used in constraint"
|
||||
end
|
||||
Ast.TY_fn _ -> cid
|
||||
| _ -> bug () "bad type of predicate"
|
||||
end
|
||||
else
|
||||
|
|
|
@ -44,7 +44,7 @@ fn default_environment(session.session sess,
|
|||
);
|
||||
}
|
||||
|
||||
impure fn parse_input(session.session sess,
|
||||
fn parse_input(session.session sess,
|
||||
parser.parser p,
|
||||
str input) -> @front.ast.crate {
|
||||
if (_str.ends_with(input, ".rc")) {
|
||||
|
@ -56,7 +56,7 @@ impure fn parse_input(session.session sess,
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn compile_input(session.session sess,
|
||||
fn compile_input(session.session sess,
|
||||
eval.env env,
|
||||
str input, str output,
|
||||
bool shared,
|
||||
|
@ -79,7 +79,7 @@ impure fn compile_input(session.session sess,
|
|||
ot);
|
||||
}
|
||||
|
||||
impure fn pretty_print_input(session.session sess,
|
||||
fn pretty_print_input(session.session sess,
|
||||
eval.env env,
|
||||
str input) {
|
||||
auto def = tup(0, 0);
|
||||
|
@ -116,7 +116,7 @@ fn get_os() -> session.os {
|
|||
if (_str.eq(s, "linux")) { ret session.os_linux; }
|
||||
}
|
||||
|
||||
impure fn main(vec[str] args) {
|
||||
fn main(vec[str] args) {
|
||||
|
||||
// FIXME: don't hard-wire this.
|
||||
auto target_cfg = rec(os = get_os(),
|
||||
|
|
|
@ -83,7 +83,7 @@ tag crate_directive_ {
|
|||
cdir_view_item(@view_item);
|
||||
cdir_meta(vec[@meta_item]);
|
||||
cdir_syntax(path);
|
||||
cdir_auth(path, effect);
|
||||
cdir_auth(path, _auth);
|
||||
}
|
||||
type crate_directive = spanned[crate_directive_];
|
||||
|
||||
|
@ -130,10 +130,8 @@ tag layer {
|
|||
layer_gc;
|
||||
}
|
||||
|
||||
tag effect {
|
||||
eff_pure;
|
||||
eff_impure;
|
||||
eff_unsafe;
|
||||
tag _auth {
|
||||
auth_unsafe;
|
||||
}
|
||||
|
||||
tag proto {
|
||||
|
@ -314,7 +312,7 @@ tag lit_ {
|
|||
type mt = rec(@ty ty, mutability mut);
|
||||
type ty_field = rec(ident ident, mt mt);
|
||||
type ty_arg = rec(mode mode, @ty ty);
|
||||
type ty_method = rec(effect effect, proto proto, ident ident,
|
||||
type ty_method = rec(proto proto, ident ident,
|
||||
vec[ty_arg] inputs, @ty output);
|
||||
type ty = spanned[ty_];
|
||||
tag ty_ {
|
||||
|
@ -332,7 +330,7 @@ tag ty_ {
|
|||
ty_chan(@ty);
|
||||
ty_tup(vec[mt]);
|
||||
ty_rec(vec[ty_field]);
|
||||
ty_fn(effect, proto, vec[ty_arg], @ty);
|
||||
ty_fn(proto, vec[ty_arg], @ty);
|
||||
ty_obj(vec[ty_method]);
|
||||
ty_path(path, option.t[def]);
|
||||
ty_type;
|
||||
|
@ -348,8 +346,7 @@ type constr_ = rec(path path, vec[@constr_arg] args);
|
|||
type constr = spanned[constr_];
|
||||
|
||||
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
|
||||
type fn_decl = rec(effect effect,
|
||||
vec[arg] inputs,
|
||||
type fn_decl = rec(vec[arg] inputs,
|
||||
@ty output);
|
||||
type _fn = rec(fn_decl decl,
|
||||
proto proto,
|
||||
|
|
|
@ -55,7 +55,7 @@ fn peek(@pstate st) -> u8 {
|
|||
if (st.pos < st.len) {ret st.rep.(st.pos) as u8;}
|
||||
else {ret ' ' as u8;}
|
||||
}
|
||||
impure fn next(@pstate st) -> u8 { // ?? somehow not recognized as impure
|
||||
fn next(@pstate st) -> u8 { // ?? somehow not recognized as impure
|
||||
if (st.pos >= st.len) {fail;}
|
||||
auto ch = st.rep.(st.pos);
|
||||
st.pos = st.pos + 1u;
|
||||
|
@ -74,12 +74,12 @@ fn parse_ty_str(str rep, str_def sd) -> @ty.t {
|
|||
ret result;
|
||||
}
|
||||
|
||||
impure fn parse_ty(@pstate st, str_def sd) -> @ty.t {
|
||||
fn parse_ty(@pstate st, str_def sd) -> @ty.t {
|
||||
ret @rec(struct=parse_sty(st, sd),
|
||||
cname=option.none[str]);
|
||||
}
|
||||
|
||||
impure fn parse_mt(@pstate st, str_def sd) -> ty.mt {
|
||||
fn parse_mt(@pstate st, str_def sd) -> ty.mt {
|
||||
auto mut;
|
||||
alt (peek(st) as char) {
|
||||
case ('m') {next(st); mut = ast.mut;}
|
||||
|
@ -89,7 +89,7 @@ impure fn parse_mt(@pstate st, str_def sd) -> ty.mt {
|
|||
ret rec(ty=parse_ty(st, sd), mut=mut);
|
||||
}
|
||||
|
||||
impure fn parse_def(@pstate st, str_def sd) -> ast.def_id {
|
||||
fn parse_def(@pstate st, str_def sd) -> ast.def_id {
|
||||
auto def = "";
|
||||
while (peek(st) as char != '|') {
|
||||
def += _str.unsafe_from_byte(next(st));
|
||||
|
@ -98,7 +98,7 @@ impure fn parse_def(@pstate st, str_def sd) -> ast.def_id {
|
|||
ret sd(def);
|
||||
}
|
||||
|
||||
impure fn parse_sty(@pstate st, str_def sd) -> ty.sty {
|
||||
fn parse_sty(@pstate st, str_def sd) -> ty.sty {
|
||||
alt (next(st) as char) {
|
||||
case ('n') {ret ty.ty_nil;}
|
||||
case ('b') {ret ty.ty_bool;}
|
||||
|
@ -205,7 +205,7 @@ impure fn parse_sty(@pstate st, str_def sd) -> ty.sty {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_int(@pstate st) -> int {
|
||||
fn parse_int(@pstate st) -> int {
|
||||
auto n = 0;
|
||||
while (true) {
|
||||
auto cur = peek(st) as char;
|
||||
|
@ -217,7 +217,7 @@ impure fn parse_int(@pstate st) -> int {
|
|||
ret n;
|
||||
}
|
||||
|
||||
impure fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) {
|
||||
fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) {
|
||||
check(next(st) as char == '[');
|
||||
let vec[ty.arg] inputs = vec();
|
||||
while (peek(st) as char != ']') {
|
||||
|
@ -565,7 +565,7 @@ fn get_tag_variants(session.session sess, ast.def_id def)
|
|||
ret infos;
|
||||
}
|
||||
|
||||
impure fn list_file_metadata(str path, io.writer out) {
|
||||
fn list_file_metadata(str path, io.writer out) {
|
||||
alt (get_metadata_section(path)) {
|
||||
case (option.some[vec[u8]](?bytes)) {
|
||||
list_crate_metadata(bytes, out);
|
||||
|
@ -584,7 +584,7 @@ fn read_path(&ebml.doc d) -> tup(str, uint) {
|
|||
ret tup(path, pos);
|
||||
}
|
||||
|
||||
impure fn list_crate_metadata(vec[u8] bytes, io.writer out) {
|
||||
fn list_crate_metadata(vec[u8] bytes, io.writer out) {
|
||||
auto md = ebml.new_doc(bytes);
|
||||
auto paths = ebml.get_doc(md, metadata.tag_paths);
|
||||
auto items = ebml.get_doc(md, metadata.tag_items);
|
||||
|
|
|
@ -224,7 +224,7 @@ fn val_eq(session.session sess, span sp, val av, val bv) -> bool {
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn eval_crate_directives(ctx cx,
|
||||
fn eval_crate_directives(ctx cx,
|
||||
env e,
|
||||
vec[@ast.crate_directive] cdirs,
|
||||
str prefix,
|
||||
|
@ -240,7 +240,7 @@ impure fn eval_crate_directives(ctx cx,
|
|||
}
|
||||
|
||||
|
||||
impure fn eval_crate_directives_to_mod(ctx cx, env e,
|
||||
fn eval_crate_directives_to_mod(ctx cx, env e,
|
||||
vec[@ast.crate_directive] cdirs,
|
||||
str prefix) -> ast._mod {
|
||||
let vec[@ast.view_item] view_items = vec();
|
||||
|
@ -254,7 +254,7 @@ impure fn eval_crate_directives_to_mod(ctx cx, env e,
|
|||
}
|
||||
|
||||
|
||||
impure fn eval_crate_directive_block(ctx cx,
|
||||
fn eval_crate_directive_block(ctx cx,
|
||||
env e,
|
||||
&ast.block blk,
|
||||
str prefix,
|
||||
|
@ -277,7 +277,7 @@ impure fn eval_crate_directive_block(ctx cx,
|
|||
}
|
||||
}
|
||||
|
||||
impure fn eval_crate_directive_expr(ctx cx,
|
||||
fn eval_crate_directive_expr(ctx cx,
|
||||
env e,
|
||||
@ast.expr x,
|
||||
str prefix,
|
||||
|
@ -349,7 +349,7 @@ impure fn eval_crate_directive_expr(ctx cx,
|
|||
}
|
||||
}
|
||||
|
||||
impure fn eval_crate_directive(ctx cx,
|
||||
fn eval_crate_directive(ctx cx,
|
||||
env e,
|
||||
@ast.crate_directive cdir,
|
||||
str prefix,
|
||||
|
|
|
@ -14,8 +14,8 @@ state type reader = state obj {
|
|||
fn is_eof() -> bool;
|
||||
fn curr() -> char;
|
||||
fn next() -> char;
|
||||
impure fn init();
|
||||
impure fn bump();
|
||||
fn init();
|
||||
fn bump();
|
||||
fn mark();
|
||||
fn get_mark_chpos() -> uint;
|
||||
fn get_chpos() -> uint;
|
||||
|
@ -24,7 +24,7 @@ state type reader = state obj {
|
|||
fn get_filemap() -> codemap.filemap;
|
||||
};
|
||||
|
||||
impure fn new_reader(io.reader rdr, str filename, codemap.filemap filemap)
|
||||
fn new_reader(io.reader rdr, str filename, codemap.filemap filemap)
|
||||
-> reader {
|
||||
state obj reader(str file,
|
||||
uint len,
|
||||
|
@ -53,7 +53,7 @@ impure fn new_reader(io.reader rdr, str filename, codemap.filemap filemap)
|
|||
else {ret -1 as char;}
|
||||
}
|
||||
|
||||
impure fn init() {
|
||||
fn init() {
|
||||
if (pos < len) {
|
||||
auto next = _str.char_range_at(file, pos);
|
||||
pos = next._1;
|
||||
|
@ -61,7 +61,7 @@ impure fn new_reader(io.reader rdr, str filename, codemap.filemap filemap)
|
|||
}
|
||||
}
|
||||
|
||||
impure fn bump() {
|
||||
fn bump() {
|
||||
if (pos < len) {
|
||||
chpos += 1u;
|
||||
if (ch == '\n') {
|
||||
|
@ -135,7 +135,6 @@ fn keyword_table() -> std.map.hashmap[str, token.token] {
|
|||
keywords.insert("state", token.STATE);
|
||||
keywords.insert("gc", token.GC);
|
||||
|
||||
keywords.insert("impure", token.IMPURE);
|
||||
keywords.insert("unsafe", token.UNSAFE);
|
||||
|
||||
keywords.insert("native", token.NATIVE);
|
||||
|
@ -274,14 +273,14 @@ fn is_whitespace(char c) -> bool {
|
|||
ret c == ' ' || c == '\t' || c == '\r' || c == '\n';
|
||||
}
|
||||
|
||||
impure fn consume_any_whitespace(reader rdr) {
|
||||
fn consume_any_whitespace(reader rdr) {
|
||||
while (is_whitespace(rdr.curr())) {
|
||||
rdr.bump();
|
||||
}
|
||||
be consume_any_line_comment(rdr);
|
||||
}
|
||||
|
||||
impure fn consume_any_line_comment(reader rdr) {
|
||||
fn consume_any_line_comment(reader rdr) {
|
||||
if (rdr.curr() == '/') {
|
||||
alt (rdr.next()) {
|
||||
case ('/') {
|
||||
|
@ -304,7 +303,7 @@ impure fn consume_any_line_comment(reader rdr) {
|
|||
}
|
||||
|
||||
|
||||
impure fn consume_block_comment(reader rdr) {
|
||||
fn consume_block_comment(reader rdr) {
|
||||
let int level = 1;
|
||||
while (level > 0) {
|
||||
if (rdr.curr() == '/' && rdr.next() == '*') {
|
||||
|
@ -342,7 +341,7 @@ fn digits_to_string(str s) -> int {
|
|||
ret accum_int;
|
||||
}
|
||||
|
||||
impure fn scan_exponent(reader rdr) -> option.t[str] {
|
||||
fn scan_exponent(reader rdr) -> option.t[str] {
|
||||
auto c = rdr.curr();
|
||||
auto res = "";
|
||||
|
||||
|
@ -368,7 +367,7 @@ impure fn scan_exponent(reader rdr) -> option.t[str] {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn scan_dec_digits(reader rdr) -> str {
|
||||
fn scan_dec_digits(reader rdr) -> str {
|
||||
|
||||
auto c = rdr.curr();
|
||||
let str res = "";
|
||||
|
@ -384,7 +383,7 @@ impure fn scan_dec_digits(reader rdr) -> str {
|
|||
ret res;
|
||||
}
|
||||
|
||||
impure fn scan_number(mutable char c, reader rdr) -> token.token {
|
||||
fn scan_number(mutable char c, reader rdr) -> token.token {
|
||||
auto accum_int = 0;
|
||||
let str dec_str = "";
|
||||
let bool is_dec_integer = false;
|
||||
|
@ -527,7 +526,7 @@ impure fn scan_number(mutable char c, reader rdr) -> token.token {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn scan_numeric_escape(reader rdr) -> char {
|
||||
fn scan_numeric_escape(reader rdr) -> char {
|
||||
|
||||
auto n_hex_digits = 0;
|
||||
|
||||
|
@ -563,7 +562,7 @@ impure fn scan_numeric_escape(reader rdr) -> char {
|
|||
}
|
||||
|
||||
|
||||
impure fn next_token(reader rdr) -> token.token {
|
||||
fn next_token(reader rdr) -> token.token {
|
||||
auto accum_str = "";
|
||||
|
||||
consume_any_whitespace(rdr);
|
||||
|
@ -602,7 +601,7 @@ impure fn next_token(reader rdr) -> token.token {
|
|||
ret scan_number(c, rdr);
|
||||
}
|
||||
|
||||
impure fn binop(reader rdr, token.binop op) -> token.token {
|
||||
fn binop(reader rdr, token.binop op) -> token.token {
|
||||
rdr.bump();
|
||||
if (rdr.curr() == '=') {
|
||||
rdr.bump();
|
||||
|
@ -856,7 +855,7 @@ tag cmnt_ {
|
|||
|
||||
type cmnt = rec(cmnt_ val, uint pos, bool space_after);
|
||||
|
||||
impure fn consume_whitespace(reader rdr) -> uint {
|
||||
fn consume_whitespace(reader rdr) -> uint {
|
||||
auto lines = 0u;
|
||||
while (is_whitespace(rdr.curr())) {
|
||||
if (rdr.curr() == '\n') {lines += 1u;}
|
||||
|
@ -865,7 +864,7 @@ impure fn consume_whitespace(reader rdr) -> uint {
|
|||
ret lines;
|
||||
}
|
||||
|
||||
impure fn read_line_comment(reader rdr) -> cmnt {
|
||||
fn read_line_comment(reader rdr) -> cmnt {
|
||||
auto p = rdr.get_chpos();
|
||||
rdr.bump(); rdr.bump();
|
||||
while (rdr.curr() == ' ') {rdr.bump();}
|
||||
|
@ -879,7 +878,7 @@ impure fn read_line_comment(reader rdr) -> cmnt {
|
|||
space_after=consume_whitespace(rdr) > 1u);
|
||||
}
|
||||
|
||||
impure fn read_block_comment(reader rdr) -> cmnt {
|
||||
fn read_block_comment(reader rdr) -> cmnt {
|
||||
auto p = rdr.get_chpos();
|
||||
rdr.bump(); rdr.bump();
|
||||
while (rdr.curr() == ' ') {rdr.bump();}
|
||||
|
@ -912,7 +911,7 @@ impure fn read_block_comment(reader rdr) -> cmnt {
|
|||
space_after=consume_whitespace(rdr) > 1u);
|
||||
}
|
||||
|
||||
impure fn gather_comments(str path) -> vec[cmnt] {
|
||||
fn gather_comments(str path) -> vec[cmnt] {
|
||||
auto srdr = io.file_reader(path);
|
||||
auto rdr = new_reader(srdr, path, codemap.new_filemap(path, 0u));
|
||||
let vec[cmnt] comments = vec();
|
||||
|
|
|
@ -26,9 +26,9 @@ tag file_type {
|
|||
state type parser =
|
||||
state obj {
|
||||
fn peek() -> token.token;
|
||||
impure fn bump();
|
||||
impure fn err(str s);
|
||||
impure fn restrict(restriction r);
|
||||
fn bump();
|
||||
fn err(str s);
|
||||
fn restrict(restriction r);
|
||||
fn get_restriction() -> restriction;
|
||||
fn get_file_type() -> file_type;
|
||||
fn get_env() -> eval.env;
|
||||
|
@ -43,7 +43,7 @@ state type parser =
|
|||
fn get_chpos() -> uint;
|
||||
};
|
||||
|
||||
impure fn new_parser(session.session sess,
|
||||
fn new_parser(session.session sess,
|
||||
eval.env env,
|
||||
ast.def_id initial_def,
|
||||
str path, uint pos) -> parser {
|
||||
|
@ -63,7 +63,7 @@ impure fn new_parser(session.session sess,
|
|||
ret tok;
|
||||
}
|
||||
|
||||
impure fn bump() {
|
||||
fn bump() {
|
||||
// log rdr.get_filename()
|
||||
// + ":" + common.istr(lo.line as int);
|
||||
tok = lexer.next_token(rdr);
|
||||
|
@ -71,11 +71,11 @@ impure fn new_parser(session.session sess,
|
|||
hi = rdr.get_chpos();
|
||||
}
|
||||
|
||||
impure fn err(str m) {
|
||||
fn err(str m) {
|
||||
sess.span_err(rec(lo=lo, hi=hi), m);
|
||||
}
|
||||
|
||||
impure fn restrict(restriction r) {
|
||||
fn restrict(restriction r) {
|
||||
res = r;
|
||||
}
|
||||
|
||||
|
@ -134,13 +134,13 @@ impure fn new_parser(session.session sess,
|
|||
rdr, prec_table());
|
||||
}
|
||||
|
||||
impure fn unexpected(parser p, token.token t) {
|
||||
fn unexpected(parser p, token.token t) {
|
||||
let str s = "unexpected token: ";
|
||||
s += token.to_str(t);
|
||||
p.err(s);
|
||||
}
|
||||
|
||||
impure fn expect(parser p, token.token t) {
|
||||
fn expect(parser p, token.token t) {
|
||||
if (p.peek() == t) {
|
||||
p.bump();
|
||||
} else {
|
||||
|
@ -156,7 +156,7 @@ fn spanned[T](uint lo, uint hi, &T node) -> ast.spanned[T] {
|
|||
ret rec(node=node, span=rec(lo=lo, hi=hi));
|
||||
}
|
||||
|
||||
impure fn parse_ident(parser p) -> ast.ident {
|
||||
fn parse_ident(parser p) -> ast.ident {
|
||||
alt (p.peek()) {
|
||||
case (token.IDENT(?i)) { p.bump(); ret i; }
|
||||
case (_) {
|
||||
|
@ -172,7 +172,7 @@ impure fn parse_ident(parser p) -> ast.ident {
|
|||
* lexical sytnax-extension or something similar. For now we just imitate
|
||||
* rustboot.
|
||||
*/
|
||||
impure fn parse_str_lit_or_env_ident(parser p) -> ast.ident {
|
||||
fn parse_str_lit_or_env_ident(parser p) -> ast.ident {
|
||||
alt (p.peek()) {
|
||||
case (token.LIT_STR(?s)) { p.bump(); ret s; }
|
||||
case (token.IDENT(?i)) {
|
||||
|
@ -192,9 +192,9 @@ impure fn parse_str_lit_or_env_ident(parser p) -> ast.ident {
|
|||
}
|
||||
|
||||
|
||||
impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p, uint lo)
|
||||
fn parse_ty_fn(ast.proto proto, parser p, uint lo)
|
||||
-> ast.ty_ {
|
||||
impure fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
|
||||
fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
|
||||
auto mode;
|
||||
if (p.peek() == token.BINOP(token.AND)) {
|
||||
p.bump();
|
||||
|
@ -236,10 +236,10 @@ impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p, uint lo)
|
|||
output = @spanned(lo, inputs.span.hi, ast.ty_nil);
|
||||
}
|
||||
|
||||
ret ast.ty_fn(eff, proto, inputs.node, output);
|
||||
ret ast.ty_fn(proto, inputs.node, output);
|
||||
}
|
||||
|
||||
impure fn parse_proto(parser p) -> ast.proto {
|
||||
fn parse_proto(parser p) -> ast.proto {
|
||||
alt (p.peek()) {
|
||||
case (token.ITER) { p.bump(); ret ast.proto_iter; }
|
||||
case (token.FN) { p.bump(); ret ast.proto_fn; }
|
||||
|
@ -248,19 +248,18 @@ impure fn parse_proto(parser p) -> ast.proto {
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn parse_ty_obj(parser p, &mutable uint hi) -> ast.ty_ {
|
||||
fn parse_ty_obj(parser p, &mutable uint hi) -> ast.ty_ {
|
||||
expect(p, token.OBJ);
|
||||
impure fn parse_method_sig(parser p) -> ast.ty_method {
|
||||
fn parse_method_sig(parser p) -> ast.ty_method {
|
||||
auto flo = p.get_lo_pos();
|
||||
|
||||
let ast.effect eff = parse_effect(p);
|
||||
let ast.proto proto = parse_proto(p);
|
||||
auto ident = parse_ident(p);
|
||||
auto f = parse_ty_fn(eff, proto, p, flo);
|
||||
auto f = parse_ty_fn(proto, p, flo);
|
||||
expect(p, token.SEMI);
|
||||
alt (f) {
|
||||
case (ast.ty_fn(?eff, ?proto, ?inputs, ?output)) {
|
||||
ret rec(effect=eff, proto=proto, ident=ident,
|
||||
case (ast.ty_fn(?proto, ?inputs, ?output)) {
|
||||
ret rec(proto=proto, ident=ident,
|
||||
inputs=inputs, output=output);
|
||||
}
|
||||
}
|
||||
|
@ -276,19 +275,19 @@ impure fn parse_ty_obj(parser p, &mutable uint hi) -> ast.ty_ {
|
|||
ret ast.ty_obj(meths.node);
|
||||
}
|
||||
|
||||
impure fn parse_mt(parser p) -> ast.mt {
|
||||
fn parse_mt(parser p) -> ast.mt {
|
||||
auto mut = parse_mutability(p);
|
||||
auto t = parse_ty(p);
|
||||
ret rec(ty=t, mut=mut);
|
||||
}
|
||||
|
||||
impure fn parse_ty_field(parser p) -> ast.ty_field {
|
||||
fn parse_ty_field(parser p) -> ast.ty_field {
|
||||
auto mt = parse_mt(p);
|
||||
auto id = parse_ident(p);
|
||||
ret rec(ident=id, mt=mt);
|
||||
}
|
||||
|
||||
impure fn parse_constr_arg(parser p) -> @ast.constr_arg {
|
||||
fn parse_constr_arg(parser p) -> @ast.constr_arg {
|
||||
auto sp = p.get_span();
|
||||
auto carg = ast.carg_base;
|
||||
if (p.peek() == token.BINOP(token.STAR)) {
|
||||
|
@ -299,7 +298,7 @@ impure fn parse_constr_arg(parser p) -> @ast.constr_arg {
|
|||
ret @rec(node=carg, span=sp);
|
||||
}
|
||||
|
||||
impure fn parse_ty_constr(parser p) -> @ast.constr {
|
||||
fn parse_ty_constr(parser p) -> @ast.constr {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto path = parse_path(p, GREEDY);
|
||||
auto pf = parse_constr_arg;
|
||||
|
@ -309,7 +308,7 @@ impure fn parse_ty_constr(parser p) -> @ast.constr {
|
|||
ret @spanned(lo, args.span.hi, rec(path=path, args=args.node));
|
||||
}
|
||||
|
||||
impure fn parse_constrs(parser p) -> common.spanned[vec[@ast.constr]] {
|
||||
fn parse_constrs(parser p) -> common.spanned[vec[@ast.constr]] {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto hi = p.get_hi_pos();
|
||||
let vec[@ast.constr] constrs = vec();
|
||||
|
@ -334,7 +333,7 @@ impure fn parse_constrs(parser p) -> common.spanned[vec[@ast.constr]] {
|
|||
ret spanned(lo, hi, constrs);
|
||||
}
|
||||
|
||||
impure fn parse_ty_constrs(@ast.ty t, parser p) -> @ast.ty {
|
||||
fn parse_ty_constrs(@ast.ty t, parser p) -> @ast.ty {
|
||||
if (p.peek() == token.COLON) {
|
||||
auto constrs = parse_constrs(p);
|
||||
ret @spanned(t.span.lo, constrs.span.hi,
|
||||
|
@ -343,13 +342,11 @@ impure fn parse_ty_constrs(@ast.ty t, parser p) -> @ast.ty {
|
|||
ret t;
|
||||
}
|
||||
|
||||
impure fn parse_ty(parser p) -> @ast.ty {
|
||||
fn parse_ty(parser p) -> @ast.ty {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto hi = lo;
|
||||
let ast.ty_ t;
|
||||
|
||||
// FIXME: make sure these are only used when valid
|
||||
let ast.effect eff = parse_effect(p);
|
||||
// FIXME: do something with this
|
||||
let ast.layer lyr = parse_layer(p);
|
||||
|
||||
|
@ -418,9 +415,9 @@ impure fn parse_ty(parser p) -> @ast.ty {
|
|||
case (token.FN) {
|
||||
auto flo = p.get_lo_pos();
|
||||
p.bump();
|
||||
t = parse_ty_fn(eff, ast.proto_fn, p, flo);
|
||||
t = parse_ty_fn(ast.proto_fn, p, flo);
|
||||
alt (t) {
|
||||
case (ast.ty_fn(_, _, _, ?out)) {
|
||||
case (ast.ty_fn(_, _, ?out)) {
|
||||
hi = out.span.hi;
|
||||
}
|
||||
}
|
||||
|
@ -429,9 +426,9 @@ impure fn parse_ty(parser p) -> @ast.ty {
|
|||
case (token.ITER) {
|
||||
auto flo = p.get_lo_pos();
|
||||
p.bump();
|
||||
t = parse_ty_fn(eff, ast.proto_iter, p, flo);
|
||||
t = parse_ty_fn(ast.proto_iter, p, flo);
|
||||
alt (t) {
|
||||
case (ast.ty_fn(_, _, _, ?out)) {
|
||||
case (ast.ty_fn(_, _, ?out)) {
|
||||
hi = out.span.hi;
|
||||
}
|
||||
}
|
||||
|
@ -482,7 +479,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
|
|||
ret parse_ty_constrs(@spanned(lo, hi, t), p);
|
||||
}
|
||||
|
||||
impure fn parse_arg(parser p) -> ast.arg {
|
||||
fn parse_arg(parser p) -> ast.arg {
|
||||
let ast.mode m = ast.val;
|
||||
if (p.peek() == token.BINOP(token.AND)) {
|
||||
m = ast.alias;
|
||||
|
@ -498,9 +495,9 @@ impure fn parse_arg(parser p) -> ast.arg {
|
|||
ret rec(mode=m, ty=t, ident=i, id=p.next_def_id());
|
||||
}
|
||||
|
||||
impure fn parse_seq_to_end[T](token.token ket,
|
||||
fn parse_seq_to_end[T](token.token ket,
|
||||
option.t[token.token] sep,
|
||||
(impure fn(parser) -> T) f,
|
||||
(fn(parser) -> T) f,
|
||||
mutable uint hi,
|
||||
parser p) -> vec[T] {
|
||||
let bool first = true;
|
||||
|
@ -526,10 +523,10 @@ impure fn parse_seq_to_end[T](token.token ket,
|
|||
ret v;
|
||||
}
|
||||
|
||||
impure fn parse_seq[T](token.token bra,
|
||||
fn parse_seq[T](token.token bra,
|
||||
token.token ket,
|
||||
option.t[token.token] sep,
|
||||
(impure fn(parser) -> T) f,
|
||||
(fn(parser) -> T) f,
|
||||
parser p) -> util.common.spanned[vec[T]] {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto hi = p.get_hi_pos();
|
||||
|
@ -538,7 +535,7 @@ impure fn parse_seq[T](token.token bra,
|
|||
ret spanned(lo, hi, result);
|
||||
}
|
||||
|
||||
impure fn parse_lit(parser p) -> ast.lit {
|
||||
fn parse_lit(parser p) -> ast.lit {
|
||||
auto sp = p.get_span();
|
||||
let ast.lit_ lit = ast.lit_nil;
|
||||
alt (p.peek()) {
|
||||
|
@ -594,7 +591,7 @@ tag greed {
|
|||
MINIMAL;
|
||||
}
|
||||
|
||||
impure fn parse_ty_args(parser p, uint hi) ->
|
||||
fn parse_ty_args(parser p, uint hi) ->
|
||||
util.common.spanned[vec[@ast.ty]] {
|
||||
|
||||
if (p.peek() == token.LBRACKET) {
|
||||
|
@ -609,7 +606,7 @@ impure fn parse_ty_args(parser p, uint hi) ->
|
|||
ret spanned(hi, hi, v);
|
||||
}
|
||||
|
||||
impure fn parse_path(parser p, greed g) -> ast.path {
|
||||
fn parse_path(parser p, greed g) -> ast.path {
|
||||
|
||||
auto lo = p.get_lo_pos();
|
||||
auto hi = lo;
|
||||
|
@ -643,7 +640,7 @@ impure fn parse_path(parser p, greed g) -> ast.path {
|
|||
ret spanned(lo, tys.span.hi, rec(idents=ids, types=tys.node));
|
||||
}
|
||||
|
||||
impure fn parse_mutability(parser p) -> ast.mutability {
|
||||
fn parse_mutability(parser p) -> ast.mutability {
|
||||
if (p.peek() == token.MUTABLE) {
|
||||
p.bump();
|
||||
if (p.peek() == token.QUES) {
|
||||
|
@ -655,7 +652,7 @@ impure fn parse_mutability(parser p) -> ast.mutability {
|
|||
ret ast.imm;
|
||||
}
|
||||
|
||||
impure fn parse_field(parser p) -> ast.field {
|
||||
fn parse_field(parser p) -> ast.field {
|
||||
auto m = parse_mutability(p);
|
||||
auto i = parse_ident(p);
|
||||
expect(p, token.EQ);
|
||||
|
@ -663,7 +660,7 @@ impure fn parse_field(parser p) -> ast.field {
|
|||
ret rec(mut=m, ident=i, expr=e);
|
||||
}
|
||||
|
||||
impure fn parse_bottom_expr(parser p) -> @ast.expr {
|
||||
fn parse_bottom_expr(parser p) -> @ast.expr {
|
||||
|
||||
auto lo = p.get_lo_pos();
|
||||
auto hi = p.get_hi_pos();
|
||||
|
@ -701,7 +698,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
|
|||
|
||||
case (token.TUP) {
|
||||
p.bump();
|
||||
impure fn parse_elt(parser p) -> ast.elt {
|
||||
fn parse_elt(parser p) -> ast.elt {
|
||||
auto m = parse_mutability(p);
|
||||
auto e = parse_expr(p);
|
||||
ret rec(mut=m, expr=e);
|
||||
|
@ -767,7 +764,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
|
|||
case (token.BIND) {
|
||||
p.bump();
|
||||
auto e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
|
||||
impure fn parse_expr_opt(parser p) -> option.t[@ast.expr] {
|
||||
fn parse_expr_opt(parser p) -> option.t[@ast.expr] {
|
||||
alt (p.peek()) {
|
||||
case (token.UNDERSCORE) {
|
||||
p.bump();
|
||||
|
@ -937,7 +934,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
|
|||
* rust crates. At the moment we have neither.
|
||||
*/
|
||||
|
||||
impure fn expand_syntax_ext(parser p, ast.span sp,
|
||||
fn expand_syntax_ext(parser p, ast.span sp,
|
||||
&ast.path path, vec[@ast.expr] args,
|
||||
option.t[@ast.expr] body) -> ast.expr_ {
|
||||
|
||||
|
@ -956,7 +953,7 @@ impure fn expand_syntax_ext(parser p, ast.span sp,
|
|||
}
|
||||
}
|
||||
|
||||
impure fn extend_expr_by_ident(parser p, uint lo, uint hi,
|
||||
fn extend_expr_by_ident(parser p, uint lo, uint hi,
|
||||
@ast.expr e, ast.ident i) -> @ast.expr {
|
||||
auto e_ = e.node;
|
||||
alt (e.node) {
|
||||
|
@ -981,14 +978,14 @@ impure fn extend_expr_by_ident(parser p, uint lo, uint hi,
|
|||
ret @spanned(lo, hi, e_);
|
||||
}
|
||||
|
||||
impure fn parse_self_method(parser p) -> @ast.expr {
|
||||
fn parse_self_method(parser p) -> @ast.expr {
|
||||
auto sp = p.get_span();
|
||||
let ast.ident f_name = parse_ident(p);
|
||||
auto hi = p.get_span();
|
||||
ret @rec(node=ast.expr_self_method(f_name, ast.ann_none), span=sp);
|
||||
}
|
||||
|
||||
impure fn parse_dot_or_call_expr(parser p) -> @ast.expr {
|
||||
fn parse_dot_or_call_expr(parser p) -> @ast.expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto e = parse_bottom_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
|
@ -1043,7 +1040,7 @@ impure fn parse_dot_or_call_expr(parser p) -> @ast.expr {
|
|||
ret e;
|
||||
}
|
||||
|
||||
impure fn parse_prefix_expr(parser p) -> @ast.expr {
|
||||
fn parse_prefix_expr(parser p) -> @ast.expr {
|
||||
|
||||
if (p.peek() == token.MUTABLE) {
|
||||
p.bump();
|
||||
|
@ -1140,11 +1137,11 @@ fn prec_table() -> vec[op_spec] {
|
|||
rec(tok=token.OROR, op=ast.or, prec=1));
|
||||
}
|
||||
|
||||
impure fn parse_binops(parser p) -> @ast.expr {
|
||||
fn parse_binops(parser p) -> @ast.expr {
|
||||
ret parse_more_binops(p, parse_prefix_expr(p), 0);
|
||||
}
|
||||
|
||||
impure fn parse_more_binops(parser p, @ast.expr lhs, int min_prec)
|
||||
fn parse_more_binops(parser p, @ast.expr lhs, int min_prec)
|
||||
-> @ast.expr {
|
||||
// Magic nonsense to work around rustboot bug
|
||||
fn op_eq(token.token a, token.token b) -> bool {
|
||||
|
@ -1176,7 +1173,7 @@ impure fn parse_more_binops(parser p, @ast.expr lhs, int min_prec)
|
|||
ret lhs;
|
||||
}
|
||||
|
||||
impure fn parse_assign_expr(parser p) -> @ast.expr {
|
||||
fn parse_assign_expr(parser p) -> @ast.expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto lhs = parse_binops(p);
|
||||
alt (p.peek()) {
|
||||
|
@ -1223,7 +1220,7 @@ impure fn parse_assign_expr(parser p) -> @ast.expr {
|
|||
ret lhs;
|
||||
}
|
||||
|
||||
impure fn parse_if_expr(parser p) -> @ast.expr {
|
||||
fn parse_if_expr(parser p) -> @ast.expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
|
||||
expect(p, token.IF);
|
||||
|
@ -1245,7 +1242,7 @@ impure fn parse_if_expr(parser p) -> @ast.expr {
|
|||
ret @spanned(lo, hi, ast.expr_if(cond, thn, els, ast.ann_none));
|
||||
}
|
||||
|
||||
impure fn parse_else_expr(parser p) -> @ast.expr {
|
||||
fn parse_else_expr(parser p) -> @ast.expr {
|
||||
expect(p, token.ELSE);
|
||||
alt (p.peek()) {
|
||||
case (token.IF) {
|
||||
|
@ -1259,7 +1256,7 @@ impure fn parse_else_expr(parser p) -> @ast.expr {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_head_local(parser p) -> @ast.decl {
|
||||
fn parse_head_local(parser p) -> @ast.decl {
|
||||
auto lo = p.get_lo_pos();
|
||||
let @ast.local local;
|
||||
if (p.peek() == token.AUTO) {
|
||||
|
@ -1272,7 +1269,7 @@ impure fn parse_head_local(parser p) -> @ast.decl {
|
|||
|
||||
|
||||
|
||||
impure fn parse_for_expr(parser p) -> @ast.expr {
|
||||
fn parse_for_expr(parser p) -> @ast.expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto is_each = false;
|
||||
|
||||
|
@ -1301,7 +1298,7 @@ impure fn parse_for_expr(parser p) -> @ast.expr {
|
|||
}
|
||||
|
||||
|
||||
impure fn parse_while_expr(parser p) -> @ast.expr {
|
||||
fn parse_while_expr(parser p) -> @ast.expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
|
||||
expect(p, token.WHILE);
|
||||
|
@ -1313,7 +1310,7 @@ impure fn parse_while_expr(parser p) -> @ast.expr {
|
|||
ret @spanned(lo, hi, ast.expr_while(cond, body, ast.ann_none));
|
||||
}
|
||||
|
||||
impure fn parse_do_while_expr(parser p) -> @ast.expr {
|
||||
fn parse_do_while_expr(parser p) -> @ast.expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
|
||||
expect(p, token.DO);
|
||||
|
@ -1326,7 +1323,7 @@ impure fn parse_do_while_expr(parser p) -> @ast.expr {
|
|||
ret @spanned(lo, hi, ast.expr_do_while(body, cond, ast.ann_none));
|
||||
}
|
||||
|
||||
impure fn parse_alt_expr(parser p) -> @ast.expr {
|
||||
fn parse_alt_expr(parser p) -> @ast.expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.ALT);
|
||||
expect(p, token.LPAREN);
|
||||
|
@ -1377,7 +1374,7 @@ impure fn parse_alt_expr(parser p) -> @ast.expr {
|
|||
ret @spanned(lo, hi, expr);
|
||||
}
|
||||
|
||||
impure fn parse_spawn_expr(parser p) -> @ast.expr {
|
||||
fn parse_spawn_expr(parser p) -> @ast.expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.SPAWN);
|
||||
|
||||
|
@ -1398,11 +1395,11 @@ impure fn parse_spawn_expr(parser p) -> @ast.expr {
|
|||
ret @spanned(lo, hi, spawn_expr);
|
||||
}
|
||||
|
||||
impure fn parse_expr(parser p) -> @ast.expr {
|
||||
fn parse_expr(parser p) -> @ast.expr {
|
||||
ret parse_expr_res(p, UNRESTRICTED);
|
||||
}
|
||||
|
||||
impure fn parse_expr_res(parser p, restriction r) -> @ast.expr {
|
||||
fn parse_expr_res(parser p, restriction r) -> @ast.expr {
|
||||
auto old = p.get_restriction();
|
||||
p.restrict(r);
|
||||
auto e = parse_expr_inner(p);
|
||||
|
@ -1410,7 +1407,7 @@ impure fn parse_expr_res(parser p, restriction r) -> @ast.expr {
|
|||
ret e;
|
||||
}
|
||||
|
||||
impure fn parse_expr_inner(parser p) -> @ast.expr {
|
||||
fn parse_expr_inner(parser p) -> @ast.expr {
|
||||
alt (p.peek()) {
|
||||
case (token.LBRACE) {
|
||||
auto blk = parse_block(p);
|
||||
|
@ -1442,7 +1439,7 @@ impure fn parse_expr_inner(parser p) -> @ast.expr {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_initializer(parser p) -> option.t[ast.initializer] {
|
||||
fn parse_initializer(parser p) -> option.t[ast.initializer] {
|
||||
alt (p.peek()) {
|
||||
case (token.EQ) {
|
||||
p.bump();
|
||||
|
@ -1460,7 +1457,7 @@ impure fn parse_initializer(parser p) -> option.t[ast.initializer] {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_pat(parser p) -> @ast.pat {
|
||||
fn parse_pat(parser p) -> @ast.pat {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto hi = p.get_hi_pos();
|
||||
auto pat;
|
||||
|
@ -1514,7 +1511,7 @@ impure fn parse_pat(parser p) -> @ast.pat {
|
|||
ret @spanned(lo, hi, pat);
|
||||
}
|
||||
|
||||
impure fn parse_local_full(&option.t[@ast.ty] tyopt,
|
||||
fn parse_local_full(&option.t[@ast.ty] tyopt,
|
||||
parser p) -> @ast.local {
|
||||
auto ident = parse_ident(p);
|
||||
auto init = parse_initializer(p);
|
||||
|
@ -1526,30 +1523,30 @@ impure fn parse_local_full(&option.t[@ast.ty] tyopt,
|
|||
ann = ast.ann_none);
|
||||
}
|
||||
|
||||
impure fn parse_typed_local(parser p) -> @ast.local {
|
||||
fn parse_typed_local(parser p) -> @ast.local {
|
||||
auto ty = parse_ty(p);
|
||||
ret parse_local_full(some(ty), p);
|
||||
}
|
||||
|
||||
impure fn parse_auto_local(parser p) -> @ast.local {
|
||||
fn parse_auto_local(parser p) -> @ast.local {
|
||||
ret parse_local_full(none[@ast.ty], p);
|
||||
}
|
||||
|
||||
impure fn parse_let(parser p) -> @ast.decl {
|
||||
fn parse_let(parser p) -> @ast.decl {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.LET);
|
||||
auto local = parse_typed_local(p);
|
||||
ret @spanned(lo, p.get_hi_pos(), ast.decl_local(local));
|
||||
}
|
||||
|
||||
impure fn parse_auto(parser p) -> @ast.decl {
|
||||
fn parse_auto(parser p) -> @ast.decl {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.AUTO);
|
||||
auto local = parse_auto_local(p);
|
||||
ret @spanned(lo, p.get_hi_pos(), ast.decl_local(local));
|
||||
}
|
||||
|
||||
impure fn parse_stmt(parser p) -> @ast.stmt {
|
||||
fn parse_stmt(parser p) -> @ast.stmt {
|
||||
if (p.get_file_type() == SOURCE_FILE) {
|
||||
ret parse_source_stmt(p);
|
||||
} else {
|
||||
|
@ -1557,13 +1554,13 @@ impure fn parse_stmt(parser p) -> @ast.stmt {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_crate_stmt(parser p) -> @ast.stmt {
|
||||
fn parse_crate_stmt(parser p) -> @ast.stmt {
|
||||
auto cdir = parse_crate_directive(p);
|
||||
ret @spanned(cdir.span.lo, cdir.span.hi,
|
||||
ast.stmt_crate_directive(@cdir));
|
||||
}
|
||||
|
||||
impure fn parse_source_stmt(parser p) -> @ast.stmt {
|
||||
fn parse_source_stmt(parser p) -> @ast.stmt {
|
||||
auto lo = p.get_lo_pos();
|
||||
alt (p.peek()) {
|
||||
|
||||
|
@ -1685,7 +1682,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_block(parser p) -> ast.block {
|
||||
fn parse_block(parser p) -> ast.block {
|
||||
auto lo = p.get_lo_pos();
|
||||
|
||||
let vec[@ast.stmt] stmts = vec();
|
||||
|
@ -1746,11 +1743,11 @@ impure fn parse_block(parser p) -> ast.block {
|
|||
ret spanned[ast.block_](lo, hi, bloc);
|
||||
}
|
||||
|
||||
impure fn parse_ty_param(parser p) -> ast.ty_param {
|
||||
fn parse_ty_param(parser p) -> ast.ty_param {
|
||||
ret parse_ident(p);
|
||||
}
|
||||
|
||||
impure fn parse_ty_params(parser p) -> vec[ast.ty_param] {
|
||||
fn parse_ty_params(parser p) -> vec[ast.ty_param] {
|
||||
let vec[ast.ty_param] ty_params = vec();
|
||||
if (p.peek() == token.LBRACKET) {
|
||||
auto f = parse_ty_param; // FIXME: pass as lval directly
|
||||
|
@ -1760,7 +1757,7 @@ impure fn parse_ty_params(parser p) -> vec[ast.ty_param] {
|
|||
ret ty_params;
|
||||
}
|
||||
|
||||
impure fn parse_fn_decl(parser p, ast.effect eff) -> ast.fn_decl {
|
||||
fn parse_fn_decl(parser p) -> ast.fn_decl {
|
||||
auto pf = parse_arg;
|
||||
let util.common.spanned[vec[ast.arg]] inputs =
|
||||
// FIXME: passing parse_arg as an lval doesn't work at the
|
||||
|
@ -1783,61 +1780,59 @@ impure fn parse_fn_decl(parser p, ast.effect eff) -> ast.fn_decl {
|
|||
} else {
|
||||
output = @spanned(inputs.span.lo, inputs.span.hi, ast.ty_nil);
|
||||
}
|
||||
ret rec(effect=eff, inputs=inputs.node, output=output);
|
||||
ret rec(inputs=inputs.node, output=output);
|
||||
}
|
||||
|
||||
impure fn parse_fn(parser p, ast.effect eff, ast.proto proto) -> ast._fn {
|
||||
auto decl = parse_fn_decl(p, eff);
|
||||
fn parse_fn(parser p, ast.proto proto) -> ast._fn {
|
||||
auto decl = parse_fn_decl(p);
|
||||
auto body = parse_block(p);
|
||||
ret rec(decl = decl,
|
||||
proto = proto,
|
||||
body = body);
|
||||
}
|
||||
|
||||
impure fn parse_fn_header(parser p)
|
||||
fn parse_fn_header(parser p)
|
||||
-> tup(ast.ident, vec[ast.ty_param]) {
|
||||
auto id = parse_ident(p);
|
||||
auto ty_params = parse_ty_params(p);
|
||||
ret tup(id, ty_params);
|
||||
}
|
||||
|
||||
impure fn parse_item_fn_or_iter(parser p, ast.effect eff) -> @ast.item {
|
||||
fn parse_item_fn_or_iter(parser p) -> @ast.item {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto proto = parse_proto(p);
|
||||
auto t = parse_fn_header(p);
|
||||
auto f = parse_fn(p, eff, proto);
|
||||
auto f = parse_fn(p, proto);
|
||||
auto item = ast.item_fn(t._0, f, t._1,
|
||||
p.next_def_id(), ast.ann_none);
|
||||
ret @spanned(lo, f.body.span.hi, item);
|
||||
}
|
||||
|
||||
|
||||
impure fn parse_obj_field(parser p) -> ast.obj_field {
|
||||
fn parse_obj_field(parser p) -> ast.obj_field {
|
||||
auto mut = parse_mutability(p); // TODO: store this, use it in typeck
|
||||
auto ty = parse_ty(p);
|
||||
auto ident = parse_ident(p);
|
||||
ret rec(ty=ty, ident=ident, id=p.next_def_id(), ann=ast.ann_none);
|
||||
}
|
||||
|
||||
impure fn parse_method(parser p) -> @ast.method {
|
||||
fn parse_method(parser p) -> @ast.method {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto eff = parse_effect(p);
|
||||
auto proto = parse_proto(p);
|
||||
auto ident = parse_ident(p);
|
||||
auto f = parse_fn(p, eff, proto);
|
||||
auto f = parse_fn(p, proto);
|
||||
auto meth = rec(ident=ident, meth=f,
|
||||
id=p.next_def_id(), ann=ast.ann_none);
|
||||
ret @spanned(lo, f.body.span.hi, meth);
|
||||
}
|
||||
|
||||
impure fn parse_dtor(parser p) -> @ast.method {
|
||||
fn parse_dtor(parser p) -> @ast.method {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.DROP);
|
||||
let ast.block b = parse_block(p);
|
||||
let vec[ast.arg] inputs = vec();
|
||||
let @ast.ty output = @spanned(lo, lo, ast.ty_nil);
|
||||
let ast.fn_decl d = rec(effect=ast.eff_pure,
|
||||
inputs=inputs,
|
||||
let ast.fn_decl d = rec(inputs=inputs,
|
||||
output=output);
|
||||
let ast._fn f = rec(decl = d,
|
||||
proto = ast.proto_fn,
|
||||
|
@ -1849,7 +1844,7 @@ impure fn parse_dtor(parser p) -> @ast.method {
|
|||
ret @spanned(lo, f.body.span.hi, m);
|
||||
}
|
||||
|
||||
impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
|
||||
fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.OBJ);
|
||||
auto ident = parse_ident(p);
|
||||
|
@ -1890,7 +1885,7 @@ impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
|
|||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
|
||||
fn parse_mod_items(parser p, token.token term) -> ast._mod {
|
||||
auto index = new_str_hash[ast.mod_index_entry]();
|
||||
auto view_items = parse_view(p, index);
|
||||
let vec[@ast.item] items = vec();
|
||||
|
@ -1904,7 +1899,7 @@ impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
|
|||
ret rec(view_items=view_items, items=items, index=index);
|
||||
}
|
||||
|
||||
impure fn parse_item_const(parser p) -> @ast.item {
|
||||
fn parse_item_const(parser p) -> @ast.item {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.CONST);
|
||||
auto ty = parse_ty(p);
|
||||
|
@ -1917,7 +1912,7 @@ impure fn parse_item_const(parser p) -> @ast.item {
|
|||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_item_mod(parser p) -> @ast.item {
|
||||
fn parse_item_mod(parser p) -> @ast.item {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.MOD);
|
||||
auto id = parse_ident(p);
|
||||
|
@ -1929,7 +1924,7 @@ impure fn parse_item_mod(parser p) -> @ast.item {
|
|||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_item_native_type(parser p) -> @ast.native_item {
|
||||
fn parse_item_native_type(parser p) -> @ast.native_item {
|
||||
auto t = parse_type_decl(p);
|
||||
auto hi = p.get_hi_pos();
|
||||
expect(p, token.SEMI);
|
||||
|
@ -1937,11 +1932,11 @@ impure fn parse_item_native_type(parser p) -> @ast.native_item {
|
|||
ret @spanned(t._0, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_item_native_fn(parser p, ast.effect eff) -> @ast.native_item {
|
||||
fn parse_item_native_fn(parser p) -> @ast.native_item {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.FN);
|
||||
auto t = parse_fn_header(p);
|
||||
auto decl = parse_fn_decl(p, eff);
|
||||
auto decl = parse_fn_decl(p);
|
||||
auto link_name = none[str];
|
||||
if (p.peek() == token.EQ) {
|
||||
p.bump();
|
||||
|
@ -1955,8 +1950,7 @@ impure fn parse_item_native_fn(parser p, ast.effect eff) -> @ast.native_item {
|
|||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_native_item(parser p) -> @ast.native_item {
|
||||
let ast.effect eff = parse_effect(p);
|
||||
fn parse_native_item(parser p) -> @ast.native_item {
|
||||
let ast.opacity opa = parse_opacity(p);
|
||||
let ast.layer lyr = parse_layer(p);
|
||||
alt (p.peek()) {
|
||||
|
@ -1964,7 +1958,7 @@ impure fn parse_native_item(parser p) -> @ast.native_item {
|
|||
ret parse_item_native_type(p);
|
||||
}
|
||||
case (token.FN) {
|
||||
ret parse_item_native_fn(p, eff);
|
||||
ret parse_item_native_fn(p);
|
||||
}
|
||||
case (?t) {
|
||||
unexpected(p, t);
|
||||
|
@ -1973,7 +1967,7 @@ impure fn parse_native_item(parser p) -> @ast.native_item {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_native_mod_items(parser p,
|
||||
fn parse_native_mod_items(parser p,
|
||||
str native_name,
|
||||
ast.native_abi abi) -> ast.native_mod {
|
||||
auto index = new_str_hash[ast.native_mod_index_entry]();
|
||||
|
@ -2008,7 +2002,7 @@ fn default_native_name(session.session sess, str id) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_item_native_mod(parser p) -> @ast.item {
|
||||
fn parse_item_native_mod(parser p) -> @ast.item {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.NATIVE);
|
||||
auto abi = ast.native_abi_cdecl;
|
||||
|
@ -2041,14 +2035,14 @@ impure fn parse_item_native_mod(parser p) -> @ast.item {
|
|||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_type_decl(parser p) -> tup(uint, ast.ident) {
|
||||
fn parse_type_decl(parser p) -> tup(uint, ast.ident) {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.TYPE);
|
||||
auto id = parse_ident(p);
|
||||
ret tup(lo, id);
|
||||
}
|
||||
|
||||
impure fn parse_item_type(parser p) -> @ast.item {
|
||||
fn parse_item_type(parser p) -> @ast.item {
|
||||
auto t = parse_type_decl(p);
|
||||
auto tps = parse_ty_params(p);
|
||||
|
||||
|
@ -2060,7 +2054,7 @@ impure fn parse_item_type(parser p) -> @ast.item {
|
|||
ret @spanned(t._0, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_item_tag(parser p) -> @ast.item {
|
||||
fn parse_item_tag(parser p) -> @ast.item {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.TAG);
|
||||
auto id = parse_ident(p);
|
||||
|
@ -2112,7 +2106,7 @@ impure fn parse_item_tag(parser p) -> @ast.item {
|
|||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_opacity(parser p) -> ast.opacity {
|
||||
fn parse_opacity(parser p) -> ast.opacity {
|
||||
alt (p.peek()) {
|
||||
case (token.ABS) {
|
||||
p.bump();
|
||||
|
@ -2125,7 +2119,7 @@ impure fn parse_opacity(parser p) -> ast.opacity {
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn parse_layer(parser p) -> ast.layer {
|
||||
fn parse_layer(parser p) -> ast.layer {
|
||||
alt (p.peek()) {
|
||||
case (token.STATE) {
|
||||
p.bump();
|
||||
|
@ -2143,18 +2137,14 @@ impure fn parse_layer(parser p) -> ast.layer {
|
|||
}
|
||||
|
||||
|
||||
impure fn parse_effect(parser p) -> ast.effect {
|
||||
fn parse_auth(parser p) -> ast._auth {
|
||||
alt (p.peek()) {
|
||||
case (token.IMPURE) {
|
||||
p.bump();
|
||||
ret ast.eff_impure;
|
||||
}
|
||||
case (token.UNSAFE) {
|
||||
p.bump();
|
||||
ret ast.eff_unsafe;
|
||||
ret ast.auth_unsafe;
|
||||
}
|
||||
case (_) {
|
||||
ret ast.eff_pure;
|
||||
case (?t) {
|
||||
unexpected(p, t);
|
||||
}
|
||||
}
|
||||
fail;
|
||||
|
@ -2164,8 +2154,6 @@ fn peeking_at_item(parser p) -> bool {
|
|||
alt (p.peek()) {
|
||||
case (token.STATE) { ret true; }
|
||||
case (token.GC) { ret true; }
|
||||
case (token.IMPURE) { ret true; }
|
||||
case (token.UNSAFE) { ret true; }
|
||||
case (token.CONST) { ret true; }
|
||||
case (token.FN) { ret true; }
|
||||
case (token.ITER) { ret true; }
|
||||
|
@ -2178,46 +2166,39 @@ fn peeking_at_item(parser p) -> bool {
|
|||
ret false;
|
||||
}
|
||||
|
||||
impure fn parse_item(parser p) -> @ast.item {
|
||||
let ast.effect eff = parse_effect(p);
|
||||
fn parse_item(parser p) -> @ast.item {
|
||||
let ast.opacity opa = parse_opacity(p);
|
||||
let ast.layer lyr = parse_layer(p);
|
||||
|
||||
alt (p.peek()) {
|
||||
case (token.CONST) {
|
||||
check (eff == ast.eff_pure);
|
||||
check (lyr == ast.layer_value);
|
||||
ret parse_item_const(p);
|
||||
}
|
||||
|
||||
case (token.FN) {
|
||||
check (lyr == ast.layer_value);
|
||||
ret parse_item_fn_or_iter(p, eff);
|
||||
ret parse_item_fn_or_iter(p);
|
||||
}
|
||||
case (token.ITER) {
|
||||
check (lyr == ast.layer_value);
|
||||
ret parse_item_fn_or_iter(p, eff);
|
||||
ret parse_item_fn_or_iter(p);
|
||||
}
|
||||
case (token.MOD) {
|
||||
check (eff == ast.eff_pure);
|
||||
check (lyr == ast.layer_value);
|
||||
ret parse_item_mod(p);
|
||||
}
|
||||
case (token.NATIVE) {
|
||||
check (eff == ast.eff_pure);
|
||||
check (lyr == ast.layer_value);
|
||||
ret parse_item_native_mod(p);
|
||||
}
|
||||
case (token.TYPE) {
|
||||
check (eff == ast.eff_pure);
|
||||
ret parse_item_type(p);
|
||||
}
|
||||
case (token.TAG) {
|
||||
check (eff == ast.eff_pure);
|
||||
ret parse_item_tag(p);
|
||||
}
|
||||
case (token.OBJ) {
|
||||
check (eff == ast.eff_pure);
|
||||
ret parse_item_obj(p, lyr);
|
||||
}
|
||||
case (?t) {
|
||||
|
@ -2227,7 +2208,7 @@ impure fn parse_item(parser p) -> @ast.item {
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn parse_meta_item(parser p) -> @ast.meta_item {
|
||||
fn parse_meta_item(parser p) -> @ast.meta_item {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto ident = parse_ident(p);
|
||||
expect(p, token.EQ);
|
||||
|
@ -2244,13 +2225,13 @@ impure fn parse_meta_item(parser p) -> @ast.meta_item {
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn parse_meta(parser p) -> vec[@ast.meta_item] {
|
||||
fn parse_meta(parser p) -> vec[@ast.meta_item] {
|
||||
auto pf = parse_meta_item;
|
||||
ret parse_seq[@ast.meta_item](token.LPAREN, token.RPAREN,
|
||||
some(token.COMMA), pf, p).node;
|
||||
}
|
||||
|
||||
impure fn parse_optional_meta(parser p) -> vec[@ast.meta_item] {
|
||||
fn parse_optional_meta(parser p) -> vec[@ast.meta_item] {
|
||||
alt (p.peek()) {
|
||||
case (token.LPAREN) {
|
||||
ret parse_meta(p);
|
||||
|
@ -2262,7 +2243,7 @@ impure fn parse_optional_meta(parser p) -> vec[@ast.meta_item] {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_use(parser p) -> @ast.view_item {
|
||||
fn parse_use(parser p) -> @ast.view_item {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.USE);
|
||||
auto ident = parse_ident(p);
|
||||
|
@ -2274,7 +2255,7 @@ impure fn parse_use(parser p) -> @ast.view_item {
|
|||
ret @spanned(lo, hi, use_decl);
|
||||
}
|
||||
|
||||
impure fn parse_rest_import_name(parser p, ast.ident first,
|
||||
fn parse_rest_import_name(parser p, ast.ident first,
|
||||
option.t[ast.ident] def_ident)
|
||||
-> @ast.view_item {
|
||||
auto lo = p.get_lo_pos();
|
||||
|
@ -2302,7 +2283,7 @@ impure fn parse_rest_import_name(parser p, ast.ident first,
|
|||
ret @spanned(lo, hi, import_decl);
|
||||
}
|
||||
|
||||
impure fn parse_full_import_name(parser p, ast.ident def_ident)
|
||||
fn parse_full_import_name(parser p, ast.ident def_ident)
|
||||
-> @ast.view_item {
|
||||
alt (p.peek()) {
|
||||
case (token.IDENT(?ident)) {
|
||||
|
@ -2316,7 +2297,7 @@ impure fn parse_full_import_name(parser p, ast.ident def_ident)
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn parse_import(parser p) -> @ast.view_item {
|
||||
fn parse_import(parser p) -> @ast.view_item {
|
||||
expect(p, token.IMPORT);
|
||||
alt (p.peek()) {
|
||||
case (token.IDENT(?ident)) {
|
||||
|
@ -2338,7 +2319,7 @@ impure fn parse_import(parser p) -> @ast.view_item {
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn parse_export(parser p) -> @ast.view_item {
|
||||
fn parse_export(parser p) -> @ast.view_item {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, token.EXPORT);
|
||||
auto id = parse_ident(p);
|
||||
|
@ -2347,7 +2328,7 @@ impure fn parse_export(parser p) -> @ast.view_item {
|
|||
ret @spanned(lo, hi, ast.view_item_export(id));
|
||||
}
|
||||
|
||||
impure fn parse_view_item(parser p) -> @ast.view_item {
|
||||
fn parse_view_item(parser p) -> @ast.view_item {
|
||||
alt (p.peek()) {
|
||||
case (token.USE) {
|
||||
ret parse_use(p);
|
||||
|
@ -2371,7 +2352,7 @@ fn is_view_item(token.token t) -> bool {
|
|||
ret false;
|
||||
}
|
||||
|
||||
impure fn parse_view(parser p, ast.mod_index index) -> vec[@ast.view_item] {
|
||||
fn parse_view(parser p, ast.mod_index index) -> vec[@ast.view_item] {
|
||||
let vec[@ast.view_item] items = vec();
|
||||
while (is_view_item(p.peek())) {
|
||||
auto item = parse_view_item(p);
|
||||
|
@ -2382,7 +2363,7 @@ impure fn parse_view(parser p, ast.mod_index index) -> vec[@ast.view_item] {
|
|||
ret items;
|
||||
}
|
||||
|
||||
impure fn parse_native_view(parser p, ast.native_mod_index index)
|
||||
fn parse_native_view(parser p, ast.native_mod_index index)
|
||||
-> vec[@ast.view_item] {
|
||||
let vec[@ast.view_item] items = vec();
|
||||
while (is_view_item(p.peek())) {
|
||||
|
@ -2395,7 +2376,7 @@ impure fn parse_native_view(parser p, ast.native_mod_index index)
|
|||
}
|
||||
|
||||
|
||||
impure fn parse_crate_from_source_file(parser p) -> @ast.crate {
|
||||
fn parse_crate_from_source_file(parser p) -> @ast.crate {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto m = parse_mod_items(p, token.EOF);
|
||||
let vec[@ast.crate_directive] cdirs = vec();
|
||||
|
@ -2409,7 +2390,7 @@ impure fn parse_crate_from_source_file(parser p) -> @ast.crate {
|
|||
//
|
||||
// Each directive imperatively extends its environment with 0 or more items.
|
||||
|
||||
impure fn parse_crate_directive(parser p) -> ast.crate_directive
|
||||
fn parse_crate_directive(parser p) -> ast.crate_directive
|
||||
{
|
||||
auto lo = p.get_lo_pos();
|
||||
alt (p.peek()) {
|
||||
|
@ -2417,10 +2398,10 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive
|
|||
p.bump();
|
||||
auto n = parse_path(p, GREEDY);
|
||||
expect(p, token.EQ);
|
||||
auto e = parse_effect(p);
|
||||
auto a = parse_auth(p);
|
||||
auto hi = p.get_hi_pos();
|
||||
expect(p, token.SEMI);
|
||||
ret spanned(lo, hi, ast.cdir_auth(n, e));
|
||||
ret spanned(lo, hi, ast.cdir_auth(n, a));
|
||||
}
|
||||
|
||||
case (token.META) {
|
||||
|
@ -2510,7 +2491,7 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive
|
|||
}
|
||||
|
||||
|
||||
impure fn parse_crate_directives(parser p, token.token term)
|
||||
fn parse_crate_directives(parser p, token.token term)
|
||||
-> vec[@ast.crate_directive] {
|
||||
|
||||
let vec[@ast.crate_directive] cdirs = vec();
|
||||
|
@ -2523,7 +2504,7 @@ impure fn parse_crate_directives(parser p, token.token term)
|
|||
ret cdirs;
|
||||
}
|
||||
|
||||
impure fn parse_crate_from_crate_file(parser p) -> @ast.crate {
|
||||
fn parse_crate_from_crate_file(parser p) -> @ast.crate {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto prefix = std.fs.dirname(p.get_filemap().name);
|
||||
auto cdirs = parse_crate_directives(p, token.EOF);
|
||||
|
|
|
@ -100,8 +100,7 @@ tag token {
|
|||
STATE;
|
||||
GC;
|
||||
|
||||
/* Effect keywords */
|
||||
IMPURE;
|
||||
/* Unsafe-block keyword */
|
||||
UNSAFE;
|
||||
|
||||
/* Type qualifiers */
|
||||
|
@ -273,8 +272,7 @@ fn to_str(token t) -> str {
|
|||
case (STATE) { ret "state"; }
|
||||
case (GC) { ret "gc"; }
|
||||
|
||||
/* Effect keywords */
|
||||
case (IMPURE) { ret "impure"; }
|
||||
/* Unsafe-block keyword */
|
||||
case (UNSAFE) { ret "unsafe"; }
|
||||
|
||||
/* Type qualifiers */
|
||||
|
|
|
@ -61,7 +61,6 @@ type ast_fold[ENV] =
|
|||
vec[ast.ty_method] meths) -> @ty) fold_ty_obj,
|
||||
|
||||
(fn(&ENV e, &span sp,
|
||||
ast.effect eff,
|
||||
ast.proto proto,
|
||||
vec[rec(ast.mode mode, @ty ty)] inputs,
|
||||
@ty output) -> @ty) fold_ty_fn,
|
||||
|
@ -299,7 +298,7 @@ type ast_fold[ENV] =
|
|||
ast.proto proto,
|
||||
&block body) -> ast._fn) fold_fn,
|
||||
|
||||
(fn(&ENV e, ast.effect effect,
|
||||
(fn(&ENV e,
|
||||
vec[arg] inputs,
|
||||
@ty output) -> ast.fn_decl) fold_fn_decl,
|
||||
|
||||
|
@ -398,12 +397,12 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
|
|||
case (ast.ty_obj(?meths)) {
|
||||
let vec[ast.ty_method] meths_ = vec();
|
||||
for (ast.ty_method m in meths) {
|
||||
auto tfn = fold_ty_fn(env_, fld, t.span, m.effect, m.proto,
|
||||
auto tfn = fold_ty_fn(env_, fld, t.span, m.proto,
|
||||
m.inputs, m.output);
|
||||
alt (tfn.node) {
|
||||
case (ast.ty_fn(?eff, ?p, ?ins, ?out)) {
|
||||
case (ast.ty_fn(?p, ?ins, ?out)) {
|
||||
_vec.push[ast.ty_method]
|
||||
(meths_, rec(effect=eff, proto=p, inputs=ins,
|
||||
(meths_, rec(proto=p, inputs=ins,
|
||||
output=out with m));
|
||||
}
|
||||
}
|
||||
|
@ -416,8 +415,8 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
|
|||
ret fld.fold_ty_path(env_, t.span, pth_, ref_opt);
|
||||
}
|
||||
|
||||
case (ast.ty_fn(?eff, ?proto, ?inputs, ?output)) {
|
||||
ret fold_ty_fn(env_, fld, t.span, eff, proto, inputs, output);
|
||||
case (ast.ty_fn(?proto, ?inputs, ?output)) {
|
||||
ret fold_ty_fn(env_, fld, t.span, proto, inputs, output);
|
||||
}
|
||||
|
||||
case (ast.ty_chan(?ty)) {
|
||||
|
@ -433,7 +432,7 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
|
|||
}
|
||||
|
||||
fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp,
|
||||
ast.effect eff, ast.proto proto,
|
||||
ast.proto proto,
|
||||
vec[rec(ast.mode mode, @ty ty)] inputs,
|
||||
@ty output) -> @ty {
|
||||
auto output_ = fold_ty(env, fld, output);
|
||||
|
@ -443,7 +442,7 @@ fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp,
|
|||
auto input_ = rec(ty=ty_ with input);
|
||||
inputs_ += vec(input_);
|
||||
}
|
||||
ret fld.fold_ty_fn(env, sp, eff, proto, inputs_, output_);
|
||||
ret fld.fold_ty_fn(env, sp, proto, inputs_, output_);
|
||||
}
|
||||
|
||||
fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
|
||||
|
@ -894,7 +893,7 @@ fn fold_fn_decl[ENV](&ENV env, ast_fold[ENV] fld,
|
|||
inputs += vec(fold_arg(env, fld, a));
|
||||
}
|
||||
auto output = fold_ty[ENV](env, fld, decl.output);
|
||||
ret fld.fold_fn_decl(env, decl.effect, inputs, output);
|
||||
ret fld.fold_fn_decl(env, inputs, output);
|
||||
}
|
||||
|
||||
fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn {
|
||||
|
@ -1187,10 +1186,10 @@ fn identity_fold_ty_obj[ENV](&ENV env, &span sp,
|
|||
}
|
||||
|
||||
fn identity_fold_ty_fn[ENV](&ENV env, &span sp,
|
||||
ast.effect eff, ast.proto proto,
|
||||
ast.proto proto,
|
||||
vec[rec(ast.mode mode, @ty ty)] inputs,
|
||||
@ty output) -> @ty {
|
||||
ret @respan(sp, ast.ty_fn(eff, proto, inputs, output));
|
||||
ret @respan(sp, ast.ty_fn(proto, inputs, output));
|
||||
}
|
||||
|
||||
fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p,
|
||||
|
@ -1530,10 +1529,9 @@ fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block {
|
|||
}
|
||||
|
||||
fn identity_fold_fn_decl[ENV](&ENV e,
|
||||
ast.effect effect,
|
||||
vec[arg] inputs,
|
||||
@ty output) -> ast.fn_decl {
|
||||
ret rec(effect=effect, inputs=inputs, output=output);
|
||||
ret rec(inputs=inputs, output=output);
|
||||
}
|
||||
|
||||
fn identity_fold_fn[ENV](&ENV e,
|
||||
|
@ -1638,7 +1636,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
|||
fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_),
|
||||
fold_ty_rec = bind identity_fold_ty_rec[ENV](_,_,_),
|
||||
fold_ty_obj = bind identity_fold_ty_obj[ENV](_,_,_),
|
||||
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_,_),
|
||||
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_),
|
||||
fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_),
|
||||
fold_ty_chan = bind identity_fold_ty_chan[ENV](_,_,_),
|
||||
fold_ty_port = bind identity_fold_ty_port[ENV](_,_,_),
|
||||
|
@ -1708,7 +1706,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
|||
bind identity_fold_native_item_ty[ENV](_,_,_,_),
|
||||
fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_,_),
|
||||
fold_item_obj = bind identity_fold_item_obj[ENV](_,_,_,_,_,_,_),
|
||||
|
||||
|
||||
fold_view_item_use =
|
||||
bind identity_fold_view_item_use[ENV](_,_,_,_,_,_),
|
||||
fold_view_item_import =
|
||||
|
@ -1720,7 +1718,7 @@ fn new_identity_fold[ENV]() -> ast_fold[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_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](_,_,_,_),
|
||||
|
|
|
@ -521,8 +521,8 @@ fn create_index[T](vec[tup(T, uint)] index, fn(&T) -> uint hash_fn)
|
|||
ret buckets;
|
||||
}
|
||||
|
||||
impure fn encode_index[T](&ebml.writer ebml_w, vec[vec[tup(T, uint)]] buckets,
|
||||
impure fn(io.writer, &T) write_fn) {
|
||||
fn encode_index[T](&ebml.writer ebml_w, vec[vec[tup(T, uint)]] buckets,
|
||||
fn(io.writer, &T) write_fn) {
|
||||
auto writer = io.new_writer_(ebml_w.writer);
|
||||
|
||||
ebml.start_tag(ebml_w, tag_index);
|
||||
|
@ -553,16 +553,16 @@ impure fn encode_index[T](&ebml.writer ebml_w, vec[vec[tup(T, uint)]] buckets,
|
|||
}
|
||||
|
||||
|
||||
impure fn write_str(io.writer writer, &str s) {
|
||||
fn write_str(io.writer writer, &str s) {
|
||||
writer.write_str(s);
|
||||
}
|
||||
|
||||
impure fn write_int(io.writer writer, &int n) {
|
||||
fn write_int(io.writer writer, &int n) {
|
||||
writer.write_be_uint(n as uint, 4u);
|
||||
}
|
||||
|
||||
|
||||
impure fn encode_metadata(@trans.crate_ctxt cx, @ast.crate crate)
|
||||
fn encode_metadata(@trans.crate_ctxt cx, @ast.crate crate)
|
||||
-> ValueRef {
|
||||
auto string_w = io.string_writer();
|
||||
auto buf_w = string_w.get_writer().get_buf_writer();
|
||||
|
|
|
@ -54,8 +54,8 @@ tag sty {
|
|||
ty_task;
|
||||
ty_tup(vec[mt]);
|
||||
ty_rec(vec[field]);
|
||||
ty_fn(ast.proto, vec[arg], @t); // TODO: effect
|
||||
ty_native_fn(ast.native_abi, vec[arg], @t); // TODO: effect
|
||||
ty_fn(ast.proto, vec[arg], @t);
|
||||
ty_native_fn(ast.native_abi, vec[arg], @t);
|
||||
ty_obj(vec[method]);
|
||||
ty_var(int); // ephemeral type var
|
||||
ty_local(ast.def_id); // type of a local var
|
||||
|
|
|
@ -267,7 +267,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
|
|||
sty = ty.ty_rec(flds);
|
||||
}
|
||||
|
||||
case (ast.ty_fn(_, ?proto, ?inputs, ?output)) {
|
||||
case (ast.ty_fn(?proto, ?inputs, ?output)) {
|
||||
auto f = bind ast_arg_to_arg(getter, _);
|
||||
auto i = _vec.map[ast.ty_arg, arg](f, inputs);
|
||||
sty = ty.ty_fn(proto, i, ast_ty_to_ty(getter, output));
|
||||
|
|
|
@ -277,7 +277,7 @@ fn mk_fn_info(_fn f) -> fn_info {
|
|||
ret res;
|
||||
}
|
||||
|
||||
/* extends mk_fn_info to an item, side-effecting the map fi from
|
||||
/* extends mk_fn_info to an item, side-effecting the map fi from
|
||||
function IDs to fn_info maps */
|
||||
fn mk_fn_info_item_fn(&_fn_info_map fi, &span sp, ident i, &ast._fn f,
|
||||
vec[ast.ty_param] ty_params, def_id id, ann a) -> @item {
|
||||
|
@ -888,14 +888,14 @@ fn find_pre_post_expr(&_fn_info_map fm, &fn_info enclosing, &expr e) -> () {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn gen(&fn_info enclosing, &ann a, def_id id) -> bool {
|
||||
fn gen(&fn_info enclosing, &ann a, def_id id) -> bool {
|
||||
check(enclosing.contains_key(id));
|
||||
let uint i = (enclosing.get(id))._0;
|
||||
|
||||
ret set_in_postcond(i, (ann_to_ts_ann_fail_more(a)).conditions);
|
||||
}
|
||||
|
||||
impure fn gen_poststate(&fn_info enclosing, &ann a, def_id id) -> bool {
|
||||
fn gen_poststate(&fn_info enclosing, &ann a, def_id id) -> bool {
|
||||
check(enclosing.contains_key(id));
|
||||
let uint i = (enclosing.get(id))._0;
|
||||
|
||||
|
@ -976,7 +976,7 @@ fn find_pre_post_state_item(_fn_info_map fm, @item i) -> bool {
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn set_prestate_ann(ann a, prestate pre) -> bool {
|
||||
fn set_prestate_ann(ann a, prestate pre) -> bool {
|
||||
alt (a) {
|
||||
case (ann_type(_,_,?ts_a)) {
|
||||
check (! is_none[@ts_ann](ts_a));
|
||||
|
@ -990,7 +990,7 @@ impure fn set_prestate_ann(ann a, prestate pre) -> bool {
|
|||
}
|
||||
|
||||
|
||||
impure fn extend_prestate_ann(ann a, prestate pre) -> bool {
|
||||
fn extend_prestate_ann(ann a, prestate pre) -> bool {
|
||||
alt (a) {
|
||||
case (ann_type(_,_,?ts_a)) {
|
||||
check (! is_none[@ts_ann](ts_a));
|
||||
|
@ -1003,7 +1003,7 @@ impure fn extend_prestate_ann(ann a, prestate pre) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn set_poststate_ann(ann a, poststate post) -> bool {
|
||||
fn set_poststate_ann(ann a, poststate post) -> bool {
|
||||
alt (a) {
|
||||
case (ann_type(_,_,?ts_a)) {
|
||||
check (! is_none[@ts_ann](ts_a));
|
||||
|
@ -1016,7 +1016,7 @@ impure fn set_poststate_ann(ann a, poststate post) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn extend_poststate_ann(ann a, poststate post) -> bool {
|
||||
fn extend_poststate_ann(ann a, poststate post) -> bool {
|
||||
alt (a) {
|
||||
case (ann_type(_,_,?ts_a)) {
|
||||
check (! is_none[@ts_ann](ts_a));
|
||||
|
@ -1029,7 +1029,7 @@ impure fn extend_poststate_ann(ann a, poststate post) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn set_pre_and_post(&ann a, pre_and_post pp) -> () {
|
||||
fn set_pre_and_post(&ann a, pre_and_post pp) -> () {
|
||||
alt (a) {
|
||||
case (ann_type(_,_,?ts_a)) {
|
||||
check (! is_none[@ts_ann](ts_a));
|
||||
|
@ -1068,7 +1068,7 @@ fn find_pre_post_state_exprs(&_fn_info_map fm,
|
|||
ret changed;
|
||||
}
|
||||
|
||||
impure fn pure_exp(&ann a, &prestate p) -> bool {
|
||||
fn pure_exp(&ann a, &prestate p) -> bool {
|
||||
auto changed = false;
|
||||
changed = extend_prestate_ann(a, p) || changed;
|
||||
changed = extend_poststate_ann(a, p) || changed;
|
||||
|
@ -1363,7 +1363,7 @@ fn fixed_point_states(_fn_info_map fm, fn_info f_info,
|
|||
}
|
||||
}
|
||||
|
||||
impure fn check_states_expr(fn_info enclosing, &expr e) -> () {
|
||||
fn check_states_expr(fn_info enclosing, &expr e) -> () {
|
||||
let precond prec = expr_precond(e);
|
||||
let prestate pres = expr_prestate(e);
|
||||
|
||||
|
|
|
@ -48,14 +48,14 @@ fn mkstate(io.writer out, uint width) -> ps {
|
|||
mutable potential_brk=false);
|
||||
}
|
||||
|
||||
impure fn write_spaces(ps p, uint i) {
|
||||
fn write_spaces(ps p, uint i) {
|
||||
while (i > 0u) {
|
||||
i -= 1u;
|
||||
p.out.write_str(" ");
|
||||
}
|
||||
}
|
||||
|
||||
impure fn push_context(ps p, contexttype tp, uint indent) {
|
||||
fn push_context(ps p, contexttype tp, uint indent) {
|
||||
before_print(p, false);
|
||||
_vec.push[context](p.context, rec(tp=tp, indent=indent));
|
||||
p.start_of_box = true;
|
||||
|
@ -65,13 +65,13 @@ fn pop_context(ps p) {
|
|||
_vec.pop[context](p.context);
|
||||
}
|
||||
|
||||
impure fn add_token(ps p, token tok) {
|
||||
fn add_token(ps p, token tok) {
|
||||
if (p.width == 0u) {direct_token(p, tok);}
|
||||
else if (p.scanning == scan_none) {do_token(p, tok);}
|
||||
else {buffer_token(p, tok);}
|
||||
}
|
||||
|
||||
impure fn direct_token(ps p, token tok) {
|
||||
fn direct_token(ps p, token tok) {
|
||||
alt (tok) {
|
||||
case (brk(?sz)) {write_spaces(p, sz);}
|
||||
case (word(?w)) {p.out.write_str(w);}
|
||||
|
@ -80,7 +80,7 @@ impure fn direct_token(ps p, token tok) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn buffer_token(ps p, token tok) {
|
||||
fn buffer_token(ps p, token tok) {
|
||||
p.buffered += vec(tok);
|
||||
auto col = p.scancol;
|
||||
p.scancol = col + token_size(tok);
|
||||
|
@ -114,14 +114,14 @@ impure fn buffer_token(ps p, token tok) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn check_potential_brk(ps p) {
|
||||
fn check_potential_brk(ps p) {
|
||||
for (boxtype tp in p.scandepth) {
|
||||
if (tp != box_h) {ret;}
|
||||
}
|
||||
p.potential_brk = true;
|
||||
}
|
||||
|
||||
impure fn finish_scan(ps p, bool fits) {
|
||||
fn finish_scan(ps p, bool fits) {
|
||||
auto buf = p.buffered;
|
||||
auto front = _vec.shift[token](buf);
|
||||
auto chosen_tp = cx_h;
|
||||
|
@ -145,7 +145,7 @@ impure fn finish_scan(ps p, bool fits) {
|
|||
for (token t in buf) { add_token(p, t); }
|
||||
}
|
||||
|
||||
impure fn start_scan(ps p, token tok, scantype tp) {
|
||||
fn start_scan(ps p, token tok, scantype tp) {
|
||||
p.buffered = vec();
|
||||
p.scancol = p.col;
|
||||
p.scanning = tp;
|
||||
|
@ -174,7 +174,7 @@ fn box_is(boxtype a, boxtype b) -> bool {
|
|||
else {ret false;}
|
||||
}
|
||||
|
||||
impure fn do_token(ps p, token tok) {
|
||||
fn do_token(ps p, token tok) {
|
||||
auto start_of_box = p.start_of_box;
|
||||
p.start_of_box = false;
|
||||
alt (tok) {
|
||||
|
@ -223,14 +223,14 @@ impure fn do_token(ps p, token tok) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn line_break(ps p) {
|
||||
fn line_break(ps p) {
|
||||
p.out.write_str("\n");
|
||||
p.col = 0u;
|
||||
p.spaces = cur_context(p).indent;
|
||||
p.start_of_line = true;
|
||||
}
|
||||
|
||||
impure fn before_print(ps p, bool closing) {
|
||||
fn before_print(ps p, bool closing) {
|
||||
if (p.start_of_line) {
|
||||
p.start_of_line = false;
|
||||
if (closing) {p.spaces = base_indent(p);}
|
||||
|
@ -254,14 +254,14 @@ fn token_size(token tok) -> uint {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn box(ps p, uint indent) {add_token(p, open(box_hv, indent));}
|
||||
impure fn abox(ps p) {add_token(p, open(box_align, 0u));}
|
||||
impure fn vbox(ps p, uint indent) {add_token(p, open(box_v, indent));}
|
||||
impure fn hbox(ps p, uint indent) {add_token(p, open(box_h, indent));}
|
||||
impure fn end(ps p) {add_token(p, close);}
|
||||
impure fn wrd(ps p, str wrd) {add_token(p, word(wrd));}
|
||||
impure fn cwrd(ps p, str wrd) {add_token(p, cword(wrd));}
|
||||
impure fn space(ps p) {add_token(p, brk(1u));}
|
||||
impure fn spaces(ps p, uint n) {add_token(p, brk(n));}
|
||||
impure fn line(ps p) {add_token(p, brk(0u));}
|
||||
impure fn hardbreak(ps p) {add_token(p, hardbrk);}
|
||||
fn box(ps p, uint indent) {add_token(p, open(box_hv, indent));}
|
||||
fn abox(ps p) {add_token(p, open(box_align, 0u));}
|
||||
fn vbox(ps p, uint indent) {add_token(p, open(box_v, indent));}
|
||||
fn hbox(ps p, uint indent) {add_token(p, open(box_h, indent));}
|
||||
fn end(ps p) {add_token(p, close);}
|
||||
fn wrd(ps p, str wrd) {add_token(p, word(wrd));}
|
||||
fn cwrd(ps p, str wrd) {add_token(p, cword(wrd));}
|
||||
fn space(ps p) {add_token(p, brk(1u));}
|
||||
fn spaces(ps p, uint n) {add_token(p, brk(n));}
|
||||
fn line(ps p) {add_token(p, brk(0u));}
|
||||
fn hardbreak(ps p) {add_token(p, hardbrk);}
|
||||
|
|
|
@ -15,7 +15,7 @@ type ps = @rec(pp.ps s,
|
|||
option.t[vec[lexer.cmnt]] comments,
|
||||
mutable uint cur_cmnt);
|
||||
|
||||
impure fn print_file(ast._mod _mod, str filename, io.writer out) {
|
||||
fn print_file(ast._mod _mod, str filename, io.writer out) {
|
||||
auto cmnts = lexer.gather_comments(filename);
|
||||
auto s = @rec(s=pp.mkstate(out, default_columns),
|
||||
comments=option.some[vec[lexer.cmnt]](cmnts),
|
||||
|
@ -59,39 +59,39 @@ fn pat_to_str(&@ast.pat p) -> str {
|
|||
ret writer.get_str();
|
||||
}
|
||||
|
||||
impure fn hbox(ps s) {
|
||||
fn hbox(ps s) {
|
||||
pp.hbox(s.s, indent_unit);
|
||||
}
|
||||
impure fn wrd1(ps s, str word) {
|
||||
fn wrd1(ps s, str word) {
|
||||
wrd(s.s, word);
|
||||
space(s.s);
|
||||
}
|
||||
impure fn popen(ps s) {
|
||||
fn popen(ps s) {
|
||||
wrd(s.s, "(");
|
||||
pp.abox(s.s);
|
||||
}
|
||||
impure fn popen_h(ps s) {
|
||||
fn popen_h(ps s) {
|
||||
wrd(s.s, "(");
|
||||
pp.hbox(s.s, 0u);
|
||||
}
|
||||
impure fn pclose(ps s) {
|
||||
fn pclose(ps s) {
|
||||
end(s.s);
|
||||
wrd(s.s, ")");
|
||||
}
|
||||
impure fn bopen(ps s) {
|
||||
fn bopen(ps s) {
|
||||
wrd(s.s, "{");
|
||||
pp.vbox(s.s, indent_unit);
|
||||
line(s.s);
|
||||
}
|
||||
impure fn bclose(ps s) {
|
||||
fn bclose(ps s) {
|
||||
end(s.s);
|
||||
pp.cwrd(s.s, "}");
|
||||
}
|
||||
impure fn bclose_c(ps s, common.span span) {
|
||||
fn bclose_c(ps s, common.span span) {
|
||||
maybe_print_comment(s, span.hi);
|
||||
bclose(s);
|
||||
}
|
||||
impure fn commasep[IN](ps s, vec[IN] elts, impure fn(ps, &IN) op) {
|
||||
fn commasep[IN](ps s, vec[IN] elts, fn(ps, &IN) op) {
|
||||
auto first = true;
|
||||
for (IN elt in elts) {
|
||||
if (first) {first = false;}
|
||||
|
@ -99,7 +99,7 @@ impure fn commasep[IN](ps s, vec[IN] elts, impure fn(ps, &IN) op) {
|
|||
op(s, elt);
|
||||
}
|
||||
}
|
||||
impure fn commasep_cmnt[IN](ps s, vec[IN] elts, impure fn(ps, &IN) op,
|
||||
fn commasep_cmnt[IN](ps s, vec[IN] elts, fn(ps, &IN) op,
|
||||
fn(&IN) -> common.span get_span) {
|
||||
auto len = _vec.len[IN](elts);
|
||||
auto i = 0u;
|
||||
|
@ -112,21 +112,21 @@ impure fn commasep_cmnt[IN](ps s, vec[IN] elts, impure fn(ps, &IN) op,
|
|||
}
|
||||
}
|
||||
}
|
||||
impure fn commasep_exprs(ps s, vec[@ast.expr] exprs) {
|
||||
fn commasep_exprs(ps s, vec[@ast.expr] exprs) {
|
||||
fn expr_span(&@ast.expr expr) -> common.span {ret expr.span;}
|
||||
auto f = print_expr;
|
||||
auto gs = expr_span;
|
||||
commasep_cmnt[@ast.expr](s, exprs, f, gs);
|
||||
}
|
||||
|
||||
impure fn print_mod(ps s, ast._mod _mod) {
|
||||
fn print_mod(ps s, ast._mod _mod) {
|
||||
for (@ast.view_item vitem in _mod.view_items) {print_view_item(s, vitem);}
|
||||
line(s.s);
|
||||
for (@ast.item item in _mod.items) {print_item(s, item);}
|
||||
print_remaining_comments(s);
|
||||
}
|
||||
|
||||
impure fn print_type(ps s, &@ast.ty ty) {
|
||||
fn print_type(ps s, &@ast.ty ty) {
|
||||
maybe_print_comment(s, ty.span.lo);
|
||||
hbox(s);
|
||||
alt (ty.node) {
|
||||
|
@ -159,7 +159,7 @@ impure fn print_type(ps s, &@ast.ty ty) {
|
|||
case (ast.ty_rec(?fields)) {
|
||||
wrd(s.s, "rec");
|
||||
popen(s);
|
||||
impure fn print_field(ps s, &ast.ty_field f) {
|
||||
fn print_field(ps s, &ast.ty_field f) {
|
||||
hbox(s);
|
||||
print_mt(s, f.mt);
|
||||
space(s.s);
|
||||
|
@ -182,7 +182,7 @@ impure fn print_type(ps s, &@ast.ty ty) {
|
|||
bopen(s);
|
||||
for (ast.ty_method m in methods) {
|
||||
hbox(s);
|
||||
print_ty_fn(s, m.effect, m.proto, option.some[str](m.ident),
|
||||
print_ty_fn(s, m.proto, option.some[str](m.ident),
|
||||
m.inputs, m.output);
|
||||
wrd(s.s, ";");
|
||||
end(s.s);
|
||||
|
@ -190,8 +190,8 @@ impure fn print_type(ps s, &@ast.ty ty) {
|
|||
}
|
||||
bclose_c(s, ty.span);
|
||||
}
|
||||
case (ast.ty_fn(?eff, ?proto,?inputs,?output)) {
|
||||
print_ty_fn(s, eff, proto, option.none[str], inputs, output);
|
||||
case (ast.ty_fn(?proto,?inputs,?output)) {
|
||||
print_ty_fn(s, proto, option.none[str], inputs, output);
|
||||
}
|
||||
case (ast.ty_path(?path,_)) {
|
||||
print_path(s, path);
|
||||
|
@ -200,7 +200,7 @@ impure fn print_type(ps s, &@ast.ty ty) {
|
|||
end(s.s);
|
||||
}
|
||||
|
||||
impure fn print_item(ps s, @ast.item item) {
|
||||
fn print_item(ps s, @ast.item item) {
|
||||
maybe_print_comment(s, item.span.lo);
|
||||
hbox(s);
|
||||
alt (item.node) {
|
||||
|
@ -278,7 +278,7 @@ impure fn print_item(ps s, @ast.item item) {
|
|||
wrd(s.s, v.node.name);
|
||||
if (_vec.len[ast.variant_arg](v.node.args) > 0u) {
|
||||
popen(s);
|
||||
impure fn print_variant_arg(ps s, &ast.variant_arg arg) {
|
||||
fn print_variant_arg(ps s, &ast.variant_arg arg) {
|
||||
print_type(s, arg.ty);
|
||||
}
|
||||
auto f = print_variant_arg;
|
||||
|
@ -295,7 +295,7 @@ impure fn print_item(ps s, @ast.item item) {
|
|||
wrd(s.s, id);
|
||||
print_type_params(s, params);
|
||||
popen(s);
|
||||
impure fn print_field(ps s, &ast.obj_field field) {
|
||||
fn print_field(ps s, &ast.obj_field field) {
|
||||
hbox(s);
|
||||
print_type(s, field.ty);
|
||||
space(s.s);
|
||||
|
@ -337,7 +337,7 @@ impure fn print_item(ps s, @ast.item item) {
|
|||
line(s.s);
|
||||
}
|
||||
|
||||
impure fn print_block(ps s, ast.block blk) {
|
||||
fn print_block(ps s, ast.block blk) {
|
||||
maybe_print_comment(s, blk.span.lo);
|
||||
bopen(s);
|
||||
for (@ast.stmt st in blk.node.stmts) {
|
||||
|
@ -359,7 +359,7 @@ impure fn print_block(ps s, ast.block blk) {
|
|||
bclose_c(s, blk.span);
|
||||
}
|
||||
|
||||
impure fn print_literal(ps s, @ast.lit lit) {
|
||||
fn print_literal(ps s, @ast.lit lit) {
|
||||
maybe_print_comment(s, lit.span.lo);
|
||||
alt (lit.node) {
|
||||
case (ast.lit_str(?st)) {print_string(s, st);}
|
||||
|
@ -392,7 +392,7 @@ impure fn print_literal(ps s, @ast.lit lit) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn print_expr(ps s, &@ast.expr expr) {
|
||||
fn print_expr(ps s, &@ast.expr expr) {
|
||||
maybe_print_comment(s, expr.span.lo);
|
||||
hbox(s);
|
||||
alt (expr.node) {
|
||||
|
@ -406,7 +406,7 @@ impure fn print_expr(ps s, &@ast.expr expr) {
|
|||
pclose(s);
|
||||
}
|
||||
case (ast.expr_tup(?exprs,_)) {
|
||||
impure fn printElt(ps s, &ast.elt elt) {
|
||||
fn printElt(ps s, &ast.elt elt) {
|
||||
hbox(s);
|
||||
if (elt.mut == ast.mut) {wrd1(s, "mutable");}
|
||||
print_expr(s, elt.expr);
|
||||
|
@ -421,7 +421,7 @@ impure fn print_expr(ps s, &@ast.expr expr) {
|
|||
pclose(s);
|
||||
}
|
||||
case (ast.expr_rec(?fields,?wth,_)) {
|
||||
impure fn print_field(ps s, &ast.field field) {
|
||||
fn print_field(ps s, &ast.field field) {
|
||||
hbox(s);
|
||||
if (field.mut == ast.mut) {wrd1(s, "mutable");}
|
||||
wrd(s.s, field.ident);
|
||||
|
@ -460,7 +460,7 @@ impure fn print_expr(ps s, &@ast.expr expr) {
|
|||
print_ident(s, ident);
|
||||
}
|
||||
case (ast.expr_bind(?func,?args,_)) {
|
||||
impure fn print_opt(ps s, &option.t[@ast.expr] expr) {
|
||||
fn print_opt(ps s, &option.t[@ast.expr] expr) {
|
||||
alt (expr) {
|
||||
case (option.some[@ast.expr](?expr)) {
|
||||
print_expr(s, expr);
|
||||
|
@ -685,7 +685,7 @@ impure fn print_expr(ps s, &@ast.expr expr) {
|
|||
end(s.s);
|
||||
}
|
||||
|
||||
impure fn print_decl(ps s, @ast.decl decl) {
|
||||
fn print_decl(ps s, @ast.decl decl) {
|
||||
maybe_print_comment(s, decl.span.lo);
|
||||
hbox(s);
|
||||
alt (decl.node) {
|
||||
|
@ -724,11 +724,11 @@ impure fn print_decl(ps s, @ast.decl decl) {
|
|||
end(s.s);
|
||||
}
|
||||
|
||||
impure fn print_ident(ps s, ast.ident ident) {
|
||||
fn print_ident(ps s, ast.ident ident) {
|
||||
wrd(s.s, ident);
|
||||
}
|
||||
|
||||
impure fn print_for_decl(ps s, @ast.decl decl) {
|
||||
fn print_for_decl(ps s, @ast.decl decl) {
|
||||
alt (decl.node) {
|
||||
case (ast.decl_local(?loc)) {
|
||||
print_type(s, option.get[@ast.ty](loc.ty));
|
||||
|
@ -738,7 +738,7 @@ impure fn print_for_decl(ps s, @ast.decl decl) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn print_path(ps s, ast.path path) {
|
||||
fn print_path(ps s, ast.path path) {
|
||||
maybe_print_comment(s, path.span.lo);
|
||||
auto first = true;
|
||||
for (str id in path.node.idents) {
|
||||
|
@ -754,7 +754,7 @@ impure fn print_path(ps s, ast.path path) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn print_pat(ps s, &@ast.pat pat) {
|
||||
fn print_pat(ps s, &@ast.pat pat) {
|
||||
maybe_print_comment(s, pat.span.lo);
|
||||
alt (pat.node) {
|
||||
case (ast.pat_wild(_)) {wrd(s.s, "_");}
|
||||
|
@ -772,18 +772,13 @@ impure fn print_pat(ps s, &@ast.pat pat) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn print_fn(ps s, ast.fn_decl decl, str name,
|
||||
fn print_fn(ps s, ast.fn_decl decl, str name,
|
||||
vec[ast.ty_param] typarams) {
|
||||
alt (decl.effect) {
|
||||
case (ast.eff_impure) {wrd1(s, "impure");}
|
||||
case (ast.eff_unsafe) {wrd1(s, "unsafe");}
|
||||
case (_) {}
|
||||
}
|
||||
wrd1(s, "fn");
|
||||
wrd(s.s, name);
|
||||
print_type_params(s, typarams);
|
||||
popen(s);
|
||||
impure fn print_arg(ps s, &ast.arg x) {
|
||||
fn print_arg(ps s, &ast.arg x) {
|
||||
hbox(s);
|
||||
if (x.mode == ast.alias) {wrd(s.s, "&");}
|
||||
print_type(s, x.ty);
|
||||
|
@ -804,10 +799,10 @@ impure fn print_fn(ps s, ast.fn_decl decl, str name,
|
|||
}
|
||||
}
|
||||
|
||||
impure fn print_type_params(ps s, vec[ast.ty_param] params) {
|
||||
fn print_type_params(ps s, vec[ast.ty_param] params) {
|
||||
if (_vec.len[ast.ty_param](params) > 0u) {
|
||||
wrd(s.s, "[");
|
||||
impure fn printParam(ps s, &ast.ty_param param) {
|
||||
fn printParam(ps s, &ast.ty_param param) {
|
||||
wrd(s.s, param);
|
||||
}
|
||||
auto f = printParam;
|
||||
|
@ -816,7 +811,7 @@ impure fn print_type_params(ps s, vec[ast.ty_param] params) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn print_view_item(ps s, @ast.view_item item) {
|
||||
fn print_view_item(ps s, @ast.view_item item) {
|
||||
maybe_print_comment(s, item.span.lo);
|
||||
hbox(s);
|
||||
alt (item.node) {
|
||||
|
@ -825,7 +820,7 @@ impure fn print_view_item(ps s, @ast.view_item item) {
|
|||
wrd(s.s, id);
|
||||
if (_vec.len[@ast.meta_item](mta) > 0u) {
|
||||
popen(s);
|
||||
impure fn print_meta(ps s, &@ast.meta_item item) {
|
||||
fn print_meta(ps s, &@ast.meta_item item) {
|
||||
hbox(s);
|
||||
wrd1(s, item.node.name);
|
||||
wrd1(s, "=");
|
||||
|
@ -869,7 +864,7 @@ fn operator_prec(ast.binop op) -> int {
|
|||
fail;
|
||||
}
|
||||
|
||||
impure fn print_maybe_parens(ps s, @ast.expr expr, int outer_prec) {
|
||||
fn print_maybe_parens(ps s, @ast.expr expr, int outer_prec) {
|
||||
auto add_them;
|
||||
alt (expr.node) {
|
||||
case (ast.expr_binary(?op,_,_,_)) {
|
||||
|
@ -907,7 +902,7 @@ fn escape_str(str st, char to_escape) -> str {
|
|||
ret out;
|
||||
}
|
||||
|
||||
impure fn print_mt(ps s, &ast.mt mt) {
|
||||
fn print_mt(ps s, &ast.mt mt) {
|
||||
alt (mt.mut) {
|
||||
case (ast.mut) { wrd1(s, "mutable"); }
|
||||
case (ast.maybe_mut) { wrd1(s, "mutable?"); }
|
||||
|
@ -916,17 +911,12 @@ impure fn print_mt(ps s, &ast.mt mt) {
|
|||
print_type(s, mt.ty);
|
||||
}
|
||||
|
||||
impure fn print_string(ps s, str st) {
|
||||
fn print_string(ps s, str st) {
|
||||
wrd(s.s, "\""); wrd(s.s, escape_str(st, '"')); wrd(s.s, "\"");
|
||||
}
|
||||
|
||||
impure fn print_ty_fn(ps s, ast.effect eff, ast.proto proto, option.t[str] id,
|
||||
vec[ast.ty_arg] inputs, @ast.ty output) {
|
||||
alt (eff) {
|
||||
case (ast.eff_impure) {wrd1(s, "impure");}
|
||||
case (ast.eff_unsafe) {wrd1(s, "unsafe");}
|
||||
case (_) {}
|
||||
}
|
||||
fn print_ty_fn(ps s, ast.proto proto, option.t[str] id,
|
||||
vec[ast.ty_arg] inputs, @ast.ty output) {
|
||||
if (proto == ast.proto_fn) {wrd(s.s, "fn");}
|
||||
else {wrd(s.s, "iter");}
|
||||
alt (id) {
|
||||
|
@ -934,7 +924,7 @@ impure fn print_ty_fn(ps s, ast.effect eff, ast.proto proto, option.t[str] id,
|
|||
case (_) {}
|
||||
}
|
||||
popen_h(s);
|
||||
impure fn print_arg(ps s, &ast.ty_arg input) {
|
||||
fn print_arg(ps s, &ast.ty_arg input) {
|
||||
if (middle.ty.mode_is_alias(input.mode)) {wrd(s.s, "&");}
|
||||
print_type(s, input.ty);
|
||||
}
|
||||
|
@ -962,7 +952,7 @@ fn next_comment(ps s) -> option.t[lexer.cmnt] {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn maybe_print_comment(ps s, uint pos) {
|
||||
fn maybe_print_comment(ps s, uint pos) {
|
||||
while (true) {
|
||||
alt (next_comment(s)) {
|
||||
case (option.some[lexer.cmnt](?cmnt)) {
|
||||
|
@ -977,7 +967,7 @@ impure fn maybe_print_comment(ps s, uint pos) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn maybe_print_line_comment(ps s, common.span span) -> bool {
|
||||
fn maybe_print_line_comment(ps s, common.span span) -> bool {
|
||||
alt (next_comment(s)) {
|
||||
case (option.some[lexer.cmnt](?cmnt)) {
|
||||
if (span.hi + 4u >= cmnt.pos) {
|
||||
|
@ -992,7 +982,7 @@ impure fn maybe_print_line_comment(ps s, common.span span) -> bool {
|
|||
ret false;
|
||||
}
|
||||
|
||||
impure fn print_remaining_comments(ps s) {
|
||||
fn print_remaining_comments(ps s) {
|
||||
while (true) {
|
||||
alt (next_comment(s)) {
|
||||
case (option.some[lexer.cmnt](?cmnt)) {
|
||||
|
@ -1005,7 +995,7 @@ impure fn print_remaining_comments(ps s) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn print_comment(ps s, lexer.cmnt_ cmnt) {
|
||||
fn print_comment(ps s, lexer.cmnt_ cmnt) {
|
||||
alt (cmnt) {
|
||||
case (lexer.cmnt_line(?val)) {
|
||||
wrd(s.s, "// " + val);
|
||||
|
|
|
@ -45,37 +45,11 @@ mod util {
|
|||
mod typestate_ann;
|
||||
}
|
||||
|
||||
auth driver.rustc.main = impure;
|
||||
auth front.creader.parse_ty_str = impure;
|
||||
auth front.creader.load_crate = unsafe;
|
||||
auth front.creader.get_metadata_section = unsafe;
|
||||
auth front.creader.lookup_def = impure;
|
||||
auth front.creader.get_type = impure;
|
||||
auth front.creader.get_symbol = impure;
|
||||
auth front.creader.get_tag_variants = impure;
|
||||
auth front.creader.impure_no_op = impure;
|
||||
auth middle.metadata = unsafe;
|
||||
auth middle.metadata.encode_index = impure;
|
||||
auth middle.metadata.encode_metadata = impure;
|
||||
auth middle.trans = unsafe;
|
||||
auth middle.trans.copy_any_self_to_alloca = impure;
|
||||
auth middle.trans.copy_args_to_allocas = impure;
|
||||
auth middle.trans.trans_block = impure;
|
||||
auth middle.trans.alloc_ty = impure;
|
||||
auth middle.typestate_check.log_expr = impure;
|
||||
auth lib.llvm = unsafe;
|
||||
auth pretty.pprust = impure;
|
||||
auth middle.typestate_check.find_pre_post_block = impure;
|
||||
auth middle.typestate_check.find_pre_post_state_block = impure;
|
||||
auth middle.typestate_check.find_pre_post_state_stmt = impure;
|
||||
auth middle.typestate_check.find_pre_post_state_expr = impure;
|
||||
auth middle.typestate_check.find_pre_post_state_exprs = impure;
|
||||
auth middle.typestate_check.find_pre_post_expr = impure;
|
||||
auth middle.typestate_check.find_pre_post_stmt = impure;
|
||||
auth middle.typestate_check.check_states_against_conditions = impure;
|
||||
auth middle.typestate_check.check_states_stmt = impure;
|
||||
auth middle.typestate_check.log_stmt = impure;
|
||||
auth util.typestate_ann.implies = impure;
|
||||
|
||||
mod lib {
|
||||
alt (target_os) {
|
||||
|
|
|
@ -85,20 +85,20 @@ fn pps_len(&pre_and_post p) -> uint {
|
|||
ret p.precondition.nbits;
|
||||
}
|
||||
|
||||
impure fn require_and_preserve(uint i, &pre_and_post p) -> () {
|
||||
fn require_and_preserve(uint i, &pre_and_post p) -> () {
|
||||
// sets the ith bit in p's pre and post
|
||||
bitv.set(p.precondition, i, true);
|
||||
bitv.set(p.postcondition, i, true);
|
||||
}
|
||||
|
||||
impure fn set_in_postcond(uint i, &pre_and_post p) -> bool {
|
||||
fn set_in_postcond(uint i, &pre_and_post p) -> bool {
|
||||
// sets the ith bit in p's post
|
||||
auto was_set = bitv.get(p.postcondition, i);
|
||||
bitv.set(p.postcondition, i, true);
|
||||
ret !was_set;
|
||||
}
|
||||
|
||||
impure fn set_in_poststate(uint i, &pre_and_post_state s) -> bool {
|
||||
fn set_in_poststate(uint i, &pre_and_post_state s) -> bool {
|
||||
// sets the ith bit in p's post
|
||||
auto was_set = bitv.get(s.poststate, i);
|
||||
bitv.set(s.poststate, i, true);
|
||||
|
@ -107,35 +107,35 @@ impure fn set_in_poststate(uint i, &pre_and_post_state s) -> bool {
|
|||
|
||||
// Sets all the bits in a's precondition to equal the
|
||||
// corresponding bit in p's precondition.
|
||||
impure fn set_precondition(&ts_ann a, &precond p) -> () {
|
||||
fn set_precondition(&ts_ann a, &precond p) -> () {
|
||||
bitv.copy(a.conditions.precondition, p);
|
||||
}
|
||||
|
||||
// Sets all the bits in a's postcondition to equal the
|
||||
// corresponding bit in p's postcondition.
|
||||
impure fn set_postcondition(&ts_ann a, &postcond p) -> () {
|
||||
fn set_postcondition(&ts_ann a, &postcond p) -> () {
|
||||
bitv.copy(a.conditions.postcondition, p);
|
||||
}
|
||||
|
||||
// Sets all the bits in a's prestate to equal the
|
||||
// corresponding bit in p's prestate.
|
||||
impure fn set_prestate(&ts_ann a, &prestate p) -> bool {
|
||||
fn set_prestate(&ts_ann a, &prestate p) -> bool {
|
||||
ret bitv.copy(a.states.prestate, p);
|
||||
}
|
||||
|
||||
// Sets all the bits in a's postcondition to equal the
|
||||
// corresponding bit in p's postcondition.
|
||||
impure fn set_poststate(&ts_ann a, &poststate p) -> bool {
|
||||
fn set_poststate(&ts_ann a, &poststate p) -> bool {
|
||||
ret bitv.copy(a.states.poststate, p);
|
||||
}
|
||||
|
||||
// Set all the bits in p that are set in new
|
||||
impure fn extend_prestate(&prestate p, &poststate new) -> bool {
|
||||
fn extend_prestate(&prestate p, &poststate new) -> bool {
|
||||
ret bitv.union(p, new);
|
||||
}
|
||||
|
||||
// Set all the bits in p that are set in new
|
||||
impure fn extend_poststate(&poststate p, &poststate new) -> bool {
|
||||
fn extend_poststate(&poststate p, &poststate new) -> bool {
|
||||
ret bitv.union(p, new);
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ fn ann_prestate(&ts_ann a) -> prestate {
|
|||
// returns true if a implies b
|
||||
// that is, returns true except if for some bits c and d,
|
||||
// c = 1 and d = 0
|
||||
impure fn implies(bitv.t a, bitv.t b) -> bool {
|
||||
fn implies(bitv.t a, bitv.t b) -> bool {
|
||||
auto tmp = bitv.clone(b);
|
||||
bitv.difference(tmp, a);
|
||||
ret bitv.is_false(tmp);
|
||||
|
|
|
@ -154,11 +154,11 @@ fn unsafe_from_byte(u8 u) -> str {
|
|||
ret rustrt.str_from_vec(vec(u));
|
||||
}
|
||||
|
||||
unsafe fn str_from_cstr(sbuf cstr) -> str {
|
||||
fn str_from_cstr(sbuf cstr) -> str {
|
||||
ret rustrt.str_from_cstr(cstr);
|
||||
}
|
||||
|
||||
unsafe fn str_from_buf(sbuf buf, uint len) -> str {
|
||||
fn str_from_buf(sbuf buf, uint len) -> str {
|
||||
ret rustrt.str_from_buf(buf, len);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ fn refcount[T](vec[mutable? T] v) -> uint {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T] {
|
||||
fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T] {
|
||||
ret rustrt.vec_from_vbuf[T](v, n_elts);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ fn create(uint nbits, bool init) -> t {
|
|||
ret rec(storage = storage, nbits = nbits);
|
||||
}
|
||||
|
||||
impure fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool {
|
||||
fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool {
|
||||
auto len = _vec.len[mutable uint](v1.storage);
|
||||
|
||||
check (_vec.len[mutable uint](v0.storage) == len);
|
||||
|
@ -51,7 +51,7 @@ fn lor(uint w0, uint w1) -> uint {
|
|||
ret w0 | w1;
|
||||
}
|
||||
|
||||
impure fn union(&t v0, &t v1) -> bool {
|
||||
fn union(&t v0, &t v1) -> bool {
|
||||
auto sub = lor;
|
||||
ret process(sub, v0, v1);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ fn land(uint w0, uint w1) -> uint {
|
|||
ret w0 & w1;
|
||||
}
|
||||
|
||||
impure fn intersect(&t v0, &t v1) -> bool {
|
||||
fn intersect(&t v0, &t v1) -> bool {
|
||||
auto sub = land;
|
||||
ret process(sub, v0, v1);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ fn right(uint w0, uint w1) -> uint {
|
|||
ret w1;
|
||||
}
|
||||
|
||||
impure fn copy(&t v0, t v1) -> bool {
|
||||
fn copy(&t v0, t v1) -> bool {
|
||||
auto sub = right;
|
||||
ret process(sub, v0, v1);
|
||||
}
|
||||
|
@ -108,27 +108,27 @@ fn equal(&t v0, &t v1) -> bool {
|
|||
ret true;
|
||||
}
|
||||
|
||||
impure fn clear(&t v) {
|
||||
fn clear(&t v) {
|
||||
for each (uint i in _uint.range(0u, _vec.len[mutable uint](v.storage))) {
|
||||
v.storage.(i) = 0u;
|
||||
}
|
||||
}
|
||||
|
||||
impure fn invert(&t v) {
|
||||
fn invert(&t v) {
|
||||
for each (uint i in _uint.range(0u, _vec.len[mutable uint](v.storage))) {
|
||||
v.storage.(i) = ~v.storage.(i);
|
||||
}
|
||||
}
|
||||
|
||||
/* v0 = v0 - v1 */
|
||||
impure fn difference(&t v0, &t v1) -> bool {
|
||||
fn difference(&t v0, &t v1) -> bool {
|
||||
invert(v1);
|
||||
auto b = intersect(v0, v1);
|
||||
invert(v1);
|
||||
ret b;
|
||||
}
|
||||
|
||||
impure fn set(&t v, uint i, bool x) {
|
||||
fn set(&t v, uint i, bool x) {
|
||||
check (i < v.nbits);
|
||||
|
||||
auto bits = uint_bits();
|
||||
|
|
|
@ -26,11 +26,11 @@ fn connect(path pre, path post) -> path {
|
|||
ret pre + path_sep() + post;
|
||||
}
|
||||
|
||||
impure fn file_is_dir(path p) -> bool {
|
||||
fn file_is_dir(path p) -> bool {
|
||||
ret rustrt.rust_file_is_dir(p) != 0;
|
||||
}
|
||||
|
||||
impure fn list_dir(path p) -> vec[str] {
|
||||
fn list_dir(path p) -> vec[str] {
|
||||
auto pl = _str.byte_len(p);
|
||||
if (pl == 0u || p.(pl - 1u) as char != os_fs.path_sep) {
|
||||
p += path_sep();
|
||||
|
|
124
src/lib/io.rs
124
src/lib/io.rs
|
@ -14,37 +14,37 @@ tag seek_style {seek_set; seek_end; seek_cur;}
|
|||
// The raw underlying reader class. All readers must implement this.
|
||||
type buf_reader =
|
||||
state obj {
|
||||
impure fn read(uint len) -> vec[u8];
|
||||
impure fn read_byte() -> int;
|
||||
impure fn unread_byte(int byte);
|
||||
impure fn eof() -> bool;
|
||||
fn read(uint len) -> vec[u8];
|
||||
fn read_byte() -> int;
|
||||
fn unread_byte(int byte);
|
||||
fn eof() -> bool;
|
||||
|
||||
// FIXME: Seekable really should be orthogonal. We will need
|
||||
// inheritance.
|
||||
impure fn seek(int offset, seek_style whence);
|
||||
impure fn tell() -> uint;
|
||||
fn seek(int offset, seek_style whence);
|
||||
fn tell() -> uint;
|
||||
};
|
||||
|
||||
// Convenience methods for reading.
|
||||
type reader =
|
||||
state obj {
|
||||
// FIXME: This should inherit from buf_reader.
|
||||
impure fn get_buf_reader() -> buf_reader;
|
||||
fn get_buf_reader() -> buf_reader;
|
||||
|
||||
impure fn read_byte() -> int;
|
||||
impure fn unread_byte(int byte);
|
||||
impure fn read_bytes(uint len) -> vec[u8];
|
||||
impure fn read_char() -> char;
|
||||
impure fn eof() -> bool;
|
||||
impure fn read_line() -> str;
|
||||
impure fn read_c_str() -> str;
|
||||
impure fn read_le_uint(uint size) -> uint;
|
||||
impure fn read_le_int(uint size) -> int;
|
||||
impure fn read_be_uint(uint size) -> uint;
|
||||
impure fn read_whole_stream() -> vec[u8];
|
||||
fn read_byte() -> int;
|
||||
fn unread_byte(int byte);
|
||||
fn read_bytes(uint len) -> vec[u8];
|
||||
fn read_char() -> char;
|
||||
fn eof() -> bool;
|
||||
fn read_line() -> str;
|
||||
fn read_c_str() -> str;
|
||||
fn read_le_uint(uint size) -> uint;
|
||||
fn read_le_int(uint size) -> int;
|
||||
fn read_be_uint(uint size) -> uint;
|
||||
fn read_whole_stream() -> vec[u8];
|
||||
|
||||
impure fn seek(int offset, seek_style whence);
|
||||
impure fn tell() -> uint; // FIXME: eventually u64
|
||||
fn seek(int offset, seek_style whence);
|
||||
fn tell() -> uint; // FIXME: eventually u64
|
||||
};
|
||||
|
||||
fn convert_whence(seek_style whence) -> int {
|
||||
|
@ -56,25 +56,25 @@ fn convert_whence(seek_style whence) -> int {
|
|||
}
|
||||
|
||||
state obj FILE_buf_reader(os.libc.FILE f, bool must_close) {
|
||||
impure fn read(uint len) -> vec[u8] {
|
||||
fn read(uint len) -> vec[u8] {
|
||||
auto buf = _vec.alloc[u8](len);
|
||||
auto read = os.libc.fread(_vec.buf[u8](buf), 1u, len, f);
|
||||
_vec.len_set[u8](buf, read);
|
||||
ret buf;
|
||||
}
|
||||
impure fn read_byte() -> int {
|
||||
fn read_byte() -> int {
|
||||
ret os.libc.fgetc(f);
|
||||
}
|
||||
impure fn unread_byte(int byte) {
|
||||
fn unread_byte(int byte) {
|
||||
os.libc.ungetc(byte, f);
|
||||
}
|
||||
impure fn eof() -> bool {
|
||||
fn eof() -> bool {
|
||||
ret os.libc.feof(f) != 0;
|
||||
}
|
||||
impure fn seek(int offset, seek_style whence) {
|
||||
fn seek(int offset, seek_style whence) {
|
||||
check (os.libc.fseek(f, offset, convert_whence(whence)) == 0);
|
||||
}
|
||||
impure fn tell() -> uint {
|
||||
fn tell() -> uint {
|
||||
ret os.libc.ftell(f) as uint;
|
||||
}
|
||||
drop {
|
||||
|
@ -84,19 +84,19 @@ state obj FILE_buf_reader(os.libc.FILE f, bool must_close) {
|
|||
|
||||
// FIXME: Convert this into pseudomethods on buf_reader.
|
||||
state obj new_reader(buf_reader rdr) {
|
||||
impure fn get_buf_reader() -> buf_reader {
|
||||
fn get_buf_reader() -> buf_reader {
|
||||
ret rdr;
|
||||
}
|
||||
impure fn read_byte() -> int {
|
||||
fn read_byte() -> int {
|
||||
ret rdr.read_byte();
|
||||
}
|
||||
impure fn unread_byte(int byte) {
|
||||
fn unread_byte(int byte) {
|
||||
ret rdr.unread_byte(byte);
|
||||
}
|
||||
impure fn read_bytes(uint len) -> vec[u8] {
|
||||
fn read_bytes(uint len) -> vec[u8] {
|
||||
ret rdr.read(len);
|
||||
}
|
||||
impure fn read_char() -> char {
|
||||
fn read_char() -> char {
|
||||
auto c0 = rdr.read_byte();
|
||||
if (c0 == -1) {ret -1 as char;} // FIXME will this stay valid?
|
||||
auto b0 = c0 as u8;
|
||||
|
@ -116,10 +116,10 @@ state obj new_reader(buf_reader rdr) {
|
|||
val += ((b0 << ((w + 1u) as u8)) as uint) << ((w - 1u) * 6u - w - 1u);
|
||||
ret val as char;
|
||||
}
|
||||
impure fn eof() -> bool {
|
||||
fn eof() -> bool {
|
||||
ret rdr.eof();
|
||||
}
|
||||
impure fn read_line() -> str {
|
||||
fn read_line() -> str {
|
||||
let vec[u8] buf = vec();
|
||||
// No break yet in rustc
|
||||
auto go_on = true;
|
||||
|
@ -130,7 +130,7 @@ state obj new_reader(buf_reader rdr) {
|
|||
}
|
||||
ret _str.unsafe_from_bytes(buf);
|
||||
}
|
||||
impure fn read_c_str() -> str {
|
||||
fn read_c_str() -> str {
|
||||
let vec[u8] buf = vec();
|
||||
auto go_on = true;
|
||||
while (go_on) {
|
||||
|
@ -141,7 +141,7 @@ state obj new_reader(buf_reader rdr) {
|
|||
ret _str.unsafe_from_bytes(buf);
|
||||
}
|
||||
// FIXME deal with eof?
|
||||
impure fn read_le_uint(uint size) -> uint {
|
||||
fn read_le_uint(uint size) -> uint {
|
||||
auto val = 0u;
|
||||
auto pos = 0u;
|
||||
while (size > 0u) {
|
||||
|
@ -151,7 +151,7 @@ state obj new_reader(buf_reader rdr) {
|
|||
}
|
||||
ret val;
|
||||
}
|
||||
impure fn read_le_int(uint size) -> int {
|
||||
fn read_le_int(uint size) -> int {
|
||||
auto val = 0u;
|
||||
auto pos = 0u;
|
||||
while (size > 0u) {
|
||||
|
@ -162,7 +162,7 @@ state obj new_reader(buf_reader rdr) {
|
|||
ret val as int;
|
||||
}
|
||||
// FIXME deal with eof?
|
||||
impure fn read_be_uint(uint size) -> uint {
|
||||
fn read_be_uint(uint size) -> uint {
|
||||
auto val = 0u;
|
||||
auto sz = size; // FIXME: trans.ml bug workaround
|
||||
while (sz > 0u) {
|
||||
|
@ -171,17 +171,17 @@ state obj new_reader(buf_reader rdr) {
|
|||
}
|
||||
ret val;
|
||||
}
|
||||
impure fn read_whole_stream() -> vec[u8] {
|
||||
fn read_whole_stream() -> vec[u8] {
|
||||
let vec[u8] buf = vec();
|
||||
while (!rdr.eof()) {
|
||||
buf += rdr.read(2048u);
|
||||
}
|
||||
ret buf;
|
||||
}
|
||||
impure fn seek(int offset, seek_style whence) {
|
||||
fn seek(int offset, seek_style whence) {
|
||||
ret rdr.seek(offset, whence);
|
||||
}
|
||||
impure fn tell() -> uint {
|
||||
fn tell() -> uint {
|
||||
ret rdr.tell();
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ fn new_reader_(buf_reader bufr) -> reader {
|
|||
type byte_buf = @rec(vec[u8] buf, mutable uint pos);
|
||||
|
||||
state obj byte_buf_reader(byte_buf bbuf) {
|
||||
impure fn read(uint len) -> vec[u8] {
|
||||
fn read(uint len) -> vec[u8] {
|
||||
auto rest = _vec.len[u8](bbuf.buf) - bbuf.pos;
|
||||
auto to_read = len;
|
||||
if (rest < to_read) {
|
||||
|
@ -221,29 +221,29 @@ state obj byte_buf_reader(byte_buf bbuf) {
|
|||
bbuf.pos += to_read;
|
||||
ret range;
|
||||
}
|
||||
impure fn read_byte() -> int {
|
||||
fn read_byte() -> int {
|
||||
if (bbuf.pos == _vec.len[u8](bbuf.buf)) {ret -1;}
|
||||
auto b = bbuf.buf.(bbuf.pos);
|
||||
bbuf.pos += 1u;
|
||||
ret b as int;
|
||||
}
|
||||
|
||||
impure fn unread_byte(int byte) {
|
||||
fn unread_byte(int byte) {
|
||||
log_err "TODO: unread_byte";
|
||||
fail;
|
||||
}
|
||||
|
||||
impure fn eof() -> bool {
|
||||
fn eof() -> bool {
|
||||
ret bbuf.pos == _vec.len[u8](bbuf.buf);
|
||||
}
|
||||
|
||||
impure fn seek(int offset, seek_style whence) {
|
||||
fn seek(int offset, seek_style whence) {
|
||||
auto pos = bbuf.pos;
|
||||
auto len = _vec.len[u8](bbuf.buf);
|
||||
bbuf.pos = seek_in_buf(offset, pos, len, whence);
|
||||
}
|
||||
|
||||
impure fn tell() -> uint { ret bbuf.pos; }
|
||||
fn tell() -> uint { ret bbuf.pos; }
|
||||
}
|
||||
|
||||
fn new_byte_buf_reader(vec[u8] buf) -> byte_buf_reader {
|
||||
|
@ -355,14 +355,14 @@ type writer =
|
|||
fn get_buf_writer() -> buf_writer;
|
||||
// write_str will continue to do utf-8 output only. an alternative
|
||||
// function will be provided for general encoded string output
|
||||
impure fn write_str(str s);
|
||||
impure fn write_char(char ch);
|
||||
impure fn write_int(int n);
|
||||
impure fn write_uint(uint n);
|
||||
impure fn write_bytes(vec[u8] bytes);
|
||||
impure fn write_le_uint(uint n, uint size);
|
||||
impure fn write_le_int(int n, uint size);
|
||||
impure fn write_be_uint(uint n, uint size);
|
||||
fn write_str(str s);
|
||||
fn write_char(char ch);
|
||||
fn write_int(int n);
|
||||
fn write_uint(uint n);
|
||||
fn write_bytes(vec[u8] bytes);
|
||||
fn write_le_uint(uint n, uint size);
|
||||
fn write_le_int(int n, uint size);
|
||||
fn write_be_uint(uint n, uint size);
|
||||
};
|
||||
|
||||
fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
|
||||
|
@ -389,29 +389,29 @@ state obj new_writer(buf_writer out) {
|
|||
fn get_buf_writer() -> buf_writer {
|
||||
ret out;
|
||||
}
|
||||
impure fn write_str(str s) {
|
||||
fn write_str(str s) {
|
||||
out.write(_str.bytes(s));
|
||||
}
|
||||
impure fn write_char(char ch) {
|
||||
fn write_char(char ch) {
|
||||
// FIXME needlessly consy
|
||||
out.write(_str.bytes(_str.from_char(ch)));
|
||||
}
|
||||
impure fn write_int(int n) {
|
||||
fn write_int(int n) {
|
||||
out.write(_str.bytes(_int.to_str(n, 10u)));
|
||||
}
|
||||
impure fn write_uint(uint n) {
|
||||
fn write_uint(uint n) {
|
||||
out.write(_str.bytes(_uint.to_str(n, 10u)));
|
||||
}
|
||||
impure fn write_bytes(vec[u8] bytes) {
|
||||
fn write_bytes(vec[u8] bytes) {
|
||||
out.write(bytes);
|
||||
}
|
||||
impure fn write_le_uint(uint n, uint size) {
|
||||
fn write_le_uint(uint n, uint size) {
|
||||
out.write(uint_to_le_bytes(n, size));
|
||||
}
|
||||
impure fn write_le_int(int n, uint size) {
|
||||
fn write_le_int(int n, uint size) {
|
||||
out.write(uint_to_le_bytes(n as uint, size));
|
||||
}
|
||||
impure fn write_be_uint(uint n, uint size) {
|
||||
fn write_be_uint(uint n, uint size) {
|
||||
out.write(uint_to_be_bytes(n, size));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
|
|||
* We attempt to never call this with a full table. If we do, it
|
||||
* will fail.
|
||||
*/
|
||||
impure fn insert_common[K, V](&hashfn[K] hasher,
|
||||
fn insert_common[K, V](&hashfn[K] hasher,
|
||||
&eqfn[K] eqer,
|
||||
vec[mutable bucket[K, V]] bkts,
|
||||
uint nbkts,
|
||||
|
@ -119,7 +119,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
|
|||
}
|
||||
|
||||
|
||||
impure fn rehash[K, V](&hashfn[K] hasher,
|
||||
fn rehash[K, V](&hashfn[K] hasher,
|
||||
&eqfn[K] eqer,
|
||||
vec[mutable bucket[K, V]] oldbkts, uint noldbkts,
|
||||
vec[mutable bucket[K, V]] newbkts, uint nnewbkts)
|
||||
|
|
|
@ -2,7 +2,7 @@ native "rust" mod rustrt {
|
|||
fn rust_dirent_filename(os.libc.dirent ent) -> str;
|
||||
}
|
||||
|
||||
impure fn list_dir(str path) -> vec[str] {
|
||||
fn list_dir(str path) -> vec[str] {
|
||||
// TODO ensure this is always closed
|
||||
auto dir = os.libc.opendir(_str.buf(path));
|
||||
check (dir as uint != 0u);
|
||||
|
|
|
@ -14,7 +14,7 @@ fn argvec(str prog, vec[str] args) -> vec[sbuf] {
|
|||
ret argptrs;
|
||||
}
|
||||
|
||||
impure fn run_program(str prog, vec[str] args) -> int {
|
||||
fn run_program(str prog, vec[str] args) -> int {
|
||||
auto pid = rustrt.rust_run_program(_vec.buf[sbuf](argvec(prog, args)),
|
||||
0, 0, 0);
|
||||
ret os.waitpid(pid);
|
||||
|
@ -25,11 +25,11 @@ type program =
|
|||
fn get_id() -> int;
|
||||
fn input() -> io.writer;
|
||||
fn output() -> io.reader;
|
||||
impure fn close_input();
|
||||
impure fn finish() -> int;
|
||||
fn close_input();
|
||||
fn finish() -> int;
|
||||
};
|
||||
|
||||
impure fn start_program(str prog, vec[str] args) -> @program {
|
||||
fn start_program(str prog, vec[str] args) -> @program {
|
||||
auto pipe_input = os.pipe();
|
||||
auto pipe_output = os.pipe();
|
||||
auto pid = rustrt.rust_run_program
|
||||
|
@ -50,10 +50,10 @@ impure fn start_program(str prog, vec[str] args) -> @program {
|
|||
fn output() -> io.reader {
|
||||
ret io.new_reader(io.FILE_buf_reader(out_file, false));
|
||||
}
|
||||
impure fn close_input() {
|
||||
fn close_input() {
|
||||
os.libc.close(in_fd);
|
||||
}
|
||||
impure fn finish() -> int {
|
||||
fn finish() -> int {
|
||||
if (finished) {ret 0;}
|
||||
finished = true;
|
||||
os.libc.close(in_fd);
|
||||
|
@ -72,7 +72,7 @@ impure fn start_program(str prog, vec[str] args) -> @program {
|
|||
false);
|
||||
}
|
||||
|
||||
impure fn program_output(str prog, vec[str] args)
|
||||
fn program_output(str prog, vec[str] args)
|
||||
-> rec(int status, str out) {
|
||||
auto pr = start_program(prog, args);
|
||||
pr.close_input();
|
||||
|
|
|
@ -41,7 +41,7 @@ fn mk_sha1() -> sha1 {
|
|||
mutable uint msg_block_idx,
|
||||
mutable bool computed);
|
||||
|
||||
impure fn add_input(&sha1state st, &vec[u8] msg) {
|
||||
fn add_input(&sha1state st, &vec[u8] msg) {
|
||||
// FIXME: Should be typestate precondition
|
||||
check (!st.computed);
|
||||
|
||||
|
@ -64,7 +64,7 @@ fn mk_sha1() -> sha1 {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn process_msg_block(&sha1state st) {
|
||||
fn process_msg_block(&sha1state st) {
|
||||
|
||||
// FIXME: Make precondition
|
||||
check (_vec.len[mutable u32](st.h) == digest_buf_len);
|
||||
|
@ -164,7 +164,7 @@ fn mk_sha1() -> sha1 {
|
|||
ret (word << bits_hack) | (word >> (32u32 - bits));
|
||||
}
|
||||
|
||||
impure fn mk_result(&sha1state st) -> vec[u8] {
|
||||
fn mk_result(&sha1state st) -> vec[u8] {
|
||||
if (!st.computed) {
|
||||
pad_msg(st);
|
||||
st.computed = true;
|
||||
|
@ -190,7 +190,7 @@ fn mk_sha1() -> sha1 {
|
|||
* call process_msg_block() appropriately. When it returns, it
|
||||
* can be assumed that the message digest has been computed.
|
||||
*/
|
||||
impure fn pad_msg(&sha1state st) {
|
||||
fn pad_msg(&sha1state st) {
|
||||
// FIXME: Should be a precondition
|
||||
check (_vec.len[mutable u8](st.msg_block) == msg_block_len);
|
||||
|
||||
|
|
|
@ -34,21 +34,6 @@ auth _str = unsafe;
|
|||
auth _vec = unsafe;
|
||||
auth _task = unsafe;
|
||||
|
||||
|
||||
// FIXME: impure on these will infect caller in a way that is totally
|
||||
// beyond reason, if the caller's mutated-argument doesn't escape;
|
||||
// 'impure' needs work.
|
||||
auth _str.unshift_byte = impure;
|
||||
auth _str.shift_byte = impure;
|
||||
auth _str.pop_byte = impure;
|
||||
auth _str.unshift_char = impure;
|
||||
auth _str.shift_char = impure;
|
||||
auth _str.pop_char = impure;
|
||||
auth _vec.shift = impure;
|
||||
auth _vec.unshift = impure;
|
||||
auth _vec.pop = impure;
|
||||
auth UFind.union = impure;
|
||||
|
||||
auth dbg = unsafe;
|
||||
|
||||
auth _uint.next_power_of_two = unsafe;
|
||||
|
|
|
@ -3,7 +3,7 @@ native "rust" mod rustrt {
|
|||
fn rust_file_is_dir(str path) -> int;
|
||||
}
|
||||
|
||||
impure fn list_dir(str path) -> vec[str] {
|
||||
fn list_dir(str path) -> vec[str] {
|
||||
ret rustrt.rust_list_files(path+"*");
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use std;
|
|||
import std._int;
|
||||
import std._vec;
|
||||
|
||||
impure fn fannkuch(int n) -> int {
|
||||
fn fannkuch(int n) -> int {
|
||||
|
||||
fn perm1init(uint i) -> mutable int {
|
||||
ret i as int;
|
||||
|
@ -94,7 +94,7 @@ impure fn fannkuch(int n) -> int {
|
|||
ret flips;
|
||||
}
|
||||
|
||||
impure fn main(vec[str] args) {
|
||||
fn main(vec[str] args) {
|
||||
auto n = 7;
|
||||
log #fmt("Pfannkuchen(%d) = %d", n, fannkuch(n));
|
||||
}
|
|
@ -218,7 +218,7 @@ mod Body {
|
|||
);
|
||||
}
|
||||
|
||||
impure fn offsetMomentum(&Body.props props,
|
||||
fn offsetMomentum(&Body.props props,
|
||||
float px,
|
||||
float py,
|
||||
float pz) -> () {
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
// xfail-stage0
|
||||
// -*- rust -*-
|
||||
|
||||
// error-pattern: impure function used in constraint
|
||||
|
||||
fn f(int a, int b) : lt(a,b) {
|
||||
}
|
||||
|
||||
impure fn lt(int a, int b) -> bool {
|
||||
let port[int] p = port();
|
||||
let chan[int] c = chan(p);
|
||||
c <| 10;
|
||||
ret true;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let int a = 10;
|
||||
let int b = 23;
|
||||
check lt(a,b);
|
||||
f(a,b);
|
||||
}
|
|
@ -7,7 +7,7 @@ fn child() {
|
|||
check (1 == 2);
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
spawn child();
|
||||
let int x;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// xfail-stage0
|
||||
// -*- rust -*-
|
||||
|
||||
impure fn f(chan[int] c)
|
||||
fn f(chan[int] c)
|
||||
{
|
||||
type t = tup(int,int,int);
|
||||
|
||||
|
@ -24,7 +24,7 @@ impure fn f(chan[int] c)
|
|||
}
|
||||
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
spawn f(chan(p));
|
||||
let int i;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// xfail-stage0
|
||||
// -*- rust -*-
|
||||
|
||||
impure fn a(chan[int] c) {
|
||||
fn a(chan[int] c) {
|
||||
c <| 10;
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
spawn a(chan(p));
|
||||
spawn b(chan(p));
|
||||
|
@ -15,7 +15,7 @@ impure fn main() {
|
|||
// log "Finished.";
|
||||
}
|
||||
|
||||
impure fn b(chan[int] c) {
|
||||
fn b(chan[int] c) {
|
||||
// log "task b0";
|
||||
// log "task b1";
|
||||
// log "task b2";
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
// xfail-stage0
|
||||
// -*- rust -*-
|
||||
|
||||
impure fn a(chan[int] c) {
|
||||
fn a(chan[int] c) {
|
||||
log "task a0";
|
||||
log "task a1";
|
||||
c <| 10;
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
spawn a(chan(p));
|
||||
spawn b(chan(p));
|
||||
|
@ -17,7 +17,7 @@ impure fn main() {
|
|||
log "Finished.";
|
||||
}
|
||||
|
||||
impure fn b(chan[int] c) {
|
||||
fn b(chan[int] c) {
|
||||
log "task b0";
|
||||
log "task b1";
|
||||
log "task b2";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// xfail-stage0
|
||||
// -*- rust -*-
|
||||
|
||||
impure fn a(chan[int] c) {
|
||||
fn a(chan[int] c) {
|
||||
if (true) {
|
||||
log "task a";
|
||||
log "task a";
|
||||
|
@ -23,7 +23,7 @@ fn g(int x, str y) -> int {
|
|||
ret z;
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let int n = 2 + 3 * 7;
|
||||
let str s = "hello there";
|
||||
let port[int] p = port();
|
||||
|
@ -38,7 +38,7 @@ impure fn main() {
|
|||
log "children finished, root finishing";
|
||||
}
|
||||
|
||||
impure fn b(chan[int] c) {
|
||||
fn b(chan[int] c) {
|
||||
if (true) {
|
||||
log "task b";
|
||||
log "task b";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
impure fn main() {
|
||||
fn main() {
|
||||
let tup(mutable @int) i = tup(mutable @10);
|
||||
i._0 = @11;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
// xfail-stage0
|
||||
// -*- rust -*-
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
spawn child(chan(p));
|
||||
let int y;
|
||||
|
@ -11,7 +11,7 @@ impure fn main() {
|
|||
check (y == 10);
|
||||
}
|
||||
|
||||
impure fn child(chan[int] c) {
|
||||
fn child(chan[int] c) {
|
||||
c <| 10;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// -*- rust -*-
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] po = port();
|
||||
let chan[int] ch = chan(po);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
impure fn main() {
|
||||
fn main() {
|
||||
auto x = @mutable 5;
|
||||
*x = 1000;
|
||||
log *x;
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
type point = rec(int x, int y, mutable int z);
|
||||
|
||||
impure fn f(@point p) {
|
||||
fn f(@point p) {
|
||||
check (p.z == 12);
|
||||
p.z = 13;
|
||||
check (p.z == 13);
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let point a = rec(x=10, y=11, mutable z=12);
|
||||
let @point b = @a;
|
||||
check (b.z == 12);
|
||||
|
|
|
@ -13,7 +13,7 @@ iter range(int start, int stop) -> int {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let vec[mutable int] a =
|
||||
vec(mutable -1, -1, -1, -1, -1, -1, -1, -1);
|
||||
let int p = 0;
|
||||
|
|
|
@ -5,7 +5,7 @@ iter two() -> int {
|
|||
put 1;
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let vec[mutable int] a = vec(mutable -1, -1, -1, -1);
|
||||
let int p = 0;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// xfail-stage0
|
||||
// -*- rust -*-
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
auto c = chan(p);
|
||||
let int y;
|
||||
|
@ -19,6 +19,6 @@ impure fn main() {
|
|||
check (y == 10);
|
||||
}
|
||||
|
||||
impure fn child(chan[int] c) {
|
||||
fn child(chan[int] c) {
|
||||
c <| 10;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ fn test_1_element() {
|
|||
check (bitv.eq_vec(act, vec(1u)));
|
||||
}
|
||||
|
||||
impure fn test_10_elements() {
|
||||
fn test_10_elements() {
|
||||
auto act;
|
||||
|
||||
// all 0
|
||||
|
@ -61,7 +61,7 @@ impure fn test_10_elements() {
|
|||
check (bitv.eq_vec(act, vec(1u, 0u, 0u, 1u, 0u, 0u, 1u, 0u, 0u, 1u)));
|
||||
}
|
||||
|
||||
impure fn test_31_elements() {
|
||||
fn test_31_elements() {
|
||||
auto act;
|
||||
|
||||
// all 0
|
||||
|
@ -133,7 +133,7 @@ impure fn test_31_elements() {
|
|||
0u, 0u, 0u, 0u, 0u, 0u, 1u)));
|
||||
}
|
||||
|
||||
impure fn test_32_elements() {
|
||||
fn test_32_elements() {
|
||||
auto act;
|
||||
|
||||
// all 0
|
||||
|
@ -207,7 +207,7 @@ impure fn test_32_elements() {
|
|||
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u)));
|
||||
}
|
||||
|
||||
impure fn test_33_elements() {
|
||||
fn test_33_elements() {
|
||||
auto act;
|
||||
|
||||
// all 0
|
||||
|
@ -288,7 +288,7 @@ impure fn test_33_elements() {
|
|||
1u)));
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
test_0_elements();
|
||||
test_1_element();
|
||||
test_10_elements();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// xfail-stage0
|
||||
// -*- rust -*-
|
||||
|
||||
impure fn sub(chan[int] parent, int id) {
|
||||
fn sub(chan[int] parent, int id) {
|
||||
if (id == 0) {
|
||||
parent <| 0;
|
||||
} else {
|
||||
|
@ -13,7 +13,7 @@ impure fn sub(chan[int] parent, int id) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
auto child = spawn sub(chan(p), 500);
|
||||
let int y <- p;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// -*- rust -*-
|
||||
|
||||
unsafe fn main() {
|
||||
fn main() {
|
||||
auto f = "Makefile";
|
||||
auto s = rustrt.str_buf(f);
|
||||
auto buf = libc.malloc(1024);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// -*- rust -*-
|
||||
|
||||
unsafe fn main() {
|
||||
fn main() {
|
||||
libc.puts(rustrt.str_buf("hello, native world 1"));
|
||||
libc.puts(rustrt.str_buf("hello, native world 2"));
|
||||
libc.puts(rustrt.str_buf("hello, native world 3"));
|
||||
|
|
|
@ -6,7 +6,7 @@ obj worker(chan[int] c) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn do_work(chan[int] c) {
|
||||
fn do_work(chan[int] c) {
|
||||
log "in child task";
|
||||
{
|
||||
let worker w = worker(c);
|
||||
|
@ -21,7 +21,7 @@ impure fn do_work(chan[int] c) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
log "spawning worker";
|
||||
auto w = spawn do_work(chan(p));
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
fn main() {
|
||||
|
||||
obj foo() {
|
||||
impure fn m1(mutable int i) {
|
||||
fn m1(mutable int i) {
|
||||
i += 1;
|
||||
log "hi!";
|
||||
}
|
||||
impure fn m2(mutable int i) {
|
||||
fn m2(mutable int i) {
|
||||
i += 1;
|
||||
self.m1(i);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
fn main() {
|
||||
|
||||
obj foo() {
|
||||
impure fn m1(mutable int i) -> int {
|
||||
fn m1(mutable int i) -> int {
|
||||
i += 1;
|
||||
ret i;
|
||||
}
|
||||
impure fn m2(mutable int i) -> int {
|
||||
fn m2(mutable int i) -> int {
|
||||
ret self.m1(i);
|
||||
}
|
||||
impure fn m3(mutable int i) -> int {
|
||||
fn m3(mutable int i) -> int {
|
||||
i += 1;
|
||||
ret self.m1(i);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// xfail-stage0
|
||||
// This checks that preemption works.
|
||||
|
||||
impure fn starve_main(chan[int] alive) {
|
||||
fn starve_main(chan[int] alive) {
|
||||
log "signalling main";
|
||||
alive <| 1;
|
||||
log "starving main";
|
||||
|
@ -11,7 +11,7 @@ impure fn starve_main(chan[int] alive) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] alive = port();
|
||||
log "main started";
|
||||
let task s = spawn starve_main(chan(alive));
|
||||
|
|
|
@ -17,7 +17,7 @@ type record = rec(u32 val1, u32 val2, u32 val3);
|
|||
// then the minimum buffer size needs to be 96. That's not a
|
||||
// power of two so needs to be rounded up. Don't trigger any
|
||||
// assertions.
|
||||
impure fn test_init() {
|
||||
fn test_init() {
|
||||
let port[record] myport = port();
|
||||
auto mychan = chan(myport);
|
||||
|
||||
|
@ -28,7 +28,7 @@ impure fn test_init() {
|
|||
|
||||
// Dump lots of items into the channel so it has to grow.
|
||||
// Don't trigger any assertions.
|
||||
impure fn test_grow() {
|
||||
fn test_grow() {
|
||||
let port[record] myport = port();
|
||||
auto mychan = chan(myport);
|
||||
|
||||
|
@ -40,7 +40,7 @@ impure fn test_grow() {
|
|||
}
|
||||
|
||||
// Don't allow the buffer to shrink below it's original size
|
||||
impure fn test_shrink1() {
|
||||
fn test_shrink1() {
|
||||
let port[i8] myport = port();
|
||||
auto mychan = chan(myport);
|
||||
|
||||
|
@ -48,7 +48,7 @@ impure fn test_shrink1() {
|
|||
auto x <- myport;
|
||||
}
|
||||
|
||||
impure fn test_shrink2() {
|
||||
fn test_shrink2() {
|
||||
let port[record] myport = port();
|
||||
auto mychan = chan(myport);
|
||||
|
||||
|
@ -64,7 +64,7 @@ impure fn test_shrink2() {
|
|||
}
|
||||
|
||||
// Test rotating the buffer when the unit size is not a power of two
|
||||
impure fn test_rotate() {
|
||||
fn test_rotate() {
|
||||
let port[record] myport = port();
|
||||
auto mychan = chan(myport);
|
||||
|
||||
|
@ -83,7 +83,7 @@ impure fn test_rotate() {
|
|||
|
||||
// Test rotating and growing the buffer when
|
||||
// the unit size is not a power of two
|
||||
impure fn test_rotate_grow() {
|
||||
fn test_rotate_grow() {
|
||||
let port[record] myport = port();
|
||||
auto mychan = chan(myport);
|
||||
|
||||
|
@ -104,7 +104,7 @@ impure fn test_rotate_grow() {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
test_init();
|
||||
test_grow();
|
||||
test_shrink1();
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
// xfail-stage0
|
||||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
test05();
|
||||
}
|
||||
|
||||
impure fn test05_start(chan[int] ch) {
|
||||
fn test05_start(chan[int] ch) {
|
||||
ch <| 10;
|
||||
ch <| 20;
|
||||
ch <| 30;
|
||||
}
|
||||
|
||||
impure fn test05() {
|
||||
fn test05() {
|
||||
let port[int] po = port();
|
||||
let chan[int] ch = chan(po);
|
||||
spawn test05_start(chan(po));
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
// xfail-boot
|
||||
// xfail-stage0
|
||||
impure fn start(chan[chan[str]] c) {
|
||||
fn start(chan[chan[str]] c) {
|
||||
let port[str] p = port();
|
||||
c <| chan(p);
|
||||
auto a <- p;
|
||||
// auto b <- p; // Never read the second string.
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[chan[str]] p = port();
|
||||
auto child = spawn "start" start(chan(p));
|
||||
auto c <- p;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// xfail-stage0
|
||||
impure fn start(chan[chan[str]] c) {
|
||||
fn start(chan[chan[str]] c) {
|
||||
let port[str] p = port();
|
||||
c <| chan(p);
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[chan[str]] p = port();
|
||||
auto child = spawn "child" start(chan(p));
|
||||
auto c <- p;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
use std;
|
||||
import std._task;
|
||||
|
||||
impure fn start(chan[int] c, int start, int number_of_messages) {
|
||||
fn start(chan[int] c, int start, int number_of_messages) {
|
||||
let int i = 0;
|
||||
while (i < number_of_messages) {
|
||||
c <| start + i;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
use std;
|
||||
import std._task;
|
||||
|
||||
impure fn start(chan[int] c, int start, int number_of_messages) {
|
||||
fn start(chan[int] c, int start, int number_of_messages) {
|
||||
let int i = 0;
|
||||
while (i < number_of_messages) {
|
||||
c <| start + i;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// xfail-boot
|
||||
// xfail-stage0
|
||||
impure fn start(chan[int] c, int n) {
|
||||
fn start(chan[int] c, int n) {
|
||||
let int i = n;
|
||||
|
||||
while(i > 0) {
|
||||
|
@ -9,7 +9,7 @@ impure fn start(chan[int] c, int n) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[int] p = port();
|
||||
// Spawn a task that sends us back messages. The parent task
|
||||
// is likely to terminate before the child completes, so from
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Tests of ports and channels on various types
|
||||
|
||||
impure fn test_rec() {
|
||||
fn test_rec() {
|
||||
type r = rec(int val0, u8 val1, char val2);
|
||||
|
||||
let port[r] po = port();
|
||||
|
@ -19,7 +19,7 @@ impure fn test_rec() {
|
|||
check (r1.val2 == '2');
|
||||
}
|
||||
|
||||
impure fn test_vec() {
|
||||
fn test_vec() {
|
||||
let port[vec[int]] po = port();
|
||||
let chan[vec[int]] ch = chan(po);
|
||||
let vec[int] v0 = vec(0, 1, 2);
|
||||
|
@ -34,7 +34,7 @@ impure fn test_vec() {
|
|||
check (v1.(2) == 2);
|
||||
}
|
||||
|
||||
impure fn test_str() {
|
||||
fn test_str() {
|
||||
let port[str] po = port();
|
||||
let chan[str] ch = chan(po);
|
||||
let str s0 = "test";
|
||||
|
@ -50,7 +50,7 @@ impure fn test_str() {
|
|||
check (s1.(3) as u8 == 't' as u8);
|
||||
}
|
||||
|
||||
impure fn test_tup() {
|
||||
fn test_tup() {
|
||||
type t = tup(int, u8, char);
|
||||
|
||||
let port[t] po = port();
|
||||
|
@ -67,7 +67,7 @@ impure fn test_tup() {
|
|||
check (t0._2 == '2');
|
||||
}
|
||||
|
||||
impure fn test_tag() {
|
||||
fn test_tag() {
|
||||
tag t {
|
||||
tag1;
|
||||
tag2(int);
|
||||
|
@ -91,7 +91,7 @@ impure fn test_tag() {
|
|||
check (t1 == tag3(10, 11u8, 'A'));
|
||||
}
|
||||
|
||||
impure fn test_chan() {
|
||||
fn test_chan() {
|
||||
let port[chan[int]] po = port();
|
||||
let chan[chan[int]] ch = chan(po);
|
||||
|
||||
|
@ -112,7 +112,7 @@ impure fn test_chan() {
|
|||
check (i == 10);
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
test_rec();
|
||||
test_vec();
|
||||
test_str();
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
// xfail-boot
|
||||
// xfail-stage0
|
||||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
log "===== WITHOUT THREADS =====";
|
||||
test00(false);
|
||||
log "====== WITH THREADS ======";
|
||||
test00(true);
|
||||
}
|
||||
|
||||
impure fn test00_start(chan[int] ch, int message, int count) {
|
||||
fn test00_start(chan[int] ch, int message, int count) {
|
||||
log "Starting test00_start";
|
||||
let int i = 0;
|
||||
while (i < count) {
|
||||
|
@ -18,7 +18,7 @@ impure fn test00_start(chan[int] ch, int message, int count) {
|
|||
log "Ending test00_start";
|
||||
}
|
||||
|
||||
impure fn test00(bool is_multithreaded) {
|
||||
fn test00(bool is_multithreaded) {
|
||||
let int number_of_tasks = 16;
|
||||
let int number_of_messages = 4;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
test00();
|
||||
}
|
||||
|
||||
impure fn test00() {
|
||||
fn test00() {
|
||||
let int r = 0;
|
||||
let int sum = 0;
|
||||
let port[int] p = port();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
test00();
|
||||
}
|
||||
|
||||
impure fn test00() {
|
||||
fn test00() {
|
||||
let int r = 0;
|
||||
let int sum = 0;
|
||||
let port[int] p = port();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
test00();
|
||||
}
|
||||
|
||||
impure fn test00() {
|
||||
fn test00() {
|
||||
let int r = 0;
|
||||
let int sum = 0;
|
||||
let port[int] p = port();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// xfail-stage0
|
||||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
test00();
|
||||
}
|
||||
|
||||
impure fn test00_start(chan[int] c, int start, int number_of_messages) {
|
||||
fn test00_start(chan[int] c, int start, int number_of_messages) {
|
||||
let int i = 0;
|
||||
while (i < number_of_messages) {
|
||||
c <| start + i;
|
||||
|
@ -11,7 +11,7 @@ impure fn test00_start(chan[int] c, int start, int number_of_messages) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn test00() {
|
||||
fn test00() {
|
||||
let int r = 0;
|
||||
let int sum = 0;
|
||||
let port[int] p = port();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// xfail-boot
|
||||
// xfail-stage0
|
||||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
test00();
|
||||
}
|
||||
|
||||
impure fn test00_start(chan[int] c, int start, int number_of_messages) {
|
||||
fn test00_start(chan[int] c, int start, int number_of_messages) {
|
||||
let int i = 0;
|
||||
while (i < number_of_messages) {
|
||||
c <| start + i;
|
||||
|
@ -12,7 +12,7 @@ impure fn test00_start(chan[int] c, int start, int number_of_messages) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn test00() {
|
||||
fn test00() {
|
||||
let int r = 0;
|
||||
let int sum = 0;
|
||||
let port[int] p = port();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// xfail-boot
|
||||
// xfail-stage0
|
||||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
test00();
|
||||
}
|
||||
|
||||
impure fn test00_start(chan[int] c, int number_of_messages) {
|
||||
fn test00_start(chan[int] c, int number_of_messages) {
|
||||
let int i = 0;
|
||||
while (i < number_of_messages) {
|
||||
c <| i;
|
||||
|
@ -12,7 +12,7 @@ impure fn test00_start(chan[int] c, int number_of_messages) {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn test00() {
|
||||
fn test00() {
|
||||
let int r = 0;
|
||||
let int sum = 0;
|
||||
let port[int] p = port();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// any size, but rustc currently can because they do have size. Whether
|
||||
// or not this is desirable I don't know, but here's a regression test.
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let port[()] po = port();
|
||||
let chan[()] ch = chan(po);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// xfail-boot
|
||||
// xfail-stage0
|
||||
|
||||
impure fn main() -> () {
|
||||
fn main() -> () {
|
||||
test00(true);
|
||||
// test01();
|
||||
test02();
|
||||
|
@ -11,7 +11,7 @@ impure fn main() -> () {
|
|||
test06();
|
||||
}
|
||||
|
||||
impure fn test00_start(chan[int] ch, int message, int count) {
|
||||
fn test00_start(chan[int] ch, int message, int count) {
|
||||
log "Starting test00_start";
|
||||
let int i = 0;
|
||||
while (i < count) {
|
||||
|
@ -22,7 +22,7 @@ impure fn test00_start(chan[int] ch, int message, int count) {
|
|||
log "Ending test00_start";
|
||||
}
|
||||
|
||||
impure fn test00(bool is_multithreaded) {
|
||||
fn test00(bool is_multithreaded) {
|
||||
let int number_of_tasks = 1;
|
||||
let int number_of_messages = 4;
|
||||
log "Creating tasks";
|
||||
|
@ -62,14 +62,14 @@ impure fn test00(bool is_multithreaded) {
|
|||
(number_of_tasks * number_of_tasks + number_of_tasks) / 2);
|
||||
}
|
||||
|
||||
impure fn test01() {
|
||||
fn test01() {
|
||||
let port[int] p = port();
|
||||
log "Reading from a port that is never written to.";
|
||||
let int value <- p;
|
||||
log value;
|
||||
}
|
||||
|
||||
impure fn test02() {
|
||||
fn test02() {
|
||||
let port[int] p = port();
|
||||
let chan[int] c = chan(p);
|
||||
log "Writing to a local task channel.";
|
||||
|
@ -113,7 +113,7 @@ fn test04() {
|
|||
log "Finishing up.";
|
||||
}
|
||||
|
||||
impure fn test05_start(chan[int] ch) {
|
||||
fn test05_start(chan[int] ch) {
|
||||
ch <| 10;
|
||||
ch <| 20;
|
||||
ch <| 30;
|
||||
|
@ -121,7 +121,7 @@ impure fn test05_start(chan[int] ch) {
|
|||
ch <| 30;
|
||||
}
|
||||
|
||||
impure fn test05() {
|
||||
fn test05() {
|
||||
let port[int] po = port();
|
||||
let chan[int] ch = chan(po);
|
||||
spawn thread test05_start(ch);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
impure fn main() {
|
||||
fn main() {
|
||||
let tup(mutable vec[int]) i = tup(mutable vec(1,2,3));
|
||||
i._0 = vec(4,5,6);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
type point = rec(int x, int y, mutable int z);
|
||||
|
||||
impure fn f(& mutable point p) {
|
||||
fn f(& mutable point p) {
|
||||
p.z = 13;
|
||||
}
|
||||
|
||||
impure fn main() {
|
||||
fn main() {
|
||||
let point x = rec(x=10, y=11, mutable z=12);
|
||||
f(x);
|
||||
check (x.z == 13);
|
||||
|
|
Loading…
Reference in New Issue