|
@@ -67,7 +67,10 @@ let check_dims_match dims dec_type errnode =
|
|
|
| _ -> ()
|
|
| _ -> ()
|
|
|
|
|
|
|
|
let rec typecheck node = match node with
|
|
let rec typecheck node = match node with
|
|
|
- | FunUse (FunCall (_, args, _), FunDef (_, ftype, name, params, _, _), _) ->
|
|
|
|
|
|
|
+ | FunUse (FunCall (fname, args, floc),
|
|
|
|
|
+ (FunDec (ftype, name, params, _) as dec), loc)
|
|
|
|
|
+ | FunUse (FunCall (fname, args, floc),
|
|
|
|
|
+ (FunDef (_, ftype, name, params, _, _) as dec), loc) ->
|
|
|
(match (list_size args, list_size params) with
|
|
(match (list_size args, list_size params) with
|
|
|
| (nargs, nparams) when nargs != nparams ->
|
|
| (nargs, nparams) when nargs != nparams ->
|
|
|
let msg = sprintf
|
|
let msg = sprintf
|
|
@@ -76,11 +79,12 @@ let rec typecheck node = match node with
|
|
|
in
|
|
in
|
|
|
raise (NodeError (node, msg))
|
|
raise (NodeError (node, msg))
|
|
|
| _ ->
|
|
| _ ->
|
|
|
|
|
+ let args = List.map typecheck args in
|
|
|
let check_arg_type arg param =
|
|
let check_arg_type arg param =
|
|
|
- check_type (ctypeof param) (typecheck arg);
|
|
|
|
|
|
|
+ check_type (ctypeof param) arg;
|
|
|
in
|
|
in
|
|
|
List.iter2 check_arg_type args params;
|
|
List.iter2 check_arg_type args params;
|
|
|
- Type (node, ftype)
|
|
|
|
|
|
|
+ Type (FunUse (FunCall (fname, args, floc), dec, loc), ftype)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
| Arg (Type (_, vtype)) -> Type (node, vtype)
|
|
| Arg (Type (_, vtype)) -> Type (node, vtype)
|
|
@@ -104,6 +108,8 @@ let rec typecheck node = match node with
|
|
|
| Cond (Type (cond, condtype), Type (texpr, ttype), fexpr, loc) ->
|
|
| Cond (Type (cond, condtype), Type (texpr, ttype), fexpr, loc) ->
|
|
|
check_type ttype fexpr;
|
|
check_type ttype fexpr;
|
|
|
Type (node, ttype)
|
|
Type (node, ttype)
|
|
|
|
|
+ | Cond (cond, texpr, fexpr, loc) ->
|
|
|
|
|
+ typecheck (Cond (typecheck cond, typecheck texpr, typecheck fexpr, loc))
|
|
|
|
|
|
|
|
| VarLet (Assign (_, None, (Type _ as value), _), dec_type, depth) ->
|
|
| VarLet (Assign (_, None, (Type _ as value), _), dec_type, depth) ->
|
|
|
check_type dec_type value;
|
|
check_type dec_type value;
|