Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/typechecker/check-expr.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/typechecker/check-expr.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3407, Wed Nov 11 18:53:18 2015 UTC revision 3413, Thu Nov 12 15:21:54 2015 UTC
# Line 13  Line 13 
13    (* type check an expression *)    (* type check an expression *)
14      val check : Env.t * Env.context * ParseTree.expr -> (AST.expr * Types.ty)      val check : Env.t * Env.context * ParseTree.expr -> (AST.expr * Types.ty)
15    
16      (* type check a list of expressions *)
17        val checkList : Env.t * Env.context * ParseTree.expr list -> (AST.expr list * Types.ty list)
18    
19      (* type check a dimension that is given by a constant expression *)
20        val checkDim : Env.t * Env.context * ParseTree.expr -> IntLit.t option
21    
22      (* type check a tensor shape, where the dimensions are given by constant expressions *)
23        val checkShape : Env.t * Env.context * ParseTree.expr list -> Types.shape
24    
25    (* `resolveOverload (cxt, rator, tys, args, candidates)` resolves the application of    (* `resolveOverload (cxt, rator, tys, args, candidates)` resolves the application of
26     * the overloaded operator `rator` to `args`, where `tys` are the types of the arguments     * the overloaded operator `rator` to `args`, where `tys` are the types of the arguments
27     * and `candidates` is the list of candidate definitions.     * and `candidates` is the list of candidate definitions.
# Line 20  Line 29 
29      val resolveOverload : Env.context * Atom.atom * Types.ty list * AST.expr list * Var.t list      val resolveOverload : Env.context * Atom.atom * Types.ty list * AST.expr list * Var.t list
30            -> (AST.expr * Types.ty)            -> (AST.expr * Types.ty)
31    
   (* check a dimension that is given by a constant expression *)  
     val checkDim : Env.t * Env.context * ParseTree.expr -> IntLit.t option  
   
   (* check a tensor shape, where the dimensions are given by constant expressions *)  
     val checkShape : Env.t * Env.context * ParseTree.expr list -> Types.shape  
   
32    end = struct    end = struct
33    
34      structure PT = ParseTree      structure PT = ParseTree
# Line 45  Line 48 
48      datatype token = datatype TypeError.token      datatype token = datatype TypeError.token
49    
50    (* mark a variable use with its location *)    (* mark a variable use with its location *)
51      fun useVar (cxt, x) = (x, Error.location cxt)      fun useVar (cxt : Env.context, x) = (x, #2 cxt)
52    
53    (* resolve overloading: we use a simple scheme that selects the first operator in the    (* resolve overloading: we use a simple scheme that selects the first operator in the
54     * list that matches the argument types.     * list that matches the argument types.
# Line 331  Line 334 
334                          val (tyArgs, Ty.T_Fun([domTy], rngTy)) = TU.instantiate(Var.typeOf rator)                          val (tyArgs, Ty.T_Fun([domTy], rngTy)) = TU.instantiate(Var.typeOf rator)
335                          in                          in
336                            case Util.coerceType (domTy, eTy)                            case Util.coerceType (domTy, eTy)
337                             of SOME(e', ty) => (AST.E_Prim(rator, tyArgs, [e'], rngTy), rngTy)                             of SOME e' => (AST.E_Prim(rator, tyArgs, [e'], rngTy), rngTy)
338                              | NONE => err (cxt, [                              | NONE => err (cxt, [
339                                    S "type error for unary operator \"", V rator, S "\"\n",                                    S "type error for unary operator \"", V rator, S "\"\n",
340                                    S "  expected:  ", TY domTy, S "\n",                                    S "  expected:  ", TY domTy, S "\n",
# Line 385  Line 388 
388                              in                              in
389                                if Unify.equalType(fldTy, ty1)                                if Unify.equalType(fldTy, ty1)
390                                  then (case Util.coerceType(domTy, (e2', ty2))                                  then (case Util.coerceType(domTy, (e2', ty2))
391                                     of SOME(e2', _) => (AST.E_Prim(BV.op_probe, tyArgs, [e1', e2'], rngTy), rngTy)                                     of SOME e2' => (AST.E_Prim(BV.op_probe, tyArgs, [e1', e2'], rngTy), rngTy)
392                                      | NONE => tyError()                                      | NONE => tyError()
393                                    (* end case *))                                    (* end case *))
394                                  else tyError()                                  else tyError()
# Line 507  Line 510 
510                        val resTy = Ty.T_Tensor(Ty.Shape(Ty.DimConst(List.length args) :: dd))                        val resTy = Ty.T_Tensor(Ty.Shape(Ty.DimConst(List.length args) :: dd))
511                        fun chkArgs (arg::args, argTy::tys, args') = (                        fun chkArgs (arg::args, argTy::tys, args') = (
512                              case Util.coerceType(ty, (arg, argTy))                              case Util.coerceType(ty, (arg, argTy))
513                               of SOME(arg', _) => chkArgs (args, tys, arg'::args')                               of SOME arg' => chkArgs (args, tys, arg'::args')
514                                | NONE => (                                | NONE => (
515                                    TypeError.error(cxt, [                                    TypeError.error(cxt, [
516                                        S "arguments of tensor construction must have same type"                                        S "arguments of tensor construction must have same type"
517                                      ]);                                      ]);
518                                    chkArgs (args, tys, bogusExp::args'))                                    chkArgs (args, tys, bogusExp::args'))
519                              (* end case *))                              (* end case *))
520                          | chkArgs ([], [], args') = (AST.E_Tensor(List.rev args', resTy), resTy)                          | chkArgs (_, _, args') = (AST.E_Tensor(List.rev args', resTy), resTy)
521                        in                        in
522                          chkArgs (args, tys, [])                          chkArgs (args, tys, [])
523                        end                        end

Legend:
Removed from v.3407  
changed lines
  Added in v.3413

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0