aboutsummaryrefslogtreecommitdiff
path: root/src/boot
diff options
context:
space:
mode:
authorTohava <tohava@tohava-laptop.(none)>2010-08-05 04:19:46 +0300
committerTohava <tohava@tohava-laptop.(none)>2010-08-05 04:19:46 +0300
commitce79b0e492f1583debbce3c8155da3536c684d9a (patch)
treef5a2a22230510dd14901742a4904c576f62a8500 /src/boot
parentAdded AST logging, and modified AST for consistent handling of alt stmts. (diff)
parentThread argument-types down to internal_check_outer_lval in type.ml, in prepar... (diff)
downloadrust-ce79b0e492f1583debbce3c8155da3536c684d9a.tar.xz
rust-ce79b0e492f1583debbce3c8155da3536c684d9a.zip
Merge branch 'master' of git://github.com/graydon/rust
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/fe/pexp.ml122
-rw-r--r--src/boot/me/type.ml25
2 files changed, 102 insertions, 45 deletions
diff --git a/src/boot/fe/pexp.ml b/src/boot/fe/pexp.ml
index 9b870639..fb2d91a0 100644
--- a/src/boot/fe/pexp.ml
+++ b/src/boot/fe/pexp.ml
@@ -718,131 +718,175 @@ and parse_negation_pexp (ps:pstate) : pexp =
(* Binops are all left-associative, *)
(* so we factor out some of the parsing code here. *)
-and binop_rhs
+and binop_build
(ps:pstate)
(name:string)
(apos:pos)
- (lhs:pexp)
(rhs_parse_fn:pstate -> pexp)
+ (lhs:pexp)
+ (step_fn:pexp -> pexp)
(op:Ast.binop)
: pexp =
bump ps;
let rhs = (ctxt (name ^ " rhs") rhs_parse_fn ps) in
let bpos = lexpos ps in
- span ps apos bpos (PEXP_binop (op, lhs, rhs))
+ let node = span ps apos bpos (PEXP_binop (op, lhs, rhs)) in
+ step_fn node
and parse_factor_pexp (ps:pstate) : pexp =
let name = "factor pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_negation_pexp ps in
+ let build = binop_build ps name apos parse_negation_pexp in
+ let rec step accum =
match peek ps with
- STAR -> binop_rhs ps name apos lhs parse_factor_pexp Ast.BINOP_mul
- | SLASH -> binop_rhs ps name apos lhs parse_factor_pexp Ast.BINOP_div
- | PERCENT -> binop_rhs ps name apos lhs parse_factor_pexp Ast.BINOP_mod
- | _ -> lhs
+ STAR -> build accum step Ast.BINOP_mul
+ | SLASH -> build accum step Ast.BINOP_div
+ | PERCENT -> build accum step Ast.BINOP_mod
+ | _ -> accum
+ in
+ step lhs
and parse_term_pexp (ps:pstate) : pexp =
let name = "term pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_factor_pexp ps in
+ let build = binop_build ps name apos parse_factor_pexp in
+ let rec step accum =
match peek ps with
- PLUS -> binop_rhs ps name apos lhs parse_term_pexp Ast.BINOP_add
- | MINUS -> binop_rhs ps name apos lhs parse_term_pexp Ast.BINOP_sub
- | _ -> lhs
+ PLUS -> build accum step Ast.BINOP_add
+ | MINUS -> build accum step Ast.BINOP_sub
+ | _ -> accum
+ in
+ step lhs
and parse_shift_pexp (ps:pstate) : pexp =
let name = "shift pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_term_pexp ps in
+ let build = binop_build ps name apos parse_term_pexp in
+ let rec step accum =
match peek ps with
- LSL -> binop_rhs ps name apos lhs parse_shift_pexp Ast.BINOP_lsl
- | LSR -> binop_rhs ps name apos lhs parse_shift_pexp Ast.BINOP_lsr
- | ASR -> binop_rhs ps name apos lhs parse_shift_pexp Ast.BINOP_asr
- | _ -> lhs
+ LSL -> build accum step Ast.BINOP_lsl
+ | LSR -> build accum step Ast.BINOP_lsr
+ | ASR -> build accum step Ast.BINOP_asr
+ | _ -> accum
+ in
+ step lhs
and parse_and_pexp (ps:pstate) : pexp =
let name = "and pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_shift_pexp ps in
+ let build = binop_build ps name apos parse_shift_pexp in
+ let rec step accum =
match peek ps with
- AND -> binop_rhs ps name apos lhs parse_and_pexp Ast.BINOP_and
- | _ -> lhs
+ AND -> build accum step Ast.BINOP_and
+ | _ -> accum
+ in
+ step lhs
and parse_xor_pexp (ps:pstate) : pexp =
let name = "xor pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_and_pexp ps in
+ let build = binop_build ps name apos parse_and_pexp in
+ let rec step accum =
match peek ps with
- CARET -> binop_rhs ps name apos lhs parse_xor_pexp Ast.BINOP_xor
- | _ -> lhs
+ CARET -> build accum step Ast.BINOP_xor
+ | _ -> accum
+ in
+ step lhs
and parse_or_pexp (ps:pstate) : pexp =
let name = "or pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_xor_pexp ps in
+ let build = binop_build ps name apos parse_xor_pexp in
+ let rec step accum =
match peek ps with
- OR -> binop_rhs ps name apos lhs parse_or_pexp Ast.BINOP_or
- | _ -> lhs
+ OR -> build accum step Ast.BINOP_or
+ | _ -> accum
+ in
+ step lhs
and parse_relational_pexp (ps:pstate) : pexp =
let name = "relational pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_or_pexp ps in
+ let build = binop_build ps name apos parse_or_pexp in
+ let rec step accum =
match peek ps with
- LT -> binop_rhs ps name apos lhs parse_relational_pexp Ast.BINOP_lt
- | LE -> binop_rhs ps name apos lhs parse_relational_pexp Ast.BINOP_le
- | GE -> binop_rhs ps name apos lhs parse_relational_pexp Ast.BINOP_ge
- | GT -> binop_rhs ps name apos lhs parse_relational_pexp Ast.BINOP_gt
- | _ -> lhs
+ LT -> build accum step Ast.BINOP_lt
+ | LE -> build accum step Ast.BINOP_le
+ | GE -> build accum step Ast.BINOP_ge
+ | GT -> build accum step Ast.BINOP_gt
+ | _ -> accum
+ in
+ step lhs
and parse_equality_pexp (ps:pstate) : pexp =
let name = "equality pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_relational_pexp ps in
+ let build = binop_build ps name apos parse_relational_pexp in
+ let rec step accum =
match peek ps with
- EQEQ -> binop_rhs ps name apos lhs parse_equality_pexp Ast.BINOP_eq
- | NE -> binop_rhs ps name apos lhs parse_equality_pexp Ast.BINOP_ne
- | _ -> lhs
+ EQEQ -> build accum step Ast.BINOP_eq
+ | NE -> build accum step Ast.BINOP_ne
+ | _ -> accum
+ in
+ step lhs
and parse_andand_pexp (ps:pstate) : pexp =
let name = "andand pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_equality_pexp ps in
+ let rec step accum =
match peek ps with
ANDAND ->
bump ps;
- let rhs = parse_andand_pexp ps in
+ let rhs = parse_equality_pexp ps in
let bpos = lexpos ps in
- span ps apos bpos (PEXP_lazy_and (lhs, rhs))
+ let node = span ps apos bpos (PEXP_lazy_and (accum, rhs)) in
+ step node
- | _ -> lhs
+ | _ -> accum
+ in
+ step lhs
and parse_oror_pexp (ps:pstate) : pexp =
let name = "oror pexp" in
let apos = lexpos ps in
let lhs = ctxt (name ^ " lhs") parse_andand_pexp ps in
+ let rec step accum =
match peek ps with
OROR ->
bump ps;
- let rhs = parse_oror_pexp ps in
+ let rhs = parse_andand_pexp ps in
let bpos = lexpos ps in
- span ps apos bpos (PEXP_lazy_or (lhs, rhs))
+ let node = span ps apos bpos (PEXP_lazy_or (accum, rhs)) in
+ step node
+
+ | _ -> accum
+ in
+ step lhs
- | _ -> lhs
and parse_as_pexp (ps:pstate) : pexp =
let apos = lexpos ps in
let pexp = ctxt "as pexp" parse_oror_pexp ps in
+ let rec step accum =
match peek ps with
AS ->
bump ps;
@@ -850,10 +894,16 @@ and parse_as_pexp (ps:pstate) : pexp =
let t = parse_ty ps in
let bpos = lexpos ps in
let t = span ps tapos bpos t in
+ let node =
span ps apos bpos
- (PEXP_unop ((Ast.UNOP_cast t), pexp))
+ (PEXP_unop ((Ast.UNOP_cast t), accum))
+ in
+ step node
+
+ | _ -> accum
+ in
+ step pexp
- | _ -> pexp
and parse_pexp (ps:pstate) : pexp =
parse_as_pexp ps
diff --git a/src/boot/me/type.ml b/src/boot/me/type.ml
index 57fdc457..787855f0 100644
--- a/src/boot/me/type.ml
+++ b/src/boot/me/type.ml
@@ -472,6 +472,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
and internal_check_outer_lval
~mut:(mut:Ast.mutability)
~deref:(deref:bool)
+ ~fn_args:(fn_args:(Ast.ty array) option)
(infer:Ast.ty option)
(lval:Ast.lval)
: (Ast.ty * int) =
@@ -485,11 +486,15 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
demand expected actual;
yield_ty actual
| None, (LTYPE_poly _ as lty) ->
- Common.err
- None
- "not enough context to automatically instantiate the polymorphic \
- type '%a'; supply type parameters explicitly"
- sprintf_ltype lty
+ begin
+ match fn_args with
+ None ->
+ Common.err None
+ "can't auto-instantiate %a" sprintf_ltype lty
+ | Some args ->
+ Common.err None "can't auto-instantiate %a on %d args"
+ sprintf_ltype lty (Array.length args)
+ end
| Some _, (LTYPE_poly _) ->
(* FIXME: auto-instantiate *)
Common.unimpl
@@ -502,6 +507,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
and generic_check_lval
~mut:(mut:Ast.mutability)
~deref:(deref:bool)
+ ~fn_args:(fn_args:(Ast.ty array) option)
(infer:Ast.ty option)
(lval:Ast.lval)
: Ast.ty =
@@ -521,7 +527,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
| Some t -> Fmt.fmt_to_str Ast.fmt_ty t))
in
let (lval_ty, n_boxes) =
- internal_check_outer_lval ~mut:mut ~deref:deref infer lval
+ internal_check_outer_lval ~mut ~deref ~fn_args infer lval
in
let _ =
iflog cx
@@ -563,9 +569,10 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
and check_lval
?mut:(mut=Ast.MUT_immutable)
?deref:(deref=false)
+ ?fn_args:(fn_args=None)
(lval:Ast.lval)
: Ast.ty =
- generic_check_lval ~mut:mut ~deref:deref None lval
+ generic_check_lval ~fn_args ~mut ~deref None lval
and check_atom ?deref:(deref=false) (atom:Ast.atom) : Ast.ty =
match atom with
@@ -582,7 +589,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
(ty:Ast.ty)
(lval:Ast.lval)
: unit =
- ignore (generic_check_lval ?mut:mut ~deref:false
+ ignore (generic_check_lval ~mut ~deref:false ~fn_args:None
(Some (Ast.TY_mutable ty)) lval)
in
@@ -636,7 +643,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
* returns the return type. *)
let check_fn (callee:Ast.lval) (args:Ast.atom array) : Ast.ty =
let arg_tys = Array.map check_atom args in
- let callee_ty = check_lval callee in
+ let callee_ty = check_lval callee ~fn_args:(Some arg_tys) in
demand_fn (Array.map (fun ty -> Some ty) arg_tys) callee_ty
in